@helia/ipns 8.2.3 → 8.2.4-7d471a02
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 +3 -3
- package/dist/index.min.js.map +4 -4
- package/package.json +2 -2
- package/dist/typedoc-urls.json +0 -48
package/dist/index.min.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.HeliaIpns = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var HeliaIpns=(()=>{var
|
|
3
|
-
`,R:"%H:%M",T:"%H:%M:%S",t:" ",X:"%T",Z:"GMT",z:"+0000"};return m;function m(g,A,N){var v=this;if(!(v instanceof m))return new m(g,A,N);v.time=+g||0,v.nano=+A||0,v.year=+N||0,k(v)}function k(g){var A,N,v,B=g.year,U=g.time,H=g.nano,x=((H<0||a<=H)&&(H-=(N=Math.floor(H/a))*a,U+=N,N=1),B%t);return(U<-i||i<U||x)&&((A=f(U/o))&&(B+=A*t,U-=A*o),(v=O(U)).setUTCFullYear(x+v.getUTCFullYear()),v=(U=+v)+(A=f((B-=x)/t))*o,A&&-i<=v&&v<=i&&(B-=A*t,U=v),N=1),N&&(g.year=B,g.time=U,g.nano=H),g}function O(g){var A=new Date(0);return A.setTime(g),A}function q(B,v){B=+B||0;var N=f((v=(v|0)*s)/n)+f(B/n),v=v%n+B%n,B=f(v/n);return B&&(N+=B,v-=B*n),new m(1e3*v,0,N*t)}function C(g,A,N,v,B,U){return function(x,w){var E=k(this);x=x||new Array(8),S(x,w|=0);var h=Math.floor(E.time/1e3),E=E.year*(r*e/t),K=f(E/s)+f(h/s),E=E%s+h%s,h=Math.floor(E/s);return h&&(K+=h,E-=h*s),H(x,w+B,K),H(x,w+U,E),x};function H(x,w,K){x[w+g]=K>>24&255,x[w+A]=K>>16&255,x[w+N]=K>>8&255,x[w+v]=255&K}}function d(g,A,N,v,B,U){return function(x,w){S(x,w|=0);var K=H(x,w+B);return q(H(x,w+U),K)};function H(x,w){return 16777216*x[w+g]+(x[w+A]<<16|x[w+N]<<8|x[w+v])}}function S(g,A){if(g=g&&g.length,g==null)throw new TypeError("Invalid Buffer");if(g<A+8)throw new RangeError("Out of range")}function R(g){return(9<g?"":"0")+(0|g)}function L(g,A){return(c+(0|g)).substr(-A)}}()});var bu=es((Pw,wu)=>{wu.exports=function(e){if(!e)throw Error("hashlru must have a max value, of type number, greater than 0");var t=0,r=Object.create(null),n=Object.create(null);function o(i,s){r[i]=s,t++,t>=e&&(t=0,n=r,r=Object.create(null))}return{has:function(i){return r[i]!==void 0||n[i]!==void 0},remove:function(i){r[i]!==void 0&&(r[i]=void 0),n[i]!==void 0&&(n[i]=void 0)},get:function(i){var s=r[i];if(s!==void 0)return s;if((s=n[i])!==void 0)return o(i,s),s},set:function(i,s){r[i]!==void 0?r[i]=s:o(i,s)},clear:function(){r=Object.create(null),n=Object.create(null)}}}});var Uh={};At(Uh,{ipns:()=>_h,ipnsSelector:()=>to,ipnsValidator:()=>Wr});function ns(e){return e==null?!1:(e.type==="RSA"||e.type==="Ed25519"||e.type==="secp256k1"||e.type==="ECDSA")&&e.raw instanceof Uint8Array&&typeof e.equals=="function"&&typeof e.toMultihash=="function"&&typeof e.toCID=="function"&&typeof e.verify=="function"}var uo=Symbol.for("@libp2p/peer-id");var at=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Ye=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var xr=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}};var tn=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},je=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var We=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var mo={};At(mo,{base32:()=>me,base32hex:()=>Xu,base32hexpad:()=>Qu,base32hexpadupper:()=>tf,base32hexupper:()=>Ju,base32pad:()=>ju,base32padupper:()=>Wu,base32upper:()=>Yu,base32z:()=>ef});var Ph=new Uint8Array(0);function os(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Qt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function is(e){return new TextEncoder().encode(e)}function ss(e){return new TextDecoder().decode(e)}function Hu(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var i=e.charAt(o),s=i.charCodeAt(0);if(r[s]!==255)throw new TypeError(i+" is ambiguous");r[s]=o}var a=e.length,c=e.charAt(0),f=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function l(T){if(T instanceof Uint8Array||(ArrayBuffer.isView(T)?T=new Uint8Array(T.buffer,T.byteOffset,T.byteLength):Array.isArray(T)&&(T=Uint8Array.from(T))),!(T instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(T.length===0)return"";for(var m=0,k=0,O=0,q=T.length;O!==q&&T[O]===0;)O++,m++;for(var C=(q-O)*u+1>>>0,d=new Uint8Array(C);O!==q;){for(var S=T[O],R=0,L=C-1;(S!==0||R<k)&&L!==-1;L--,R++)S+=256*d[L]>>>0,d[L]=S%a>>>0,S=S/a>>>0;if(S!==0)throw new Error("Non-zero carry");k=R,O++}for(var g=C-k;g!==C&&d[g]===0;)g++;for(var A=c.repeat(m);g<C;++g)A+=e.charAt(d[g]);return A}function y(T){if(typeof T!="string")throw new TypeError("Expected String");if(T.length===0)return new Uint8Array;var m=0;if(T[m]!==" "){for(var k=0,O=0;T[m]===c;)k++,m++;for(var q=(T.length-m)*f+1>>>0,C=new Uint8Array(q);T[m];){var d=r[T.charCodeAt(m)];if(d===255)return;for(var S=0,R=q-1;(d!==0||S<O)&&R!==-1;R--,S++)d+=a*C[R]>>>0,C[R]=d%256>>>0,d=d/256>>>0;if(d!==0)throw new Error("Non-zero carry");O=S,m++}if(T[m]!==" "){for(var L=q-O;L!==q&&C[L]===0;)L++;for(var g=new Uint8Array(k+(q-L)),A=k;L!==q;)g[A++]=C[L++];return g}}}function D(T){var m=y(T);if(m)return m;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:y,decode:D}}var qu=Hu,zu=qu,cs=zu;var fo=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},lo=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return us(this,t)}},ho=class{decoders;constructor(t){this.decoders=t}or(t){return us(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function us(e,t){return new ho({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var po=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new fo(t,r,n),this.decoder=new lo(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Xe({name:e,prefix:t,encode:r,decode:n}){return new po(e,t,r,n)}function pe({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=cs(r,e);return Xe({prefix:t,name:e,encode:n,decode:i=>Qt(o(i))})}function $u(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let i=new Uint8Array(o*r/8|0),s=0,a=0,c=0;for(let f=0;f<o;++f){let u=t[e[f]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|u,s+=r,s>=8&&(s-=8,i[c++]=255&a>>s)}if(s>=r||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function Gu(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,i="",s=0,a=0;for(let c=0;c<e.length;++c)for(a=a<<8|e[c],s+=8;s>r;)s-=r,i+=t[o&a>>s];if(s!==0&&(i+=t[o&a<<r-s]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function Zu(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function rt({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=Zu(n);return Xe({prefix:t,name:e,encode(i){return Gu(i,n,r)},decode(i){return $u(i,o,r,e)}})}var me=rt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Yu=rt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),ju=rt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Wu=rt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Xu=rt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ju=rt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Qu=rt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),tf=rt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ef=rt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var yo={};At(yo,{base58btc:()=>X,base58flickr:()=>rf});var X=pe({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),rf=pe({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var xo={};At(xo,{base64:()=>go,base64pad:()=>nf,base64url:()=>of,base64urlpad:()=>sf});var go=rt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),nf=rt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),of=rt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),sf=rt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});function af(e,t){try{if(typeof e=="string"&&e.length>0)return cf(e);if(typeof e=="number"&&isFinite(e))return t?.long?ff(e):uf(e);throw new Error("Value is not a string or number.")}catch(r){let n=lf(r)?`${r.message}. value=${JSON.stringify(e)}`:"An unknown error has occured.";throw new Error(n)}}function cf(e){if(e=String(e),e.length>100)throw new Error("Value exceeds the maximum length of 100 characters.");let t=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);if(!t)return NaN;let r=parseFloat(t[1]),n=(t[2]||"ms").toLowerCase();switch(n){case"years":case"year":case"yrs":case"yr":case"y":return r*315576e5;case"weeks":case"week":case"w":return r*6048e5;case"days":case"day":case"d":return r*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return r*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return r*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return r*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return r;default:throw new Error(`The unit ${n} was matched, but no matching case exists.`)}}var rn=af;function uf(e){let t=Math.abs(e);return t>=864e5?`${Math.round(e/864e5)}d`:t>=36e5?`${Math.round(e/36e5)}h`:t>=6e4?`${Math.round(e/6e4)}m`:t>=1e3?`${Math.round(e/1e3)}s`:`${e}ms`}function ff(e){let t=Math.abs(e);return t>=864e5?en(e,t,864e5,"day"):t>=36e5?en(e,t,36e5,"hour"):t>=6e4?en(e,t,6e4,"minute"):t>=1e3?en(e,t,1e3,"second"):`${e} ms`}function en(e,t,r,n){let o=t>=r*1.5;return`${Math.round(e/r)} ${n}${o?"s":""}`}function lf(e){return typeof e=="object"&&e!==null&&"message"in e}function wo(e){r.debug=r,r.default=r,r.coerce=c,r.disable=i,r.enable=o,r.enabled=s,r.humanize=rn,r.destroy=f,Object.keys(e).forEach(u=>{r[u]=e[u]}),r.names=[],r.skips=[],r.formatters={};function t(u){let l=0;for(let y=0;y<u.length;y++)l=(l<<5)-l+u.charCodeAt(y),l|=0;return r.colors[Math.abs(l)%r.colors.length]}r.selectColor=t;function r(u){let l,y=null,D,T;function m(...k){if(!m.enabled)return;let O=m,q=Number(new Date),C=q-(l||q);O.diff=C,O.prev=l,O.curr=q,l=q,k[0]=r.coerce(k[0]),typeof k[0]!="string"&&k.unshift("%O");let d=0;k[0]=k[0].replace(/%([a-zA-Z%])/g,(R,L)=>{if(R==="%%")return"%";d++;let g=r.formatters[L];if(typeof g=="function"){let A=k[d];R=g.call(O,A),k.splice(d,1),d--}return R}),r.formatArgs.call(O,k),(O.log||r.log).apply(O,k)}return m.namespace=u,m.useColors=r.useColors(),m.color=r.selectColor(u),m.extend=n,m.destroy=r.destroy,Object.defineProperty(m,"enabled",{enumerable:!0,configurable:!1,get:()=>y!==null?y:(D!==r.namespaces&&(D=r.namespaces,T=r.enabled(u)),T),set:k=>{y=k}}),typeof r.init=="function"&&r.init(m),m}function n(u,l){let y=r(this.namespace+(typeof l>"u"?":":l)+u);return y.log=this.log,y}function o(u){r.save(u),r.namespaces=u,r.names=[],r.skips=[];let l,y=(typeof u=="string"?u:"").split(/[\s,]+/),D=y.length;for(l=0;l<D;l++)y[l]&&(u=y[l].replace(/\*/g,".*?"),u[0]==="-"?r.skips.push(new RegExp("^"+u.substr(1)+"$")):r.names.push(new RegExp("^"+u+"$")))}function i(){let u=[...r.names.map(a),...r.skips.map(a).map(l=>"-"+l)].join(",");return r.enable(""),u}function s(u){if(u[u.length-1]==="*")return!0;let l,y;for(l=0,y=r.skips.length;l<y;l++)if(r.skips[l].test(u))return!1;for(l=0,y=r.names.length;l<y;l++)if(r.names[l].test(u))return!0;return!1}function a(u){return u.toString().substring(2,u.toString().length-2).replace(/\.\*\?$/,"*")}function c(u){return u instanceof Error?u.stack??u.message:u}function f(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return r.setupFormatters(r.formatters),r.enable(r.load()),r}var nn=xf(),df=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function hf(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/(edge|trident)\/(\d+)/)!=null?!1:typeof document<"u"&&document.documentElement?.style?.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/firefox\/(\d+)/)!=null&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/applewebkit\/(\d+)/)}function pf(e){if(e[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+e[0]+(this.useColors?"%c ":" ")+"+"+rn(this.diff),!this.useColors)return;let t="color: "+this.color;e.splice(1,0,t,"color: inherit");let r=0,n=0;e[0].replace(/%[a-zA-Z%]/g,o=>{o!=="%%"&&(r++,o==="%c"&&(n=r))}),e.splice(n,0,t)}var mf=console.debug??console.log??(()=>{});function yf(e){try{e?nn?.setItem("debug",e):nn?.removeItem("debug")}catch{}}function gf(){let e;try{e=nn?.getItem("debug")}catch{}return!e&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(e=globalThis.process.env.DEBUG),e}function xf(){try{return localStorage}catch{}}function wf(e){e.j=function(t){try{return JSON.stringify(t)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var fs=wo({formatArgs:pf,save:yf,load:gf,useColors:hf,setupFormatters:wf,colors:df,storage:nn,log:mf});var vt=fs;vt.formatters.b=e=>e==null?"undefined":X.baseEncode(e);vt.formatters.t=e=>e==null?"undefined":me.baseEncode(e);vt.formatters.m=e=>e==null?"undefined":go.baseEncode(e);vt.formatters.p=e=>e==null?"undefined":e.toString();vt.formatters.c=e=>e==null?"undefined":e.toString();vt.formatters.k=e=>e==null?"undefined":e.toString();vt.formatters.a=e=>e==null?"undefined":e.toString();vt.formatters.e=e=>e==null?"undefined":ls(e.stack)??ls(e.message)??e.toString();function bf(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 ye(e){let t=bf(`${e}:trace`);return vt.enabled(`${e}:trace`)&&vt.names.map(r=>r.toString()).find(r=>r.includes(":trace"))!=null&&(t=vt(`${e}:trace`)),Object.assign(vt(e),{error:vt(`${e}:error`),trace:t})}function ls(e){if(e!=null&&(e=e.trim(),e.length!==0))return e}var bo={};At(bo,{base36:()=>Mt,base36upper:()=>Ef});var Mt=pe({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Ef=pe({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Sf=ps,ds=128,Af=127,vf=~Af,Tf=Math.pow(2,31);function ps(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Tf;)t[r++]=e&255|ds,e/=128;for(;e&vf;)t[r++]=e&255|ds,e>>>=7;return t[r]=e|0,ps.bytes=r-n+1,t}var Cf=Eo,Bf=128,hs=127;function Eo(e,n){var r=0,n=n||0,o=0,i=n,s,a=e.length;do{if(i>=a)throw Eo.bytes=0,new RangeError("Could not decode varint");s=e[i++],r+=o<28?(s&hs)<<o:(s&hs)*Math.pow(2,o),o+=7}while(s>=Bf);return Eo.bytes=i-n,r}var If=Math.pow(2,7),_f=Math.pow(2,14),Uf=Math.pow(2,21),Df=Math.pow(2,28),Rf=Math.pow(2,35),Nf=Math.pow(2,42),Lf=Math.pow(2,49),Pf=Math.pow(2,56),kf=Math.pow(2,63),Kf=function(e){return e<If?1:e<_f?2:e<Uf?3:e<Df?4:e<Rf?5:e<Nf?6:e<Lf?7:e<Pf?8:e<kf?9:10},Of={encode:Sf,decode:Cf,encodingLength:Kf},Mf=Of,wr=Mf;function br(e,t=0){return[wr.decode(e,t),wr.decode.bytes]}function Je(e,t,r=0){return wr.encode(e,t,r),t}function Qe(e){return wr.encodingLength(e)}function Ft(e,t){let r=t.byteLength,n=Qe(e),o=n+Qe(r),i=new Uint8Array(o+r);return Je(e,i,0),Je(r,i,n),i.set(t,o),new tr(e,r,t,i)}function te(e){let t=Qt(e),[r,n]=br(t),[o,i]=br(t.subarray(n)),s=t.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new tr(r,o,s,t)}function ms(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&os(e.bytes,r.bytes)}}var tr=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function ys(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return Vf(r,So(e),t??X.encoder);default:return Hf(r,So(e),t??me.encoder)}}var gs=new WeakMap;function So(e){let t=gs.get(e);if(t==null){let r=new Map;return gs.set(e,r),r}return t}var J=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==Er)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==qf)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:r}=this.multihash,n=Ft(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&ms(t.multihash,n.multihash)}toString(t){return ys(this,t)}toJSON(){return{"/":ys(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:i,bytes:s}=r;return new e(n,o,i,s??xs(n,o,i.bytes))}else if(r[zf]===!0){let{version:n,multihash:o,code:i}=r,s=te(o);return e.create(n,i,s)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==Er)throw new Error(`Version 0 CID must use dag-pb (code: ${Er}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=xs(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,Er,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=Qt(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=o.subarray(r.multihashSize-r.digestSize),s=new tr(r.multihashCode,r.digestSize,i,o);return[r.version===0?e.createV0(s):e.createV1(r.codec,s),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[l,y]=br(t.subarray(r));return r+=y,l},o=n(),i=Er;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=r,a=n(),c=n(),f=r+c,u=f-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:u,size:f}}static parse(t,r){let[n,o]=Ff(t,r),i=e.decode(o);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return So(i).set(n,t),i}};function Ff(e,t){switch(e[0]){case"Q":{let r=t??X;return[X.prefix,r.decode(`${X.prefix}${e}`)]}case X.prefix:{let r=t??X;return[X.prefix,r.decode(e)]}case me.prefix:{let r=t??me;return[me.prefix,r.decode(e)]}case Mt.prefix:{let r=t??Mt;return[Mt.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function Vf(e,t,r){let{prefix:n}=r;if(n!==X.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let i=r.encode(e).slice(1);return t.set(n,i),i}else return o}function Hf(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let i=r.encode(e);return t.set(n,i),i}else return o}var Er=112,qf=18;function xs(e,t,r){let n=Qe(e),o=n+Qe(t),i=new Uint8Array(o+r.byteLength);return Je(e,i,0),Je(t,i,n),i.set(r,o),i}var zf=Symbol.for("@ipld/js-cid/CID");var Ao={};At(Ao,{identity:()=>Vt});var ws=0,$f="identity",bs=Qt;function Gf(e){return Ft(ws,bs(e))}var Vt={code:ws,name:$f,encode:bs,digest:Gf};function ot(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Pt(e=0){return new Uint8Array(e)}function Bt(e=0){return new Uint8Array(e)}function xe(e,t){t==null&&(t=e.reduce((o,i)=>o+i.length,0));let r=Bt(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var Ss=Symbol.for("@achingbrain/uint8arraylist");function Es(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let o=r+n.byteLength;if(t<o)return{buf:n,index:t-r};r=o}throw new RangeError("index is out of bounds")}function sn(e){return!!e?.[Ss]}var It=class e{bufs;length;[Ss]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(sn(n))r+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...t){this.prependAll(t)}prependAll(t){let r=0;for(let n of t.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(sn(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(t){let r=Es(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Es(this.bufs,t);n.buf[n.index]=r}write(t,r=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(r+n,t[n]);else if(sn(t))for(let n=0;n<t.length;n++)this.set(r+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,r){let{bufs:n,length:o}=this._subList(t,r);return xe(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:xe(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),i=new e;return i.length=o,i.bufs=[...n],i}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let i=0;i<this.bufs.length;i++){let s=this.bufs[i],a=o,c=a+s.byteLength;if(o=c,t>=c)continue;let f=t>=a&&t<c,u=r>a&&r<=c;if(f&&u){if(t===a&&r===c){n.push(s);break}let l=t-a;n.push(s.subarray(l,l+(r-t)));break}if(f){if(t===0){n.push(s);continue}n.push(s.subarray(t-a));continue}if(u){if(r===c){n.push(s);break}n.push(s.subarray(0,r-a));break}n.push(s)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!sn(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,s=new Int32Array(i);for(let l=0;l<i;l++)s[l]=-1;for(let l=0;l<o;l++)s[n[l]]=l;let a=s,c=this.byteLength-n.byteLength,f=n.byteLength-1,u;for(let l=r;l<=c;l+=u){u=0;for(let y=f;y>=0;y--){let D=this.get(l+y);if(n[y]!==D){u=Math.max(1,y-a[D]);break}}if(u===0)return l}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=Bt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=Pt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=Pt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=Pt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=Bt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=Pt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=Pt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=Pt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=Pt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=Pt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!ot(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,i)=>o+i.byteLength,0)),n.length=r,n}};var vo={};At(vo,{base10:()=>Zf});var Zf=pe({prefix:"9",name:"base10",alphabet:"0123456789"});var To={};At(To,{base16:()=>Yf,base16upper:()=>jf});var Yf=rt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),jf=rt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Co={};At(Co,{base2:()=>Wf});var Wf=rt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Bo={};At(Bo,{base256emoji:()=>el});var As=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),Xf=As.reduce((e,t,r)=>(e[r]=t,e),[]),Jf=As.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Qf(e){return e.reduce((t,r)=>(t+=Xf[r],t),"")}function tl(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Jf[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var el=Xe({prefix:"\u{1F680}",name:"base256emoji",encode:Qf,decode:tl});var Io={};At(Io,{base8:()=>rl});var rl=rt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var _o={};At(_o,{identity:()=>nl});var nl=Xe({prefix:"\0",name:"identity",encode:e=>ss(e),decode:e=>is(e)});var D0=new TextEncoder,R0=new TextDecoder;var Ro={};At(Ro,{sha256:()=>Sr,sha512:()=>sl});function Do({name:e,code:t,encode:r}){return new Uo(e,t,r)}var Uo=class{name;code;encode;constructor(t,r,n){this.name=t,this.code=r,this.encode=n}digest(t){if(t instanceof Uint8Array){let r=this.encode(t);return r instanceof Uint8Array?Ft(this.code,r):r.then(n=>Ft(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Ts(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var Sr=Do({name:"sha2-256",code:18,encode:Ts("SHA-256")}),sl=Do({name:"sha2-512",code:19,encode:Ts("SHA-512")});var No={..._o,...Co,...Io,...vo,...To,...mo,...bo,...yo,...xo,...Bo},z0={...Ro,...Ao};function Bs(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Cs=Bs("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Lo=Bs("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=Bt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),al={utf8:Cs,"utf-8":Cs,hex:No.base16,latin1:Lo,ascii:Lo,binary:Lo,...No},an=al;function G(e,t="utf8"){let r=an[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function j(e,t="utf8"){let r=an[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var cl=parseInt("11111",2),Po=parseInt("10000000",2),ul=parseInt("01111111",2),Is={0:Ar,1:Ar,2:fl,3:hl,4:pl,5:dl,6:ll,16:Ar,22:Ar,48:Ar};function ee(e,t={offset:0}){let r=e[t.offset]&cl;if(t.offset++,Is[r]!=null)return Is[r](e,t);throw new Error("No decoder for tag "+r)}function vr(e,t){let r=0;if((e[t.offset]&Po)===Po){let n=e[t.offset]&ul,o="0x";t.offset++;for(let i=0;i<n;i++,t.offset++)o+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=e[t.offset],t.offset++;return r}function Ar(e,t){vr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=ee(e,t);if(n===null)break;r.push(n)}return r}function fl(e,t){let r=vr(e,t),n=t.offset,o=t.offset+r,i=[];for(let s=n;s<o;s++)s===n&&e[s]===0||i.push(e[s]);return t.offset+=r,Uint8Array.from(i)}function ll(e,t){let r=vr(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let i=0,s=0;o<40?(i=0,s=o):o<80?(i=1,s=o-40):(i=2,s=o-80);let a=`${i}.${s}`,c=[];for(;t.offset<n;){let f=e[t.offset];if(t.offset++,c.push(f&127),f<128){c.reverse();let u=0;for(let l=0;l<c.length;l++)u+=c[l]<<l*7;a+=`.${u}`,c=[]}}return a}function dl(e,t){return t.offset++,null}function hl(e,t){let r=vr(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function pl(e,t){let r=vr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function ml(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new It;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function ko(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=ml(e.byteLength);return new It(Uint8Array.from([t.byteLength|Po]),t)}function Tt(e){let t=new It,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new It(Uint8Array.from([2]),ko(t),t)}function cn(e){let t=Uint8Array.from([0]),r=new It(t,e);return new It(Uint8Array.from([3]),ko(r),r)}function we(e,t=48){let r=new It;for(let n of e)r.append(n);return new It(Uint8Array.from([t]),ko(r),r)}async function _s(e,t,r){let n=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);return crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},n,t,r.subarray())}var yl=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),gl=Uint8Array.from([6,5,43,129,4,0,34]),xl=Uint8Array.from([6,5,43,129,4,0,35]),wl={ext:!0,kty:"EC",crv:"P-256"},bl={ext:!0,kty:"EC",crv:"P-384"},El={ext:!0,kty:"EC",crv:"P-521"},Ko=32,Oo=48,Mo=66;function Fo(e){let t=ee(e);return Us(t)}function Us(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Ko*2+1)return n=j(t.subarray(r,r+Ko),"base64url"),o=j(t.subarray(r+Ko),"base64url"),new er({...wl,key_ops:["verify"],x:n,y:o});if(t.byteLength===Oo*2+1)return n=j(t.subarray(r,r+Oo),"base64url"),o=j(t.subarray(r+Oo),"base64url"),new er({...bl,key_ops:["verify"],x:n,y:o});if(t.byteLength===Mo*2+1)return n=j(t.subarray(r,r+Mo),"base64url"),o=j(t.subarray(r+Mo),"base64url"),new er({...El,key_ops:["verify"],x:n,y:o});throw new at(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Ds(e){return we([Tt(Uint8Array.from([1])),we([Sl(e.crv)],160),we([cn(new It(Uint8Array.from([4]),G(e.x??"","base64url"),G(e.y??"","base64url")))],161)]).subarray()}function Sl(e){if(e==="P-256")return yl;if(e==="P-384")return gl;if(e==="P-521")return xl;throw new at(`Invalid curve ${e}`)}var er=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Ds(this.jwk)),this._raw}toMultihash(){return Vt.digest(be(this))}toCID(){return J.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ot(this.raw,t.raw)}async verify(t,r){return _s(this.jwk,r,t)}};var Le=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Al(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function un(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function Pe(e,...t){if(!Al(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function Rs(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");un(e.outputLen),un(e.blockLen)}function nr(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Ns(e,t){Pe(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function re(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function fn(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Ht(e,t){return e<<32-t|e>>>t}function Ls(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function Tr(e){return typeof e=="string"&&(e=Ls(e)),Pe(e),e}function Vo(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];Pe(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let i=e[n];r.set(i,o),o+=i.length}return r}var rr=class{};function Ho(e){let t=n=>e().update(Tr(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function ln(e=32){if(Le&&typeof Le.getRandomValues=="function")return Le.getRandomValues(new Uint8Array(e));if(Le&&typeof Le.randomBytes=="function")return Uint8Array.from(Le.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function vl(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let o=BigInt(32),i=BigInt(4294967295),s=Number(r>>o&i),a=Number(r&i),c=n?4:0,f=n?0:4;e.setUint32(t+c,s,n),e.setUint32(t+f,a,n)}function Ps(e,t,r){return e&t^~e&r}function ks(e,t,r){return e&t^e&r^t&r}var Cr=class extends rr{constructor(t,r,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=fn(this.buffer)}update(t){nr(this),t=Tr(t),Pe(t);let{view:r,buffer:n,blockLen:o}=this,i=t.length;for(let s=0;s<i;){let a=Math.min(o-this.pos,i-s);if(a===o){let c=fn(t);for(;o<=i-s;s+=o)this.process(c,s);continue}n.set(t.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){nr(this),Ns(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;r[s++]=128,re(this.buffer.subarray(s)),this.padOffset>o-s&&(this.process(n,0),s=0);for(let l=s;l<o;l++)r[l]=0;vl(n,o-8,BigInt(this.length*8),i),this.process(n,0);let a=fn(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=c/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<f;l++)a.setUint32(4*l,u[l],i)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:i,destroyed:s,pos:a}=this;return t.destroyed=s,t.finished=i,t.length=o,t.pos=a,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},ne=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ht=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var dn=BigInt(4294967295),Ks=BigInt(32);function Tl(e,t=!1){return t?{h:Number(e&dn),l:Number(e>>Ks&dn)}:{h:Number(e>>Ks&dn)|0,l:Number(e&dn)|0}}function Os(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let i=0;i<r;i++){let{h:s,l:a}=Tl(e[i],t);[n[i],o[i]]=[s,a]}return[n,o]}var qo=(e,t,r)=>e>>>r,zo=(e,t,r)=>e<<32-r|t>>>r,ke=(e,t,r)=>e>>>r|t<<32-r,Ke=(e,t,r)=>e<<32-r|t>>>r,Br=(e,t,r)=>e<<64-r|t>>>r-32,Ir=(e,t,r)=>e>>>r-32|t<<64-r;function Zt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var Ms=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Fs=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,Vs=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),Hs=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,qs=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),zs=(e,t,r,n,o,i)=>t+r+n+o+i+(e/2**32|0)|0;var Bl=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Ee=new Uint32Array(64),hn=class extends Cr{constructor(t=32){super(64,t,8,!1),this.A=ne[0]|0,this.B=ne[1]|0,this.C=ne[2]|0,this.D=ne[3]|0,this.E=ne[4]|0,this.F=ne[5]|0,this.G=ne[6]|0,this.H=ne[7]|0}get(){let{A:t,B:r,C:n,D:o,E:i,F:s,G:a,H:c}=this;return[t,r,n,o,i,s,a,c]}set(t,r,n,o,i,s,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}process(t,r){for(let l=0;l<16;l++,r+=4)Ee[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let y=Ee[l-15],D=Ee[l-2],T=Ht(y,7)^Ht(y,18)^y>>>3,m=Ht(D,17)^Ht(D,19)^D>>>10;Ee[l]=m+Ee[l-7]+T+Ee[l-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:f,H:u}=this;for(let l=0;l<64;l++){let y=Ht(a,6)^Ht(a,11)^Ht(a,25),D=u+y+Ps(a,c,f)+Bl[l]+Ee[l]|0,m=(Ht(n,2)^Ht(n,13)^Ht(n,22))+ks(n,o,i)|0;u=f,f=c,c=a,a=s+D|0,s=i,i=o,o=n,n=D+m|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(n,o,i,s,a,c,f,u)}roundClean(){re(Ee)}destroy(){this.set(0,0,0,0,0,0,0,0),re(this.buffer)}};var $s=Os(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))),Il=$s[0],_l=$s[1],Se=new Uint32Array(80),Ae=new Uint32Array(80),$o=class extends Cr{constructor(t=64){super(128,t,16,!1),this.Ah=ht[0]|0,this.Al=ht[1]|0,this.Bh=ht[2]|0,this.Bl=ht[3]|0,this.Ch=ht[4]|0,this.Cl=ht[5]|0,this.Dh=ht[6]|0,this.Dl=ht[7]|0,this.Eh=ht[8]|0,this.El=ht[9]|0,this.Fh=ht[10]|0,this.Fl=ht[11]|0,this.Gh=ht[12]|0,this.Gl=ht[13]|0,this.Hh=ht[14]|0,this.Hl=ht[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:i,Cl:s,Dh:a,Dl:c,Eh:f,El:u,Fh:l,Fl:y,Gh:D,Gl:T,Hh:m,Hl:k}=this;return[t,r,n,o,i,s,a,c,f,u,l,y,D,T,m,k]}set(t,r,n,o,i,s,a,c,f,u,l,y,D,T,m,k){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=i|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=u|0,this.Fh=l|0,this.Fl=y|0,this.Gh=D|0,this.Gl=T|0,this.Hh=m|0,this.Hl=k|0}process(t,r){for(let C=0;C<16;C++,r+=4)Se[C]=t.getUint32(r),Ae[C]=t.getUint32(r+=4);for(let C=16;C<80;C++){let d=Se[C-15]|0,S=Ae[C-15]|0,R=ke(d,S,1)^ke(d,S,8)^qo(d,S,7),L=Ke(d,S,1)^Ke(d,S,8)^zo(d,S,7),g=Se[C-2]|0,A=Ae[C-2]|0,N=ke(g,A,19)^Br(g,A,61)^qo(g,A,6),v=Ke(g,A,19)^Ir(g,A,61)^zo(g,A,6),B=Vs(L,v,Ae[C-7],Ae[C-16]),U=Hs(B,R,N,Se[C-7],Se[C-16]);Se[C]=U|0,Ae[C]=B|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:f,Dl:u,Eh:l,El:y,Fh:D,Fl:T,Gh:m,Gl:k,Hh:O,Hl:q}=this;for(let C=0;C<80;C++){let d=ke(l,y,14)^ke(l,y,18)^Br(l,y,41),S=Ke(l,y,14)^Ke(l,y,18)^Ir(l,y,41),R=l&D^~l&m,L=y&T^~y&k,g=qs(q,S,L,_l[C],Ae[C]),A=zs(g,O,d,R,Il[C],Se[C]),N=g|0,v=ke(n,o,28)^Br(n,o,34)^Br(n,o,39),B=Ke(n,o,28)^Ir(n,o,34)^Ir(n,o,39),U=n&i^n&a^i&a,H=o&s^o&c^s&c;O=m|0,q=k|0,m=D|0,k=T|0,D=l|0,T=y|0,{h:l,l:y}=Zt(f|0,u|0,A|0,N|0),f=a|0,u=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let x=Ms(N,B,H);n=Fs(x,A,v,U),o=x|0}({h:n,l:o}=Zt(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=Zt(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=Zt(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=Zt(this.Dh|0,this.Dl|0,f|0,u|0),{h:l,l:y}=Zt(this.Eh|0,this.El|0,l|0,y|0),{h:D,l:T}=Zt(this.Fh|0,this.Fl|0,D|0,T|0),{h:m,l:k}=Zt(this.Gh|0,this.Gl|0,m|0,k|0),{h:O,l:q}=Zt(this.Hh|0,this.Hl|0,O|0,q|0),this.set(n,o,i,s,a,c,f,u,l,y,D,T,m,k,O,q)}roundClean(){re(Se,Ae)}destroy(){re(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var pn=Ho(()=>new hn);var Gs=Ho(()=>new $o);var jo=BigInt(0),Yo=BigInt(1);function or(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Wo(e){if(!or(e))throw new Error("Uint8Array expected")}function Yt(e,t){if(typeof t!="boolean")throw new Error(e+" boolean expected, got "+t)}function _r(e){let t=e.toString(16);return t.length&1?"0"+t:t}function js(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?jo:BigInt("0x"+e)}var Ws=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Ul=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function ve(e){if(Wo(e),Ws)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Ul[e[r]];return t}var oe={_0:48,_9:57,A:65,F:70,a:97,f:102};function Zs(e){if(e>=oe._0&&e<=oe._9)return e-oe._0;if(e>=oe.A&&e<=oe.F)return e-(oe.A-10);if(e>=oe.a&&e<=oe.f)return e-(oe.a-10)}function Ur(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(Ws)return Uint8Array.fromHex(e);let t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,i=0;o<r;o++,i+=2){let s=Zs(e.charCodeAt(i)),a=Zs(e.charCodeAt(i+1));if(s===void 0||a===void 0){let c=e[i]+e[i+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+i)}n[o]=s*16+a}return n}function ie(e){return js(ve(e))}function Oe(e){return Wo(e),js(ve(Uint8Array.from(e).reverse()))}function Me(e,t){return Ur(e.toString(16).padStart(t*2,"0"))}function ir(e,t){return Me(e,t).reverse()}function tt(e,t,r){let n;if(typeof t=="string")try{n=Ur(t)}catch(i){throw new Error(e+" must be hex string or Uint8Array, cause: "+i)}else if(or(t))n=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");let o=n.length;if(typeof r=="number"&&o!==r)throw new Error(e+" of length "+r+" expected, got "+o);return n}function Te(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];Wo(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let i=e[n];r.set(i,o),o+=i.length}return r}var Go=e=>typeof e=="bigint"&&jo<=e;function mn(e,t,r){return Go(e)&&Go(t)&&Go(r)&&t<=e&&e<r}function _t(e,t,r,n){if(!mn(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Xs(e){let t;for(t=0;e>jo;e>>=Yo,t+=1);return t}var Fe=e=>(Yo<<BigInt(e))-Yo,Zo=e=>new Uint8Array(e),Ys=e=>Uint8Array.from(e);function Js(e,t,r){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=Zo(e),o=Zo(e),i=0,s=()=>{n.fill(1),o.fill(0),i=0},a=(...l)=>r(o,n,...l),c=(l=Zo(0))=>{o=a(Ys([0]),l),n=a(),l.length!==0&&(o=a(Ys([1]),l),n=a())},f=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let l=0,y=[];for(;l<t;){n=a();let D=n.slice();y.push(D),l+=n.length}return Te(...y)};return(l,y)=>{s(),c(l);let D;for(;!(D=y(f()));)c();return s(),D}}var Dl={bigint:e=>typeof e=="bigint",function:e=>typeof e=="function",boolean:e=>typeof e=="boolean",string:e=>typeof e=="string",stringOrUint8Array:e=>typeof e=="string"||or(e),isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,t)=>t.Fp.isValid(e),hash:e=>typeof e=="function"&&Number.isSafeInteger(e.outputLen)};function se(e,t,r={}){let n=(o,i,s)=>{let a=Dl[i];if(typeof a!="function")throw new Error("invalid validator function");let c=e[o];if(!(s&&c===void 0)&&!a(c,e))throw new Error("param "+String(o)+" is invalid. Expected "+i+", got "+c)};for(let[o,i]of Object.entries(t))n(o,i,!1);for(let[o,i]of Object.entries(r))n(o,i,!0);return e}function sr(e){let t=new WeakMap;return(r,...n)=>{let o=t.get(r);if(o!==void 0)return o;let i=e(r,...n);return t.set(r,i),i}}var wt=BigInt(0),ut=BigInt(1),Ve=BigInt(2),Rl=BigInt(3),ta=BigInt(4),ea=BigInt(5),ra=BigInt(8);function Q(e,t){let r=e%t;return r>=wt?r:t+r}function et(e,t,r){let n=e;for(;t-- >wt;)n*=n,n%=r;return n}function yn(e,t){if(e===wt)throw new Error("invert: expected non-zero number");if(t<=wt)throw new Error("invert: expected positive modulus, got "+t);let r=Q(e,t),n=t,o=wt,i=ut,s=ut,a=wt;for(;r!==wt;){let f=n/r,u=n%r,l=o-s*f,y=i-a*f;n=r,r=u,o=s,i=a,s=l,a=y}if(n!==ut)throw new Error("invert: does not exist");return Q(o,t)}function na(e,t){let r=(e.ORDER+ut)/ta,n=e.pow(t,r);if(!e.eql(e.sqr(n),t))throw new Error("Cannot find square root");return n}function Nl(e,t){let r=(e.ORDER-ea)/ra,n=e.mul(t,Ve),o=e.pow(n,r),i=e.mul(t,o),s=e.mul(e.mul(i,Ve),o),a=e.mul(i,e.sub(s,e.ONE));if(!e.eql(e.sqr(a),t))throw new Error("Cannot find square root");return a}function Ll(e){if(e<BigInt(3))throw new Error("sqrt is not defined for small field");let t=e-ut,r=0;for(;t%Ve===wt;)t/=Ve,r++;let n=Ve,o=ae(e);for(;Qs(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return na;let i=o.pow(n,t),s=(t+ut)/Ve;return function(c,f){if(c.is0(f))return f;if(Qs(c,f)!==1)throw new Error("Cannot find square root");let u=r,l=c.mul(c.ONE,i),y=c.pow(f,t),D=c.pow(f,s);for(;!c.eql(y,c.ONE);){if(c.is0(y))return c.ZERO;let T=1,m=c.sqr(y);for(;!c.eql(m,c.ONE);)if(T++,m=c.sqr(m),T===u)throw new Error("Cannot find square root");let k=ut<<BigInt(u-T-1),O=c.pow(l,k);u=T,l=c.sqr(O),y=c.mul(y,l),D=c.mul(D,O)}return D}}function Pl(e){return e%ta===Rl?na:e%ra===ea?Nl:Ll(e)}var oa=(e,t)=>(Q(e,t)&ut)===ut,kl=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Xo(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},r=kl.reduce((n,o)=>(n[o]="function",n),t);return se(e,r)}function Kl(e,t,r){if(r<wt)throw new Error("invalid exponent, negatives unsupported");if(r===wt)return e.ONE;if(r===ut)return t;let n=e.ONE,o=t;for(;r>wt;)r&ut&&(n=e.mul(n,o)),o=e.sqr(o),r>>=ut;return n}function ar(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((s,a,c)=>e.is0(a)?s:(n[c]=s,e.mul(s,a)),e.ONE),i=e.inv(o);return t.reduceRight((s,a,c)=>e.is0(a)?s:(n[c]=e.mul(s,n[c]),e.mul(s,a)),i),n}function Qs(e,t){let r=(e.ORDER-ut)/Ve,n=e.pow(t,r),o=e.eql(n,e.ONE),i=e.eql(n,e.ZERO),s=e.eql(n,e.neg(e.ONE));if(!o&&!i&&!s)throw new Error("invalid Legendre symbol result");return o?1:i?0:-1}function Jo(e,t){t!==void 0&&un(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function ae(e,t,r=!1,n={}){if(e<=wt)throw new Error("invalid field: expected ORDER > 0, got "+e);let{nBitLength:o,nByteLength:i}=Jo(e,t);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let s,a=Object.freeze({ORDER:e,isLE:r,BITS:o,BYTES:i,MASK:Fe(o),ZERO:wt,ONE:ut,create:c=>Q(c,e),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return wt<=c&&c<e},is0:c=>c===wt,isOdd:c=>(c&ut)===ut,neg:c=>Q(-c,e),eql:(c,f)=>c===f,sqr:c=>Q(c*c,e),add:(c,f)=>Q(c+f,e),sub:(c,f)=>Q(c-f,e),mul:(c,f)=>Q(c*f,e),pow:(c,f)=>Kl(a,c,f),div:(c,f)=>Q(c*yn(f,e),e),sqrN:c=>c*c,addN:(c,f)=>c+f,subN:(c,f)=>c-f,mulN:(c,f)=>c*f,inv:c=>yn(c,e),sqrt:n.sqrt||(c=>(s||(s=Pl(e)),s(a,c))),toBytes:c=>r?ir(c,i):Me(c,i),fromBytes:c=>{if(c.length!==i)throw new Error("Field.fromBytes: expected "+i+" bytes, got "+c.length);return r?Oe(c):ie(c)},invertBatch:c=>ar(a,c),cmov:(c,f,u)=>u?f:c});return Object.freeze(a)}function ia(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function Qo(e){let t=ia(e);return t+Math.ceil(t/2)}function sa(e,t,r=!1){let n=e.length,o=ia(t),i=Qo(t);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=r?Oe(e):ie(e),a=Q(s,t-ut)+ut;return r?ir(a,o):Me(a,o)}var aa=BigInt(0),oi=BigInt(1);function ti(e,t){let r=t.negate();return e?r:t}function ua(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function ei(e,t){ua(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,i=Fe(e),s=BigInt(e);return{windows:r,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function ca(e,t,r){let{windowSize:n,mask:o,maxNumber:i,shiftBy:s}=r,a=Number(e&o),c=e>>s;a>n&&(a-=i,c+=oi);let f=t*n,u=f+Math.abs(a)-1,l=a===0,y=a<0,D=t%2!==0;return{nextN:c,offset:u,isZero:l,isNeg:y,isNegF:D,offsetF:f}}function Ol(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function Ml(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((r,n)=>{if(!t.isValid(r))throw new Error("invalid scalar at index "+n)})}var ri=new WeakMap,fa=new WeakMap;function ni(e){return fa.get(e)||1}function gn(e,t){return{constTimeNegate:ti,hasPrecomputes(r){return ni(r)!==1},unsafeLadder(r,n,o=e.ZERO){let i=r;for(;n>aa;)n&oi&&(o=o.add(i)),i=i.double(),n>>=oi;return o},precomputeWindow(r,n){let{windows:o,windowSize:i}=ei(n,t),s=[],a=r,c=a;for(let f=0;f<o;f++){c=a,s.push(c);for(let u=1;u<i;u++)c=c.add(a),s.push(c);a=c.double()}return s},wNAF(r,n,o){let i=e.ZERO,s=e.BASE,a=ei(r,t);for(let c=0;c<a.windows;c++){let{nextN:f,offset:u,isZero:l,isNeg:y,isNegF:D,offsetF:T}=ca(o,c,a);o=f,l?s=s.add(ti(D,n[T])):i=i.add(ti(y,n[u]))}return{p:i,f:s}},wNAFUnsafe(r,n,o,i=e.ZERO){let s=ei(r,t);for(let a=0;a<s.windows&&o!==aa;a++){let{nextN:c,offset:f,isZero:u,isNeg:l}=ca(o,a,s);if(o=c,!u){let y=n[f];i=i.add(l?y.negate():y)}}return i},getPrecomputes(r,n,o){let i=ri.get(n);return i||(i=this.precomputeWindow(n,r),r!==1&&ri.set(n,o(i))),i},wNAFCached(r,n,o){let i=ni(r);return this.wNAF(i,this.getPrecomputes(i,r,o),n)},wNAFCachedUnsafe(r,n,o,i){let s=ni(r);return s===1?this.unsafeLadder(r,n,i):this.wNAFUnsafe(s,this.getPrecomputes(s,r,o),n,i)},setWindowSize(r,n){ua(n,t),fa.set(r,n),ri.delete(r)}}}function xn(e,t,r,n){Ol(r,e),Ml(n,t);let o=r.length,i=n.length;if(o!==i)throw new Error("arrays of points and scalars must have equal length");let s=e.ZERO,a=Xs(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let f=Fe(c),u=new Array(Number(f)+1).fill(s),l=Math.floor((t.BITS-1)/c)*c,y=s;for(let D=l;D>=0;D-=c){u.fill(s);for(let m=0;m<i;m++){let k=n[m],O=Number(k>>BigInt(D)&f);u[O]=u[O].add(r[m])}let T=s;for(let m=u.length-1,k=s;m>0;m--)k=k.add(u[m]),T=T.add(k);if(y=y.add(T),D!==0)for(let m=0;m<c;m++)y=y.double()}return y}function Dr(e){return Xo(e.Fp),se(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Jo(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}var jt=BigInt(0),bt=BigInt(1),la=BigInt(2),Fl=BigInt(8),Vl={zip215:!0};function Hl(e){let t=Dr(e);return se(e,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function da(e){let t=Hl(e),{Fp:r,n,prehash:o,hash:i,randomBytes:s,nByteLength:a,h:c}=t,f=la<<BigInt(a*8)-bt,u=r.create,l=ae(t.n,t.nBitLength);function y(E,h){let b=r.sqr(E),I=r.sqr(h),M=r.add(r.mul(t.a,b),I),V=r.add(r.ONE,r.mul(t.d,r.mul(b,I)));return r.eql(M,V)}if(!y(t.Gx,t.Gy))throw new Error("bad curve params: generator point");let D=t.uvRatio||((E,h)=>{try{return{isValid:!0,value:r.sqrt(E*r.inv(h))}}catch{return{isValid:!1,value:jt}}}),T=t.adjustScalarBytes||(E=>E),m=t.domain||((E,h,b)=>{if(Yt("phflag",b),h.length||b)throw new Error("Contexts/pre-hash are not supported");return E});function k(E,h,b=!1){let I=b?bt:jt;_t("coordinate "+E,h,I,f)}function O(E){if(!(E instanceof d))throw new Error("ExtendedPoint expected")}let q=sr((E,h)=>{let{ex:b,ey:I,ez:M}=E,V=E.is0();h==null&&(h=V?Fl:r.inv(M));let z=u(b*h),$=u(I*h),Y=u(M*h);if(V)return{x:jt,y:bt};if(Y!==bt)throw new Error("invZ was invalid");return{x:z,y:$}}),C=sr(E=>{let{a:h,d:b}=t;if(E.is0())throw new Error("bad point: ZERO");let{ex:I,ey:M,ez:V,et:z}=E,$=u(I*I),Y=u(M*M),W=u(V*V),st=u(W*W),nt=u($*h),dt=u(W*u(nt+Y)),St=u(st+u(b*u($*Y)));if(dt!==St)throw new Error("bad point: equation left != right (1)");let ct=u(I*M),yt=u(V*z);if(ct!==yt)throw new Error("bad point: equation left != right (2)");return!0});class d{constructor(h,b,I,M){k("x",h),k("y",b),k("z",I,!0),k("t",M),this.ex=h,this.ey=b,this.ez=I,this.et=M,Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(h){if(h instanceof d)throw new Error("extended point not allowed");let{x:b,y:I}=h||{};return k("x",b),k("y",I),new d(b,I,bt,u(b*I))}static normalizeZ(h){let b=ar(r,h.map(I=>I.ez));return h.map((I,M)=>I.toAffine(b[M])).map(d.fromAffine)}static msm(h,b){return xn(d,l,h,b)}_setWindowSize(h){L.setWindowSize(this,h)}assertValidity(){C(this)}equals(h){O(h);let{ex:b,ey:I,ez:M}=this,{ex:V,ey:z,ez:$}=h,Y=u(b*$),W=u(V*M),st=u(I*$),nt=u(z*M);return Y===W&&st===nt}is0(){return this.equals(d.ZERO)}negate(){return new d(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){let{a:h}=t,{ex:b,ey:I,ez:M}=this,V=u(b*b),z=u(I*I),$=u(la*u(M*M)),Y=u(h*V),W=b+I,st=u(u(W*W)-V-z),nt=Y+z,dt=nt-$,St=Y-z,ct=u(st*dt),yt=u(nt*St),Ct=u(st*St),Ot=u(dt*nt);return new d(ct,yt,Ot,Ct)}add(h){O(h);let{a:b,d:I}=t,{ex:M,ey:V,ez:z,et:$}=this,{ex:Y,ey:W,ez:st,et:nt}=h,dt=u(M*Y),St=u(V*W),ct=u($*I*nt),yt=u(z*st),Ct=u((M+V)*(Y+W)-dt-St),Ot=yt-ct,gr=yt+ct,ts=u(St-b*dt),Ru=u(Ct*Ot),Nu=u(gr*ts),Lu=u(Ct*ts),Pu=u(Ot*gr);return new d(Ru,Nu,Pu,Lu)}subtract(h){return this.add(h.negate())}wNAF(h){return L.wNAFCached(this,h,d.normalizeZ)}multiply(h){let b=h;_t("scalar",b,bt,n);let{p:I,f:M}=this.wNAF(b);return d.normalizeZ([I,M])[0]}multiplyUnsafe(h,b=d.ZERO){let I=h;return _t("scalar",I,jt,n),I===jt?R:this.is0()||I===bt?this:L.wNAFCachedUnsafe(this,I,d.normalizeZ,b)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return L.unsafeLadder(this,n).is0()}toAffine(h){return q(this,h)}clearCofactor(){let{h}=t;return h===bt?this:this.multiplyUnsafe(h)}static fromHex(h,b=!1){let{d:I,a:M}=t,V=r.BYTES;h=tt("pointHex",h,V),Yt("zip215",b);let z=h.slice(),$=h[V-1];z[V-1]=$&-129;let Y=Oe(z),W=b?f:r.ORDER;_t("pointHex.y",Y,jt,W);let st=u(Y*Y),nt=u(st-bt),dt=u(I*st-M),{isValid:St,value:ct}=D(nt,dt);if(!St)throw new Error("Point.fromHex: invalid y coordinate");let yt=(ct&bt)===bt,Ct=($&128)!==0;if(!b&&ct===jt&&Ct)throw new Error("Point.fromHex: x=0 and x_0=1");return Ct!==yt&&(ct=u(-ct)),d.fromAffine({x:ct,y:Y})}static fromPrivateKey(h){let{scalar:b}=N(h);return S.multiply(b)}toRawBytes(){let{x:h,y:b}=this.toAffine(),I=ir(b,r.BYTES);return I[I.length-1]|=h&bt?128:0,I}toHex(){return ve(this.toRawBytes())}}d.BASE=new d(t.Gx,t.Gy,bt,u(t.Gx*t.Gy)),d.ZERO=new d(jt,bt,bt,jt);let{BASE:S,ZERO:R}=d,L=gn(d,a*8);function g(E){return Q(E,n)}function A(E){return g(Oe(E))}function N(E){let h=r.BYTES;E=tt("private key",E,h);let b=tt("hashed private key",i(E),2*h),I=T(b.slice(0,h)),M=b.slice(h,2*h),V=A(I);return{head:I,prefix:M,scalar:V}}function v(E){let{head:h,prefix:b,scalar:I}=N(E),M=S.multiply(I),V=M.toRawBytes();return{head:h,prefix:b,scalar:I,point:M,pointBytes:V}}function B(E){return v(E).pointBytes}function U(E=Uint8Array.of(),...h){let b=Te(...h);return A(i(m(b,tt("context",E),!!o)))}function H(E,h,b={}){E=tt("message",E),o&&(E=o(E));let{prefix:I,scalar:M,pointBytes:V}=v(h),z=U(b.context,I,E),$=S.multiply(z).toRawBytes(),Y=U(b.context,$,V,E),W=g(z+Y*M);_t("signature.s",W,jt,n);let st=Te($,ir(W,r.BYTES));return tt("result",st,r.BYTES*2)}let x=Vl;function w(E,h,b,I=x){let{context:M,zip215:V}=I,z=r.BYTES;E=tt("signature",E,2*z),h=tt("message",h),b=tt("publicKey",b,z),V!==void 0&&Yt("zip215",V),o&&(h=o(h));let $=Oe(E.slice(z,2*z)),Y,W,st;try{Y=d.fromHex(b,V),W=d.fromHex(E.slice(0,z),V),st=S.multiplyUnsafe($)}catch{return!1}if(!V&&Y.isSmallOrder())return!1;let nt=U(M,W.toRawBytes(),Y.toRawBytes(),h);return W.add(Y.multiplyUnsafe(nt)).subtract(st).clearCofactor().equals(d.ZERO)}return S._setWindowSize(8),{CURVE:t,getPublicKey:B,sign:H,verify:w,ExtendedPoint:d,utils:{getExtendedPublicKey:v,randomPrivateKey:()=>s(r.BYTES),precompute(E=8,h=d.BASE){return h._setWindowSize(E),h.multiply(BigInt(3)),h}}}}var ii=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),ha=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Zp=BigInt(0),ql=BigInt(1),pa=BigInt(2),Yp=BigInt(3),zl=BigInt(5),$l=BigInt(8);function Gl(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),i=ii,a=e*e%i*e%i,c=et(a,pa,i)*a%i,f=et(c,ql,i)*e%i,u=et(f,zl,i)*f%i,l=et(u,t,i)*u%i,y=et(l,r,i)*l%i,D=et(y,n,i)*y%i,T=et(D,o,i)*D%i,m=et(T,o,i)*D%i,k=et(m,t,i)*u%i;return{pow_p_5_8:et(k,pa,i)*e%i,b2:a}}function Zl(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}function Yl(e,t){let r=ii,n=Q(t*t*t,r),o=Q(n*n*t,r),i=Gl(e*o).pow_p_5_8,s=Q(e*n*i,r),a=Q(t*s*s,r),c=s,f=Q(s*ha,r),u=a===e,l=a===Q(-e,r),y=a===Q(-e*ha,r);return u&&(s=c),(l||y)&&(s=f),oa(s,r)&&(s=Q(-s,r)),{isValid:u||l,value:s}}var ma=ae(ii,void 0,!0),jl={a:ma.create(BigInt(-1)),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:ma,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:$l,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Gs,randomBytes:ln,adjustScalarBytes:Zl,uvRatio:Yl},ya=da(jl);var wn=32;function ga(e,t,r){return ya.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}var bn=class{type="Ed25519";raw;constructor(t){this.raw=si(t,wn)}toMultihash(){return Vt.digest(be(this))}toCID(){return J.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ot(this.raw,t.raw)}verify(t,r){return ga(this.raw,r,t)}};function ai(e){return e=si(e,wn),new bn(e)}function si(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new at(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var Xl=Math.pow(2,7),Jl=Math.pow(2,14),Ql=Math.pow(2,21),wa=Math.pow(2,28),ba=Math.pow(2,35),Ea=Math.pow(2,42),Sa=Math.pow(2,49),Et=128,Ce=127;function Rr(e){if(e<Xl)return 1;if(e<Jl)return 2;if(e<Ql)return 3;if(e<wa)return 4;if(e<ba)return 5;if(e<Ea)return 6;if(e<Sa)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Aa(e,t,r=0){switch(Rr(e)){case 8:t[r++]=e&255|Et,e/=128;case 7:t[r++]=e&255|Et,e/=128;case 6:t[r++]=e&255|Et,e/=128;case 5:t[r++]=e&255|Et,e/=128;case 4:t[r++]=e&255|Et,e>>>=7;case 3:t[r++]=e&255|Et,e>>>=7;case 2:t[r++]=e&255|Et,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function va(e,t){let r=e[t],n=0;if(n+=r&Ce,r<Et||(r=e[t+1],n+=(r&Ce)<<7,r<Et)||(r=e[t+2],n+=(r&Ce)<<14,r<Et)||(r=e[t+3],n+=(r&Ce)<<21,r<Et)||(r=e[t+4],n+=(r&Ce)*wa,r<Et)||(r=e[t+5],n+=(r&Ce)*ba,r<Et)||(r=e[t+6],n+=(r&Ce)*Ea,r<Et)||(r=e[t+7],n+=(r&Ce)*Sa,r<Et))return n;throw new RangeError("Could not decode varint")}var ci=new Float32Array([-0]),Be=new Uint8Array(ci.buffer);function Ta(e,t,r){ci[0]=e,t[r]=Be[0],t[r+1]=Be[1],t[r+2]=Be[2],t[r+3]=Be[3]}function Ca(e,t){return Be[0]=e[t],Be[1]=e[t+1],Be[2]=e[t+2],Be[3]=e[t+3],ci[0]}var ui=new Float64Array([-0]),gt=new Uint8Array(ui.buffer);function Ba(e,t,r){ui[0]=e,t[r]=gt[0],t[r+1]=gt[1],t[r+2]=gt[2],t[r+3]=gt[3],t[r+4]=gt[4],t[r+5]=gt[5],t[r+6]=gt[6],t[r+7]=gt[7]}function Ia(e,t){return gt[0]=e[t],gt[1]=e[t+1],gt[2]=e[t+2],gt[3]=e[t+3],gt[4]=e[t+4],gt[5]=e[t+5],gt[6]=e[t+6],gt[7]=e[t+7],ui[0]}var td=BigInt(Number.MAX_SAFE_INTEGER),ed=BigInt(Number.MIN_SAFE_INTEGER),Ut=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return He;if(t<td&&t>ed)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,o=t-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>_a&&(o=0n,++n>_a&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return He;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):He}},He=new Ut(0,0);He.toBigInt=function(){return 0n};He.zzEncode=He.zzDecode=function(){return this};He.length=function(){return 1};var _a=4294967296n;function Ua(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Da(e,t,r){if(r-t<1)return"";let o,i=[],s=0,a;for(;t<r;)a=e[t++],a<128?i[s++]=a:a>191&&a<224?i[s++]=(a&31)<<6|e[t++]&63:a>239&&a<365?(a=((a&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,i[s++]=55296+(a>>10),i[s++]=56320+(a&1023)):i[s++]=(a&15)<<12|(e[t++]&63)<<6|e[t++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function fi(e,t,r){let n=r,o,i;for(let s=0;s<e.length;++s)o=e.charCodeAt(s),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((i=e.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function qt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function En(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var li=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,qt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw qt(this,4);return En(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw qt(this,4);return En(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw qt(this,4);let t=Ca(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw qt(this,4);let t=Ia(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw qt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return Da(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw qt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw qt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new Ut(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw qt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw qt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw qt(this,8);let t=En(this.buf,this.pos+=4),r=En(this.buf,this.pos+=4);return new Ut(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=va(this.buf,this.pos);return this.pos+=Rr(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function di(e){return new li(e instanceof Uint8Array?e:e.subarray())}function Ie(e,t,r){let n=di(e);return t.decode(n,void 0,r)}function hi(e){let t=e??8192,r=t>>>1,n,o=t;return function(s){if(s<1||s>r)return Bt(s);o+s>t&&(n=Bt(t),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var qe=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function pi(){}var yi=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},rd=hi();function nd(e){return globalThis.Buffer!=null?Bt(e):rd(e)}var Lr=class{len;head;tail;states;constructor(){this.len=0,this.head=new qe(pi,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new qe(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new gi((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(Sn,10,Ut.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=Ut.fromBigInt(t);return this._push(Sn,r.length(),r)}uint64Number(t){return this._push(Aa,Rr(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=Ut.fromBigInt(t).zzEncode();return this._push(Sn,r.length(),r)}sint64Number(t){let r=Ut.fromNumber(t).zzEncode();return this._push(Sn,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(mi,1,t?1:0)}fixed32(t){return this._push(Nr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=Ut.fromBigInt(t);return this._push(Nr,4,r.lo)._push(Nr,4,r.hi)}fixed64Number(t){let r=Ut.fromNumber(t);return this._push(Nr,4,r.lo)._push(Nr,4,r.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Ta,4,t)}double(t){return this._push(Ba,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(mi,1,0):this.uint32(r)._push(id,r,t)}string(t){let r=Ua(t);return r!==0?this.uint32(r)._push(fi,r,t):this._push(mi,1,0)}fork(){return this.states=new yi(this),this.head=this.tail=new qe(pi,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new qe(pi,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=nd(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function mi(e,t,r){t[r]=e&255}function od(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var gi=class extends qe{next;constructor(t,r){super(od,t,r),this.next=void 0}};function Sn(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function Nr(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function id(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(Lr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(sd,t,e),this},Lr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(ad,t,e),this});function sd(e,t,r){t.set(e,r)}function ad(e,t,r){e.length<40?fi(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(G(e),r)}function xi(){return new Lr}function _e(e,t){let r=xi();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var cr;(function(e){e[e.VARINT=0]="VARINT",e[e.BIT64=1]="BIT64",e[e.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",e[e.START_GROUP=3]="START_GROUP",e[e.END_GROUP=4]="END_GROUP",e[e.BIT32=5]="BIT32"})(cr||(cr={}));function An(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function Pr(e){function t(o){if(e[o.toString()]==null)throw new Error("Invalid enum value");return e[o]}let r=function(i,s){let a=t(i);s.int32(a)},n=function(i){let s=i.int32();return t(s)};return An("enum",cr.VARINT,r,n)}function Ue(e,t){return An("message",cr.LENGTH_DELIMITED,e,t)}var it;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(it||(it={}));var wi;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(wi||(wi={}));(function(e){e.codec=()=>Pr(wi)})(it||(it={}));var Wt;(function(e){let t;e.codec=()=>(t==null&&(t=Ue((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),it.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let i={},s=n==null?r.len:r.pos+n;for(;r.pos<s;){let a=r.uint32();switch(a>>>3){case 1:{i.Type=it.codec().decode(r);break}case 2:{i.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return i})),t),e.encode=r=>_e(r,e.codec()),e.decode=(r,n)=>Ie(r,e.codec(),n)})(Wt||(Wt={}));var bi;(function(e){let t;e.codec=()=>(t==null&&(t=Ue((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),it.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let i={},s=n==null?r.len:r.pos+n;for(;r.pos<s;){let a=r.uint32();switch(a>>>3){case 1:{i.Type=it.codec().decode(r);break}case 2:{i.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return i})),t),e.encode=r=>_e(r,e.codec()),e.decode=(r,n)=>Ie(r,e.codec(),n)})(bi||(bi={}));var kr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},vn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var La={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new vn("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var De=La;var Or={};At(Or,{MAX_RSA_KEY_SIZE:()=>Ei,generateRSAKeyPair:()=>Oa,jwkToJWKKeyPair:()=>Ma,jwkToPkcs1:()=>ld,jwkToPkix:()=>Ti,jwkToRSAPrivateKey:()=>_i,pkcs1MessageToJwk:()=>Ai,pkcs1MessageToRSAPrivateKey:()=>Ci,pkcs1ToJwk:()=>fd,pkcs1ToRSAPrivateKey:()=>Ka,pkixMessageToJwk:()=>vi,pkixMessageToRSAPublicKey:()=>Ii,pkixToJwk:()=>dd,pkixToRSAPublicKey:()=>Bi});var Tn=pn;var ur=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Or.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return J.createV1(114,this._multihash)}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ot(this.raw,t.raw)}verify(t,r){return ka(this.jwk,r,t)}},Kr=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Or.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ot(this.raw,t.raw)}sign(t){return Pa(this.jwk,t)}};var Ei=8192,Si=18,cd=1062,ud=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function fd(e){let t=ee(e);return Ai(t)}function Ai(e){return{n:j(e[1],"base64url"),e:j(e[2],"base64url"),d:j(e[3],"base64url"),p:j(e[4],"base64url"),q:j(e[5],"base64url"),dp:j(e[6],"base64url"),dq:j(e[7],"base64url"),qi:j(e[8],"base64url"),kty:"RSA"}}function ld(e){if(e.n==null||e.e==null||e.d==null||e.p==null||e.q==null||e.dp==null||e.dq==null||e.qi==null)throw new at("JWK was missing components");return we([Tt(Uint8Array.from([0])),Tt(G(e.n,"base64url")),Tt(G(e.e,"base64url")),Tt(G(e.d,"base64url")),Tt(G(e.p,"base64url")),Tt(G(e.q,"base64url")),Tt(G(e.dp,"base64url")),Tt(G(e.dq,"base64url")),Tt(G(e.qi,"base64url"))]).subarray()}function dd(e){let t=ee(e,{offset:0});return vi(t)}function vi(e){let t=ee(e[1],{offset:0});return{kty:"RSA",n:j(t[0],"base64url"),e:j(t[1],"base64url")}}function Ti(e){if(e.n==null||e.e==null)throw new at("JWK was missing components");return we([ud,cn(we([Tt(G(e.n,"base64url")),Tt(G(e.e,"base64url"))]))]).subarray()}function Ka(e){let t=ee(e);return Ci(t)}function Ci(e){let t=Ai(e);return _i(t)}function Bi(e,t){if(e.byteLength>=cd)throw new Ye("Key size is too large");let r=ee(e,{offset:0});return Ii(r,e,t)}function Ii(e,t,r){let n=vi(e);if(r==null){let o=Tn(Wt.encode({Type:it.RSA,Data:t}));r=Ft(Si,o)}return new ur(n,r)}function _i(e){if(Va(e)>Ei)throw new at("Key size is too large");let t=Ma(e),r=Tn(Wt.encode({Type:it.RSA,Data:Ti(t.publicKey)})),n=Ft(Si,r);return new Kr(t.privateKey,new ur(t.publicKey,n))}async function Oa(e){if(e>Ei)throw new at("Key size is too large");let t=await Fa(e),r=Tn(Wt.encode({Type:it.RSA,Data:Ti(t.publicKey)})),n=Ft(Si,r);return new Kr(t.privateKey,new ur(t.publicKey,n))}function Ma(e){if(e==null)throw new at("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function Fa(e){let t=await De.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),r=await hd(t);return{privateKey:r[0],publicKey:r[1]}}async function Pa(e,t){let r=await De.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await De.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},r,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(n,0,n.byteLength)}async function ka(e,t,r){let n=await De.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return De.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,t,r instanceof Uint8Array?r:r.subarray())}async function hd(e){if(e.privateKey==null||e.publicKey==null)throw new at("Private and public key are required");return Promise.all([De.get().subtle.exportKey("jwk",e.privateKey),De.get().subtle.exportKey("jwk",e.publicKey)])}function Va(e){if(e.kty!=="RSA")throw new at("invalid key type");if(e.n==null)throw new at("invalid key modulus");return G(e.n,"base64url").length*8}var Cn=class extends rr{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,Rs(t);let n=Tr(r);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,i=new Uint8Array(o);i.set(n.length>o?t.create().update(n).digest():n);for(let s=0;s<i.length;s++)i[s]^=54;this.iHash.update(i),this.oHash=t.create();for(let s=0;s<i.length;s++)i[s]^=106;this.oHash.update(i),re(i)}update(t){return nr(this),this.iHash.update(t),this}digestInto(t){nr(this),Pe(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:o,destroyed:i,blockLen:s,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=i,t.blockLen=s,t.outputLen=a,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Ui=(e,t,r)=>new Cn(e,t).update(r).digest();Ui.create=(e,t)=>new Cn(e,t);function Ha(e){e.lowS!==void 0&&Yt("lowS",e.lowS),e.prehash!==void 0&&Yt("prehash",e.prehash)}function pd(e){let t=Dr(e);se(t,{a:"field",b:"field"},{allowInfinityPoint:"boolean",allowedPrivateKeyLengths:"array",clearCofactor:"function",fromBytes:"function",isTorsionFree:"function",toBytes:"function",wrapPrivateKey:"boolean"});let{endo:r,Fp:n,a:o}=t;if(r){if(!n.eql(o,n.ZERO))throw new Error("invalid endo: CURVE.a must be 0");if(typeof r!="object"||typeof r.beta!="bigint"||typeof r.splitScalar!="function")throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function')}return Object.freeze({...t})}var Ni=class extends Error{constructor(t=""){super(t)}},ce={Err:Ni,_tlv:{encode:(e,t)=>{let{Err:r}=ce;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=_r(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let i=n>127?_r(o.length/2|128):"";return _r(e)+i+o+t},decode(e,t){let{Err:r}=ce,n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],i=!!(o&128),s=0;if(!i)s=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let f=t.subarray(n,n+c);if(f.length!==c)throw new r("tlv.decode: length bytes not complete");if(f[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let u of f)s=s<<8|u;if(n+=c,s<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+s);if(a.length!==s)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+s)}}},_int:{encode(e){let{Err:t}=ce;if(e<ue)throw new t("integer: negative integers are not allowed");let r=_r(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=ce;if(e[0]&128)throw new t("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return ie(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=ce,o=tt("signature",e),{v:i,l:s}=n.decode(48,o);if(s.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,i),{v:f,l:u}=n.decode(2,c);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(f)}},hexFromSig(e){let{_tlv:t,_int:r}=ce,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),i=n+o;return t.encode(48,i)}};function Di(e,t){return ve(Me(e,t))}var ue=BigInt(0),ft=BigInt(1),Sy=BigInt(2),Ri=BigInt(3),md=BigInt(4);function yd(e){let t=pd(e),{Fp:r}=t,n=ae(t.n,t.nBitLength),o=t.toBytes||((C,d,S)=>{let R=d.toAffine();return Te(Uint8Array.from([4]),r.toBytes(R.x),r.toBytes(R.y))}),i=t.fromBytes||(C=>{let d=C.subarray(1),S=r.fromBytes(d.subarray(0,r.BYTES)),R=r.fromBytes(d.subarray(r.BYTES,2*r.BYTES));return{x:S,y:R}});function s(C){let{a:d,b:S}=t,R=r.sqr(C),L=r.mul(R,C);return r.add(r.add(L,r.mul(C,d)),S)}function a(C,d){let S=r.sqr(d),R=s(C);return r.eql(S,R)}if(!a(t.Gx,t.Gy))throw new Error("bad curve params: generator point");let c=r.mul(r.pow(t.a,Ri),md),f=r.mul(r.sqr(t.b),BigInt(27));if(r.is0(r.add(c,f)))throw new Error("bad curve params: a or b");function u(C){return mn(C,ft,t.n)}function l(C){let{allowedPrivateKeyLengths:d,nByteLength:S,wrapPrivateKey:R,n:L}=t;if(d&&typeof C!="bigint"){if(or(C)&&(C=ve(C)),typeof C!="string"||!d.includes(C.length))throw new Error("invalid private key");C=C.padStart(S*2,"0")}let g;try{g=typeof C=="bigint"?C:ie(tt("private key",C,S))}catch{throw new Error("invalid private key, expected hex or "+S+" bytes, got "+typeof C)}return R&&(g=Q(g,L)),_t("private key",g,ft,L),g}function y(C){if(!(C instanceof m))throw new Error("ProjectivePoint expected")}let D=sr((C,d)=>{let{px:S,py:R,pz:L}=C;if(r.eql(L,r.ONE))return{x:S,y:R};let g=C.is0();d==null&&(d=g?r.ONE:r.inv(L));let A=r.mul(S,d),N=r.mul(R,d),v=r.mul(L,d);if(g)return{x:r.ZERO,y:r.ZERO};if(!r.eql(v,r.ONE))throw new Error("invZ was invalid");return{x:A,y:N}}),T=sr(C=>{if(C.is0()){if(t.allowInfinityPoint&&!r.is0(C.py))return;throw new Error("bad point: ZERO")}let{x:d,y:S}=C.toAffine();if(!r.isValid(d)||!r.isValid(S))throw new Error("bad point: x or y not FE");if(!a(d,S))throw new Error("bad point: equation left != right");if(!C.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class m{constructor(d,S,R){if(d==null||!r.isValid(d))throw new Error("x required");if(S==null||!r.isValid(S)||r.is0(S))throw new Error("y required");if(R==null||!r.isValid(R))throw new Error("z required");this.px=d,this.py=S,this.pz=R,Object.freeze(this)}static fromAffine(d){let{x:S,y:R}=d||{};if(!d||!r.isValid(S)||!r.isValid(R))throw new Error("invalid affine point");if(d instanceof m)throw new Error("projective point not allowed");let L=g=>r.eql(g,r.ZERO);return L(S)&&L(R)?m.ZERO:new m(S,R,r.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){let S=ar(r,d.map(R=>R.pz));return d.map((R,L)=>R.toAffine(S[L])).map(m.fromAffine)}static fromHex(d){let S=m.fromAffine(i(tt("pointHex",d)));return S.assertValidity(),S}static fromPrivateKey(d){return m.BASE.multiply(l(d))}static msm(d,S){return xn(m,n,d,S)}_setWindowSize(d){q.setWindowSize(this,d)}assertValidity(){T(this)}hasEvenY(){let{y:d}=this.toAffine();if(r.isOdd)return!r.isOdd(d);throw new Error("Field doesn't support isOdd")}equals(d){y(d);let{px:S,py:R,pz:L}=this,{px:g,py:A,pz:N}=d,v=r.eql(r.mul(S,N),r.mul(g,L)),B=r.eql(r.mul(R,N),r.mul(A,L));return v&&B}negate(){return new m(this.px,r.neg(this.py),this.pz)}double(){let{a:d,b:S}=t,R=r.mul(S,Ri),{px:L,py:g,pz:A}=this,N=r.ZERO,v=r.ZERO,B=r.ZERO,U=r.mul(L,L),H=r.mul(g,g),x=r.mul(A,A),w=r.mul(L,g);return w=r.add(w,w),B=r.mul(L,A),B=r.add(B,B),N=r.mul(d,B),v=r.mul(R,x),v=r.add(N,v),N=r.sub(H,v),v=r.add(H,v),v=r.mul(N,v),N=r.mul(w,N),B=r.mul(R,B),x=r.mul(d,x),w=r.sub(U,x),w=r.mul(d,w),w=r.add(w,B),B=r.add(U,U),U=r.add(B,U),U=r.add(U,x),U=r.mul(U,w),v=r.add(v,U),x=r.mul(g,A),x=r.add(x,x),U=r.mul(x,w),N=r.sub(N,U),B=r.mul(x,H),B=r.add(B,B),B=r.add(B,B),new m(N,v,B)}add(d){y(d);let{px:S,py:R,pz:L}=this,{px:g,py:A,pz:N}=d,v=r.ZERO,B=r.ZERO,U=r.ZERO,H=t.a,x=r.mul(t.b,Ri),w=r.mul(S,g),K=r.mul(R,A),E=r.mul(L,N),h=r.add(S,R),b=r.add(g,A);h=r.mul(h,b),b=r.add(w,K),h=r.sub(h,b),b=r.add(S,L);let I=r.add(g,N);return b=r.mul(b,I),I=r.add(w,E),b=r.sub(b,I),I=r.add(R,L),v=r.add(A,N),I=r.mul(I,v),v=r.add(K,E),I=r.sub(I,v),U=r.mul(H,b),v=r.mul(x,E),U=r.add(v,U),v=r.sub(K,U),U=r.add(K,U),B=r.mul(v,U),K=r.add(w,w),K=r.add(K,w),E=r.mul(H,E),b=r.mul(x,b),K=r.add(K,E),E=r.sub(w,E),E=r.mul(H,E),b=r.add(b,E),w=r.mul(K,b),B=r.add(B,w),w=r.mul(I,b),v=r.mul(h,v),v=r.sub(v,w),w=r.mul(h,K),U=r.mul(I,U),U=r.add(U,w),new m(v,B,U)}subtract(d){return this.add(d.negate())}is0(){return this.equals(m.ZERO)}wNAF(d){return q.wNAFCached(this,d,m.normalizeZ)}multiplyUnsafe(d){let{endo:S,n:R}=t;_t("scalar",d,ue,R);let L=m.ZERO;if(d===ue)return L;if(this.is0()||d===ft)return this;if(!S||q.hasPrecomputes(this))return q.wNAFCachedUnsafe(this,d,m.normalizeZ);let{k1neg:g,k1:A,k2neg:N,k2:v}=S.splitScalar(d),B=L,U=L,H=this;for(;A>ue||v>ue;)A&ft&&(B=B.add(H)),v&ft&&(U=U.add(H)),H=H.double(),A>>=ft,v>>=ft;return g&&(B=B.negate()),N&&(U=U.negate()),U=new m(r.mul(U.px,S.beta),U.py,U.pz),B.add(U)}multiply(d){let{endo:S,n:R}=t;_t("scalar",d,ft,R);let L,g;if(S){let{k1neg:A,k1:N,k2neg:v,k2:B}=S.splitScalar(d),{p:U,f:H}=this.wNAF(N),{p:x,f:w}=this.wNAF(B);U=q.constTimeNegate(A,U),x=q.constTimeNegate(v,x),x=new m(r.mul(x.px,S.beta),x.py,x.pz),L=U.add(x),g=H.add(w)}else{let{p:A,f:N}=this.wNAF(d);L=A,g=N}return m.normalizeZ([L,g])[0]}multiplyAndAddUnsafe(d,S,R){let L=m.BASE,g=(N,v)=>v===ue||v===ft||!N.equals(L)?N.multiplyUnsafe(v):N.multiply(v),A=g(this,S).add(g(d,R));return A.is0()?void 0:A}toAffine(d){return D(this,d)}isTorsionFree(){let{h:d,isTorsionFree:S}=t;if(d===ft)return!0;if(S)return S(m,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:d,clearCofactor:S}=t;return d===ft?this:S?S(m,this):this.multiplyUnsafe(t.h)}toRawBytes(d=!0){return Yt("isCompressed",d),this.assertValidity(),o(m,this,d)}toHex(d=!0){return Yt("isCompressed",d),ve(this.toRawBytes(d))}}m.BASE=new m(t.Gx,t.Gy,r.ONE),m.ZERO=new m(r.ZERO,r.ONE,r.ZERO);let{endo:k,nBitLength:O}=t,q=gn(m,k?Math.ceil(O/2):O);return{CURVE:t,ProjectivePoint:m,normPrivateKeyToScalar:l,weierstrassEquation:s,isWithinCurveOrder:u}}function gd(e){let t=Dr(e);return se(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function qa(e){let t=gd(e),{Fp:r,n,nByteLength:o,nBitLength:i}=t,s=r.BYTES+1,a=2*r.BYTES+1;function c(x){return Q(x,n)}function f(x){return yn(x,n)}let{ProjectivePoint:u,normPrivateKeyToScalar:l,weierstrassEquation:y,isWithinCurveOrder:D}=yd({...t,toBytes(x,w,K){let E=w.toAffine(),h=r.toBytes(E.x),b=Te;return Yt("isCompressed",K),K?b(Uint8Array.from([w.hasEvenY()?2:3]),h):b(Uint8Array.from([4]),h,r.toBytes(E.y))},fromBytes(x){let w=x.length,K=x[0],E=x.subarray(1);if(w===s&&(K===2||K===3)){let h=ie(E);if(!mn(h,ft,r.ORDER))throw new Error("Point is not on curve");let b=y(h),I;try{I=r.sqrt(b)}catch(z){let $=z instanceof Error?": "+z.message:"";throw new Error("Point is not on curve"+$)}let M=(I&ft)===ft;return(K&1)===1!==M&&(I=r.neg(I)),{x:h,y:I}}else if(w===a&&K===4){let h=r.fromBytes(E.subarray(0,r.BYTES)),b=r.fromBytes(E.subarray(r.BYTES,2*r.BYTES));return{x:h,y:b}}else{let h=s,b=a;throw new Error("invalid Point, expected length of "+h+", or uncompressed "+b+", got "+w)}}});function T(x){let w=n>>ft;return x>w}function m(x){return T(x)?c(-x):x}let k=(x,w,K)=>ie(x.slice(w,K));class O{constructor(w,K,E){_t("r",w,ft,n),_t("s",K,ft,n),this.r=w,this.s=K,E!=null&&(this.recovery=E),Object.freeze(this)}static fromCompact(w){let K=o;return w=tt("compactSignature",w,K*2),new O(k(w,0,K),k(w,K,2*K))}static fromDER(w){let{r:K,s:E}=ce.toSig(tt("DER",w));return new O(K,E)}assertValidity(){}addRecoveryBit(w){return new O(this.r,this.s,w)}recoverPublicKey(w){let{r:K,s:E,recovery:h}=this,b=L(tt("msgHash",w));if(h==null||![0,1,2,3].includes(h))throw new Error("recovery id invalid");let I=h===2||h===3?K+t.n:K;if(I>=r.ORDER)throw new Error("recovery id 2 or 3 invalid");let M=(h&1)===0?"02":"03",V=u.fromHex(M+Di(I,r.BYTES)),z=f(I),$=c(-b*z),Y=c(E*z),W=u.BASE.multiplyAndAddUnsafe(V,$,Y);if(!W)throw new Error("point at infinify");return W.assertValidity(),W}hasHighS(){return T(this.s)}normalizeS(){return this.hasHighS()?new O(this.r,c(-this.s),this.recovery):this}toDERRawBytes(){return Ur(this.toDERHex())}toDERHex(){return ce.hexFromSig(this)}toCompactRawBytes(){return Ur(this.toCompactHex())}toCompactHex(){let w=o;return Di(this.r,w)+Di(this.s,w)}}let q={isValidPrivateKey(x){try{return l(x),!0}catch{return!1}},normPrivateKeyToScalar:l,randomPrivateKey:()=>{let x=Qo(t.n);return sa(t.randomBytes(x),t.n)},precompute(x=8,w=u.BASE){return w._setWindowSize(x),w.multiply(BigInt(3)),w}};function C(x,w=!0){return u.fromPrivateKey(x).toRawBytes(w)}function d(x){if(typeof x=="bigint")return!1;if(x instanceof u)return!0;let K=tt("key",x).length,E=r.BYTES,h=E+1,b=2*E+1;if(!(t.allowedPrivateKeyLengths||o===h))return K===h||K===b}function S(x,w,K=!0){if(d(x)===!0)throw new Error("first arg must be private key");if(d(w)===!1)throw new Error("second arg must be public key");return u.fromHex(w).multiply(l(x)).toRawBytes(K)}let R=t.bits2int||function(x){if(x.length>8192)throw new Error("input is too large");let w=ie(x),K=x.length*8-i;return K>0?w>>BigInt(K):w},L=t.bits2int_modN||function(x){return c(R(x))},g=Fe(i);function A(x){return _t("num < 2^"+i,x,ue,g),Me(x,o)}function N(x,w,K=v){if(["recovered","canonical"].some(nt=>nt in K))throw new Error("sign() legacy options not supported");let{hash:E,randomBytes:h}=t,{lowS:b,prehash:I,extraEntropy:M}=K;b==null&&(b=!0),x=tt("msgHash",x),Ha(K),I&&(x=tt("prehashed msgHash",E(x)));let V=L(x),z=l(w),$=[A(z),A(V)];if(M!=null&&M!==!1){let nt=M===!0?h(r.BYTES):M;$.push(tt("extraEntropy",nt))}let Y=Te(...$),W=V;function st(nt){let dt=R(nt);if(!D(dt))return;let St=f(dt),ct=u.BASE.multiply(dt).toAffine(),yt=c(ct.x);if(yt===ue)return;let Ct=c(St*c(W+yt*z));if(Ct===ue)return;let Ot=(ct.x===yt?0:2)|Number(ct.y&ft),gr=Ct;return b&&T(Ct)&&(gr=m(Ct),Ot^=1),new O(yt,gr,Ot)}return{seed:Y,k2sig:st}}let v={lowS:t.lowS,prehash:!1},B={lowS:t.lowS,prehash:!1};function U(x,w,K=v){let{seed:E,k2sig:h}=N(x,w,K),b=t;return Js(b.hash.outputLen,b.nByteLength,b.hmac)(E,h)}u.BASE._setWindowSize(8);function H(x,w,K,E=B){let h=x;w=tt("msgHash",w),K=tt("publicKey",K);let{lowS:b,prehash:I,format:M}=E;if(Ha(E),"strict"in E)throw new Error("options.strict was renamed to lowS");if(M!==void 0&&M!=="compact"&&M!=="der")throw new Error("format must be compact or der");let V=typeof h=="string"||or(h),z=!V&&!M&&typeof h=="object"&&h!==null&&typeof h.r=="bigint"&&typeof h.s=="bigint";if(!V&&!z)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let $,Y;try{if(z&&($=new O(h.r,h.s)),V){try{M!=="compact"&&($=O.fromDER(h))}catch(Ot){if(!(Ot instanceof ce.Err))throw Ot}!$&&M!=="der"&&($=O.fromCompact(h))}Y=u.fromHex(K)}catch{return!1}if(!$||b&&$.hasHighS())return!1;I&&(w=t.hash(w));let{r:W,s:st}=$,nt=L(w),dt=f(st),St=c(nt*dt),ct=c(W*dt),yt=u.BASE.multiplyAndAddUnsafe(Y,St,ct)?.toAffine();return yt?c(yt.x)===W:!1}return{CURVE:t,getPublicKey:C,getSharedSecret:S,sign:U,verify:H,ProjectivePoint:u,Signature:O,utils:q}}function xd(e){return{hash:e,hmac:(t,...r)=>Ui(e,t,Vo(...r)),randomBytes:ln}}function za(e,t){let r=n=>qa({...e,...xd(n)});return{...r(t),create:r}}var Za=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),$a=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),wd=BigInt(0),bd=BigInt(1),Li=BigInt(2),Ga=(e,t)=>(e+t/Li)/t;function Ed(e){let t=Za,r=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),f=e*e*e%t,u=f*f*e%t,l=et(u,r,t)*u%t,y=et(l,r,t)*u%t,D=et(y,Li,t)*f%t,T=et(D,o,t)*D%t,m=et(T,i,t)*T%t,k=et(m,a,t)*m%t,O=et(k,c,t)*k%t,q=et(O,a,t)*m%t,C=et(q,r,t)*u%t,d=et(C,s,t)*T%t,S=et(d,n,t)*f%t,R=et(S,Li,t);if(!Pi.eql(Pi.sqr(R),e))throw new Error("Cannot find square root");return R}var Pi=ae(Za,void 0,void 0,{sqrt:Ed}),fr=za({a:wd,b:BigInt(7),Fp:Pi,n:$a,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{let t=$a,r=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-bd*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=r,s=BigInt("0x100000000000000000000000000000000"),a=Ga(i*e,t),c=Ga(-n*e,t),f=Q(e-a*r-c*o,t),u=Q(-a*n-c*i,t),l=f>s,y=u>s;if(l&&(f=t-f),y&&(u=t-u),f>s||u>s)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:l,k1:f,k2neg:y,k2:u}}}},pn);function Ya(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}function ja(e,t,r){let n=Sr.digest(r instanceof Uint8Array?r:r.subarray());if(Ya(n))return n.then(({digest:o})=>fr.verify(t,o,e)).catch(o=>{throw new kr(String(o))});try{return fr.verify(t,n.digest,e)}catch(o){throw new kr(String(o))}}var Bn=class{type="secp256k1";raw;_key;constructor(t){this._key=Xa(t),this.raw=Wa(this._key)}toMultihash(){return Vt.digest(be(this))}toCID(){return J.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ot(this.raw,t.raw)}verify(t,r){return ja(this._key,r,t)}};function ki(e){return new Bn(e)}function Wa(e){return fr.ProjectivePoint.fromHex(e).toRawBytes(!0)}function Xa(e){try{return fr.ProjectivePoint.fromHex(e),e}catch(t){throw new Ye(String(t))}}function Ja(e,t){let{Type:r,Data:n}=Wt.decode(e),o=n??new Uint8Array;switch(r){case it.RSA:return Bi(o,t);case it.Ed25519:return ai(o);case it.secp256k1:return ki(o);case it.ECDSA:return Fo(o);default:throw new We}}function In(e){let{Type:t,Data:r}=Wt.decode(e.digest),n=r??new Uint8Array;switch(t){case it.Ed25519:return ai(n);case it.secp256k1:return ki(n);case it.ECDSA:return Fo(n);default:throw new We}}function be(e){return Wt.encode({Type:it[e.type],Data:e.raw})}var Qa=Symbol.for("nodejs.util.inspect.custom"),Sd=114,Mr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[uo]=!0;toString(){return this.string==null&&(this.string=X.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return J.createV1(Sd,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return ot(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return ot(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Qa](){return`PeerId(${this.toString()})`}},_n=class extends Mr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Un=class extends Mr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Dn=class extends Mr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Ad=2336,Fr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Vt.digest(G(this.url))}[Qa](){return`PeerId(${this.url})`}[uo]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return J.createV1(Ad,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=j(t)),t.toString()===this.toString())}};var vd=114,tc=2336;function Rn(e,t){let r;if(e.charAt(0)==="1"||e.charAt(0)==="Q")r=te(X.decode(`z${e}`));else{if(e.startsWith("k51qzi5uqu5")||e.startsWith("kzwfwjn5ji4")||e.startsWith("k2k4r8")||e.startsWith("bafz"))return Ki(J.parse(e));if(t==null)throw new at('Please pass a multibase decoder for strings that do not start with "1" or "Q"');r=te(t.decode(e))}return ec(r)}function ec(e){if(Cd(e))return new _n({multihash:e});if(Td(e))try{let t=In(e);if(t.type==="Ed25519")return new Un({multihash:e,publicKey:t});if(t.type==="secp256k1")return new Dn({multihash:e,publicKey:t})}catch{let r=j(e.digest);return new Fr(new URL(r))}throw new je("Supplied PeerID Multihash is invalid")}function Ki(e){if(e?.multihash==null||e.version==null||e.version===1&&e.code!==vd&&e.code!==tc)throw new tn("Supplied PeerID CID is invalid");if(e.code===tc){let t=j(e.multihash.digest);return new Fr(new URL(t))}return ec(e.multihash)}function Td(e){return e.code===Vt.code}function Cd(e){return e.code===Sr.code}var fe="/",rc=new TextEncoder().encode(fe),Nn=rc[0],Vr=class e{_buf;constructor(t,r){if(typeof t=="string")this._buf=G(t);else if(t instanceof Uint8Array)this._buf=t;else throw new Error("Invalid key, should be String of Uint8Array");if(r==null&&(r=!0),r&&this.clean(),this._buf.byteLength===0||this._buf[0]!==Nn)throw new Error("Invalid key")}toString(t="utf8"){return j(this._buf,t)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(t){return new e(t.join(fe))}static random(){return new e(Math.random().toString().substring(2))}static asKey(t){return t instanceof Uint8Array||typeof t=="string"?new e(t):typeof t.uint8Array=="function"?new e(t.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=rc),this._buf[0]!==Nn){let t=new Uint8Array(this._buf.byteLength+1);t.fill(Nn,0,1),t.set(this._buf,1),this._buf=t}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===Nn;)this._buf=this._buf.subarray(0,-1)}less(t){let r=this.list(),n=t.list();for(let o=0;o<r.length;o++){if(n.length<o+1)return!1;let i=r[o],s=n[o];if(i<s)return!0;if(i>s)return!1}return r.length<n.length}reverse(){return e.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let t=this.namespaces();return t[t.length-1]}list(){return this.toString().split(fe).slice(1)}type(){return Bd(this.baseNamespace())}name(){return Id(this.baseNamespace())}instance(t){return new e(this.toString()+":"+t)}path(){let t=this.parent().toString();return t.endsWith(fe)||(t+=fe),t+=this.type(),new e(t)}parent(){let t=this.list();return t.length===1?new e(fe):new e(t.slice(0,-1).join(fe))}child(t){return this.toString()===fe?t:t.toString()===fe?this:new e(this.toString()+t.toString(),!1)}isAncestorOf(t){return t.toString()===this.toString()?!1:t.toString().startsWith(this.toString())}isDecendantOf(t){return t.toString()===this.toString()?!1:this.toString().startsWith(t.toString())}isTopLevel(){return this.list().length===1}concat(...t){return e.withNamespaces([...this.namespaces(),..._d(t.map(r=>r.namespaces()))])}};function Bd(e){let t=e.split(":");return t.length<2?"":t.slice(0,-1).join(":")}function Id(e){let t=e.split(":");return t[t.length-1]}function _d(e){return[].concat(...e)}var pu=Qr(Ln(),1);var Pn=class extends Error{static name="SignatureCreationError";constructor(t="Record signature creation failed"){super(t),this.name="SignatureCreationError"}},zt=class extends Error{static name="SignatureVerificationError";constructor(t="Record signature verification failed"){super(t),this.name="SignatureVerificationError"}},kn=class extends Error{static name="RecordExpiredError";constructor(t="Record has expired"){super(t),this.name="RecordExpiredError"}},ze=class extends Error{static name="UnsupportedValidityError";constructor(t="The validity type is unsupported"){super(t),this.name="UnsupportedValidityError"}},Kn=class extends Error{static name="RecordTooLargeError";constructor(t="The record is too large"){super(t),this.name="RecordTooLargeError"}},Hr=class extends Error{static name="InvalidValueError";constructor(t="Value must be a valid content path starting with /"){super(t),this.name="InvalidValueError"}},On=class extends Error{static name="InvalidRecordDataError";constructor(t="Invalid record data"){super(t),this.name="InvalidRecordDataError"}},qr=class extends Error{static name="InvalidEmbeddedPublicKeyError";constructor(t="Invalid embedded public key"){super(t),this.name="InvalidEmbeddedPublicKeyError"}};var pt;(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=()=>Pr(r)}(t=e.ValidityType||(e.ValidityType={}));let n;e.codec=()=>(n==null&&(n=Ue((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 a={},c=i==null?o.len:o.pos+i;for(;o.pos<c;){let f=o.uint32();switch(f>>>3){case 1:{a.value=o.bytes();break}case 2:{a.signatureV1=o.bytes();break}case 3:{a.validityType=e.ValidityType.codec().decode(o);break}case 4:{a.validity=o.bytes();break}case 5:{a.sequence=o.uint64();break}case 6:{a.ttl=o.uint64();break}case 7:{a.pubKey=o.bytes();break}case 8:{a.signatureV2=o.bytes();break}case 9:{a.data=o.bytes();break}default:{o.skipType(f&7);break}}}return a})),n),e.encode=o=>_e(o,e.codec()),e.decode=(o,i)=>Ie(o,e.codec(),i)})(pt||(pt={}));var Ud=["string","number","bigint","symbol"],Dd=["Function","Generator","AsyncGenerator","GeneratorFunction","AsyncGeneratorFunction","AsyncFunction","Observable","Array","Buffer","Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function nc(e){if(e===null)return"null";if(e===void 0)return"undefined";if(e===!0||e===!1)return"boolean";let t=typeof e;if(Ud.includes(t))return t;if(t==="function")return"Function";if(Array.isArray(e))return"Array";if(Rd(e))return"Buffer";let r=Nd(e);return r||"Object"}function Rd(e){return e&&e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer.call(null,e)}function Nd(e){let t=Object.prototype.toString.call(e).slice(8,-1);if(Dd.includes(t))return t}var p=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}};p.uint=new p(0,"uint",!0);p.negint=new p(1,"negint",!0);p.bytes=new p(2,"bytes",!0);p.string=new p(3,"string",!0);p.array=new p(4,"array",!1);p.map=new p(5,"map",!1);p.tag=new p(6,"tag",!1);p.float=new p(7,"float",!0);p.false=new p(7,"false",!0);p.true=new p(7,"true",!0);p.null=new p(7,"null",!0);p.undefined=new p(7,"undefined",!0);p.break=new p(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 lr=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Ld=new TextDecoder,Pd=new TextEncoder;function Mn(e){return lr&&globalThis.Buffer.isBuffer(e)}function Mi(e){return e instanceof Uint8Array?Mn(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e:Uint8Array.from(e)}var ac=lr?(e,t,r)=>r-t>64?globalThis.Buffer.from(e.subarray(t,r)).toString("utf8"):ic(e,t,r):(e,t,r)=>r-t>64?Ld.decode(e.subarray(t,r)):ic(e,t,r),cc=lr?e=>e.length>64?globalThis.Buffer.from(e):oc(e):e=>e.length>64?Pd.encode(e):oc(e),Xt=e=>Uint8Array.from(e),dr=lr?(e,t,r)=>Mn(e)?new Uint8Array(e.subarray(t,r)):e.slice(t,r):(e,t,r)=>e.slice(t,r),uc=lr?(e,t)=>(e=e.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),Mi(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},fc=lr?e=>globalThis.Buffer.allocUnsafe(e):e=>new Uint8Array(e);function lc(e,t){if(Mn(e)&&Mn(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 oc(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):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128)}return t}function ic(e,t,r){let n=[];for(;t<r;){let o=e[t],i=null,s=o>239?4:o>223?3:o>191?2:1;if(t+s<=r){let a,c,f,u;switch(s){case 1:o<128&&(i=o);break;case 2:a=e[t+1],(a&192)===128&&(u=(o&31)<<6|a&63,u>127&&(i=u));break;case 3:a=e[t+1],c=e[t+2],(a&192)===128&&(c&192)===128&&(u=(o&15)<<12|(a&63)<<6|c&63,u>2047&&(u<55296||u>57343)&&(i=u));break;case 4:a=e[t+1],c=e[t+2],f=e[t+3],(a&192)===128&&(c&192)===128&&(f&192)===128&&(u=(o&15)<<18|(a&63)<<12|(c&63)<<6|f&63,u>65535&&u<1114112&&(i=u))}}i===null?(i=65533,s=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),t+=s}return kd(n)}var sc=4096;function kd(e){let t=e.length;if(t<=sc)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=sc));return r}var Kd=256,zr=class{constructor(t=Kd){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=fc(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=dr(n,0,this.cursor)}else r=uc(this.chunks,this.cursor);return t&&this.reset(),r}};var F="CBOR decode error:",Fi="CBOR encode error:",$r=[];$r[23]=1;$r[24]=2;$r[25]=3;$r[26]=5;$r[27]=9;function le(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 Dt(e,t,r){le(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 Rt(e,t,r){le(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){le(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){le(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 dc(e,t,r,n){return new P(p.uint,Dt(e,t+1,n),2)}function hc(e,t,r,n){return new P(p.uint,Rt(e,t+1,n),3)}function pc(e,t,r,n){return new P(p.uint,Nt(e,t+1,n),5)}function mc(e,t,r,n){return new P(p.uint,Lt(e,t+1,n),9)}function kt(e,t){return mt(e,0,t.value)}function mt(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 mt.encodedSize(t.value)};mt.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 yc(e,t,r,n){return new P(p.negint,-1-Dt(e,t+1,n),2)}function gc(e,t,r,n){return new P(p.negint,-1-Rt(e,t+1,n),3)}function xc(e,t,r,n){return new P(p.negint,-1-Nt(e,t+1,n),5)}var Vi=BigInt(-1),wc=BigInt(1);function bc(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(p.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${F} integers outside of the safe integer range are not supported`);return new P(p.negint,Vi-BigInt(o),9)}function Fn(e,t){let r=t.value,n=typeof r=="bigint"?r*Vi-wc:r*-1-1;mt(e,t.type.majorEncoded,n)}Fn.encodedSize=function(t){let r=t.value,n=typeof r=="bigint"?r*Vi-wc:r*-1-1;return n<lt[0]?1:n<lt[1]?2:n<lt[2]?3:n<lt[3]?5:9};Fn.compareTokens=function(t,r){return t.value<r.value?1:t.value>r.value?-1:0};function Gr(e,t,r,n){le(e,t,r+n);let o=dr(e,t+r,t+r+n);return new P(p.bytes,o,r+n)}function Ec(e,t,r,n){return Gr(e,t,1,r)}function Sc(e,t,r,n){return Gr(e,t,2,Dt(e,t+1,n))}function Ac(e,t,r,n){return Gr(e,t,3,Rt(e,t+1,n))}function vc(e,t,r,n){return Gr(e,t,5,Nt(e,t+1,n))}function Tc(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 Gr(e,t,9,o)}function Vn(e){return e.encodedBytes===void 0&&(e.encodedBytes=e.type===p.string?cc(e.value):e.value),e.encodedBytes}function hr(e,t){let r=Vn(t);mt(e,t.type.majorEncoded,r.length),e.push(r)}hr.encodedSize=function(t){let r=Vn(t);return mt.encodedSize(r.length)+r.length};hr.compareTokens=function(t,r){return Md(Vn(t),Vn(r))};function Md(e,t){return e.length<t.length?-1:e.length>t.length?1:lc(e,t)}function Zr(e,t,r,n,o){let i=r+n;le(e,t,i);let s=new P(p.string,ac(e,t+r,t+i),i);return o.retainStringBytes===!0&&(s.byteValue=dr(e,t+r,t+i)),s}function Cc(e,t,r,n){return Zr(e,t,1,r,n)}function Bc(e,t,r,n){return Zr(e,t,2,Dt(e,t+1,n),n)}function Ic(e,t,r,n){return Zr(e,t,3,Rt(e,t+1,n),n)}function _c(e,t,r,n){return Zr(e,t,5,Nt(e,t+1,n),n)}function Uc(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 Zr(e,t,9,o,n)}var Dc=hr;function pr(e,t,r,n){return new P(p.array,n,r)}function Rc(e,t,r,n){return pr(e,t,1,r)}function Nc(e,t,r,n){return pr(e,t,2,Dt(e,t+1,n))}function Lc(e,t,r,n){return pr(e,t,3,Rt(e,t+1,n))}function Pc(e,t,r,n){return pr(e,t,5,Nt(e,t+1,n))}function kc(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 pr(e,t,9,o)}function Kc(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${F} indefinite length items not allowed`);return pr(e,t,1,1/0)}function Hn(e,t){mt(e,p.array.majorEncoded,t.value)}Hn.compareTokens=kt.compareTokens;Hn.encodedSize=function(t){return mt.encodedSize(t.value)};function mr(e,t,r,n){return new P(p.map,n,r)}function Oc(e,t,r,n){return mr(e,t,1,r)}function Mc(e,t,r,n){return mr(e,t,2,Dt(e,t+1,n))}function Fc(e,t,r,n){return mr(e,t,3,Rt(e,t+1,n))}function Vc(e,t,r,n){return mr(e,t,5,Nt(e,t+1,n))}function Hc(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 mr(e,t,9,o)}function qc(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${F} indefinite length items not allowed`);return mr(e,t,1,1/0)}function qn(e,t){mt(e,p.map.majorEncoded,t.value)}qn.compareTokens=kt.compareTokens;qn.encodedSize=function(t){return mt.encodedSize(t.value)};function zc(e,t,r,n){return new P(p.tag,r,1)}function $c(e,t,r,n){return new P(p.tag,Dt(e,t+1,n),2)}function Gc(e,t,r,n){return new P(p.tag,Rt(e,t+1,n),3)}function Zc(e,t,r,n){return new P(p.tag,Nt(e,t+1,n),5)}function Yc(e,t,r,n){return new P(p.tag,Lt(e,t+1,n),9)}function zn(e,t){mt(e,p.tag.majorEncoded,t.value)}zn.compareTokens=kt.compareTokens;zn.encodedSize=function(t){return mt.encodedSize(t.value)};var $d=20,Gd=21,Zd=22,Yd=23;function jc(e,t,r,n){if(n.allowUndefined===!1)throw new Error(`${F} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new P(p.null,null,1):new P(p.undefined,void 0,1)}function Wc(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${F} indefinite length items not allowed`);return new P(p.break,void 0,1)}function Hi(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(p.float,e,t)}function Xc(e,t,r,n){return Hi(qi(e,t+1),3,n)}function Jc(e,t,r,n){return Hi(zi(e,t+1),5,n)}function Qc(e,t,r,n){return Hi(nu(e,t+1),9,n)}function $n(e,t,r){let n=t.value;if(n===!1)e.push([p.float.majorEncoded|$d]);else if(n===!0)e.push([p.float.majorEncoded|Gd]);else if(n===null)e.push([p.float.majorEncoded|Zd]);else if(n===void 0)e.push([p.float.majorEncoded|Yd]);else{let o,i=!1;(!r||r.float64!==!0)&&(eu(n),o=qi($t,1),n===o||Number.isNaN(n)?($t[0]=249,e.push($t.slice(0,3)),i=!0):(ru(n),o=zi($t,1),n===o&&($t[0]=250,e.push($t.slice(0,5)),i=!0))),i||(jd(n),o=nu($t,1),$t[0]=251,e.push($t.slice(0,9)))}}$n.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){eu(n);let o=qi($t,1);if(n===o||Number.isNaN(n))return 3;if(ru(n),o=zi($t,1),n===o)return 5}return 9};var tu=new ArrayBuffer(9),Kt=new DataView(tu,1),$t=new Uint8Array(tu,0);function eu(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 qi(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 ru(e){Kt.setFloat32(0,e,!1)}function zi(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 jd(e){Kt.setFloat64(0,e,!1)}function nu(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)}$n.compareTokens=kt.compareTokens;function Z(e,t,r){throw new Error(`${F} encountered invalid minor (${r}) for major ${e[t]>>>5}`)}function Gn(e){return()=>{throw new Error(`${F} ${e}`)}}var _=[];for(let e=0;e<=23;e++)_[e]=Z;_[24]=dc;_[25]=hc;_[26]=pc;_[27]=mc;_[28]=Z;_[29]=Z;_[30]=Z;_[31]=Z;for(let e=32;e<=55;e++)_[e]=Z;_[56]=yc;_[57]=gc;_[58]=xc;_[59]=bc;_[60]=Z;_[61]=Z;_[62]=Z;_[63]=Z;for(let e=64;e<=87;e++)_[e]=Ec;_[88]=Sc;_[89]=Ac;_[90]=vc;_[91]=Tc;_[92]=Z;_[93]=Z;_[94]=Z;_[95]=Gn("indefinite length bytes/strings are not supported");for(let e=96;e<=119;e++)_[e]=Cc;_[120]=Bc;_[121]=Ic;_[122]=_c;_[123]=Uc;_[124]=Z;_[125]=Z;_[126]=Z;_[127]=Gn("indefinite length bytes/strings are not supported");for(let e=128;e<=151;e++)_[e]=Rc;_[152]=Nc;_[153]=Lc;_[154]=Pc;_[155]=kc;_[156]=Z;_[157]=Z;_[158]=Z;_[159]=Kc;for(let e=160;e<=183;e++)_[e]=Oc;_[184]=Mc;_[185]=Fc;_[186]=Vc;_[187]=Hc;_[188]=Z;_[189]=Z;_[190]=Z;_[191]=qc;for(let e=192;e<=215;e++)_[e]=zc;_[216]=$c;_[217]=Gc;_[218]=Zc;_[219]=Yc;_[220]=Z;_[221]=Z;_[222]=Z;_[223]=Z;for(let e=224;e<=243;e++)_[e]=Gn("simple values are not supported");_[244]=Z;_[245]=Z;_[246]=Z;_[247]=jc;_[248]=Gn("simple values are not supported");_[249]=Xc;_[250]=Jc;_[251]=Qc;_[252]=Z;_[253]=Z;_[254]=Z;_[255]=Wc;var Gt=[];for(let e=0;e<24;e++)Gt[e]=new P(p.uint,e,1);for(let e=-1;e>=-24;e--)Gt[31-e]=new P(p.negint,e,1);Gt[64]=new P(p.bytes,new Uint8Array(0),1);Gt[96]=new P(p.string,"",1);Gt[128]=new P(p.array,0,1);Gt[160]=new P(p.map,0,1);Gt[244]=new P(p.false,!1,1);Gt[245]=new P(p.true,!0,1);Gt[246]=new P(p.null,null,1);function ou(e){switch(e.type){case p.false:return Xt([244]);case p.true:return Xt([245]);case p.null:return Xt([246]);case p.bytes:return e.value.length?void 0:Xt([64]);case p.string:return e.value===""?Xt([96]):void 0;case p.array:return e.value===0?Xt([128]):void 0;case p.map:return e.value===0?Xt([160]):void 0;case p.uint:return e.value<24?Xt([Number(e.value)]):void 0;case p.negint:if(e.value>=-24)return Xt([31-Number(e.value)])}}var Xd={float64:!1,mapSorter:th,quickEncodeToken:ou};function Jd(){let e=[];return e[p.uint.major]=kt,e[p.negint.major]=Fn,e[p.bytes.major]=hr,e[p.string.major]=Dc,e[p.array.major]=Hn,e[p.map.major]=qn,e[p.tag.major]=zn,e[p.float.major]=$n,e}var iu=Jd(),$i=new zr,Yn=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(`${Fi} object contains circular references`);return new e(r,t)}},Re={null:new P(p.null,null),undefined:new P(p.undefined,void 0),true:new P(p.true,!0),false:new P(p.false,!1),emptyArray:new P(p.array,0),emptyMap:new P(p.map,0)},Ne={number(e,t,r,n){return!Number.isInteger(e)||!Number.isSafeInteger(e)?new P(p.float,e):e>=0?new P(p.uint,e):new P(p.negint,e)},bigint(e,t,r,n){return e>=BigInt(0)?new P(p.uint,e):new P(p.negint,e)},Uint8Array(e,t,r,n){return new P(p.bytes,e)},string(e,t,r,n){return new P(p.string,e)},boolean(e,t,r,n){return e?Re.true:Re.false},null(e,t,r,n){return Re.null},undefined(e,t,r,n){return Re.undefined},ArrayBuffer(e,t,r,n){return new P(p.bytes,new Uint8Array(e))},DataView(e,t,r,n){return new P(p.bytes,new Uint8Array(e.buffer,e.byteOffset,e.byteLength))},Array(e,t,r,n){if(!e.length)return r.addBreakTokens===!0?[Re.emptyArray,new P(p.break)]:Re.emptyArray;n=Yn.createCheck(n,e);let o=[],i=0;for(let s of e)o[i++]=Zn(s,r,n);return r.addBreakTokens?[new P(p.array,e.length),o,new P(p.break)]:[new P(p.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;if(!s)return r.addBreakTokens===!0?[Re.emptyMap,new P(p.break)]:Re.emptyMap;n=Yn.createCheck(n,e);let a=[],c=0;for(let f of i)a[c++]=[Zn(f,r,n),Zn(o?e.get(f):e[f],r,n)];return Qd(a,r),r.addBreakTokens?[new P(p.map,s),a,new P(p.break)]:[new P(p.map,s),a]}};Ne.Map=Ne.Object;Ne.Buffer=Ne.Uint8Array;for(let e of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))Ne[`${e}Array`]=Ne.DataView;function Zn(e,t={},r){let n=nc(e),o=t&&t.typeEncoders&&t.typeEncoders[n]||Ne[n];if(typeof o=="function"){let s=o(e,n,t,r);if(s!=null)return s}let i=Ne[n];if(!i)throw new Error(`${Fi} unsupported type: ${n}`);return i(e,n,t,r)}function Qd(e,t){t.mapSorter&&e.sort(t.mapSorter)}function th(e,t){let r=Array.isArray(e[0])?e[0][0]:e[0],n=Array.isArray(t[0])?t[0][0]:t[0];if(r.type!==n.type)return r.type.compare(n.type);let o=r.type.major,i=iu[o].compareTokens(r,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function su(e,t,r,n){if(Array.isArray(t))for(let o of t)su(e,o,r,n);else r[t.type.major](e,t,n)}function eh(e,t,r){let n=Zn(e,r);if(!Array.isArray(n)&&r.quickEncodeToken){let o=r.quickEncodeToken(n);if(o)return o;let i=t[n.type.major];if(i.encodedSize){let s=i.encodedSize(n,r),a=new zr(s);if(i(a,n,r),a.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return Mi(a.chunks[0])}}return $i.reset(),su($i,n,t,r),$i.toBytes(!0)}function Gi(e,t){return t=Object.assign({},Xd,t),eh(e,iu,t)}var rh={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},jn=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=_[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}},Yr=Symbol.for("DONE"),Wn=Symbol.for("BREAK");function nh(e,t,r){let n=[];for(let o=0;o<e.value;o++){let i=yr(t,r);if(i===Wn){if(e.value===1/0)break;throw new Error(`${F} got unexpected break to lengthed array`)}if(i===Yr)throw new Error(`${F} found array but not enough entries (got ${o}, expected ${e.value})`);n[o]=i}return n}function oh(e,t,r){let n=r.useMaps===!0,o=n?void 0:{},i=n?new Map:void 0;for(let s=0;s<e.value;s++){let a=yr(t,r);if(a===Wn){if(e.value===1/0)break;throw new Error(`${F} got unexpected break to lengthed map`)}if(a===Yr)throw new Error(`${F} found map but not enough entries (got ${s} [no key], expected ${e.value})`);if(n!==!0&&typeof a!="string")throw new Error(`${F} non-string keys not supported (got ${typeof a})`);if(r.rejectDuplicateMapKeys===!0&&(n&&i.has(a)||!n&&a in o))throw new Error(`${F} found repeat map key "${a}"`);let c=yr(t,r);if(c===Yr)throw new Error(`${F} found map but not enough entries (got ${s} [no value], expected ${e.value})`);n?i.set(a,c):o[a]=c}return n?i:o}function yr(e,t){if(e.done())return Yr;let r=e.next();if(r.type===p.break)return Wn;if(r.type.terminal)return r.value;if(r.type===p.array)return nh(r,e,t);if(r.type===p.map)return oh(r,e,t);if(r.type===p.tag){if(t.tags&&typeof t.tags[r.value]=="function"){let n=yr(e,t);return t.tags[r.value](n)}throw new Error(`${F} tag not supported (${r.value})`)}throw new Error("unsupported")}function au(e,t){if(!(e instanceof Uint8Array))throw new Error(`${F} data to decode must be a Uint8Array`);t=Object.assign({},rh,t);let r=t.tokenizer||new jn(e,t),n=yr(r,t);if(n===Yr)throw new Error(`${F} did not find any content to decode`);if(n===Wn)throw new Error(`${F} got unexpected break`);return[n,e.subarray(r.pos())]}function Zi(e,t){let[r,n]=au(e,t);if(n.length>0)throw new Error(`${F} too many terminals, data makes no sense`);return r}var sh=ye("ipns:utils"),cu=G("/ipns/"),ah=114,ch=0,uh=18;function jr(e){let t;if(e.pubKey!=null)try{t=Ja(e.pubKey)}catch(r){throw sh.error(r),r}if(t!=null)return t}function uu(e,t,r){let n=G(t);return xe([e,r,n])}function Jn(e){let t=G("ipns-signature:");return xe([t,e])}function Qn(e){return"signatureV1"in e?pt.encode({value:G(e.value),signatureV1:e.signatureV1,validityType:e.validityType,validity:G(e.validity),sequence:e.sequence,ttl:e.ttl,pubKey:e.pubKey,signatureV2:e.signatureV2,data:e.data}):pt.encode({pubKey:e.pubKey,signatureV2:e.signatureV2,data:e.data})}function Jt(e){let t=pt.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 zt("Missing data or signatureV2");let r=du(t.data),n=fh(r.Value),o=j(r.Validity);if(t.value!=null&&t.signatureV1!=null)return lh(t),{value:n,validityType:pt.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:pt.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 Ge(e){return xe([cu,e.bytes])}function fu(e){let t=te(e.slice(cu.length));if(!Xn(t,ch)&&!Xn(t,uh))throw new je("Multihash in IPNS key was not identity or sha2-256");return t}function lu(e,t,r,n,o){let i;if(t===pt.ValidityType.EOL)i=0;else throw new ze("The validity type is unsupported");return Gi({Value:e,Validity:r,ValidityType:i,Sequence:n,TTL:o})}function du(e){let t=Zi(e);if(t.ValidityType===0)t.ValidityType=pt.ValidityType.EOL;else throw new ze("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 fh(e){let t=j(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 Hr("Value must be a valid content path starting with /")}function hu(e){if(e!=null){let t=ph(e);if(t!=null)return t.code===ah?`/ipns/${t.toString(Mt)}`:`/ipfs/${t.toV1().toString()}`;if(dh(e))return`/ipns/${Mt.encode(e.bytes)}`;let r=e.toString().trim();if(r.startsWith("/")&&r.length>1)return r}throw new Hr("Value must be a valid content path starting with /")}function lh(e){if(e.data==null)throw new On("Record data is missing");let t=du(e.data);if(!ot(t.Value,e.value??new Uint8Array(0)))throw new zt('Field "value" did not match between protobuf and CBOR');if(!ot(t.Validity,e.validity??new Uint8Array(0)))throw new zt('Field "validity" did not match between protobuf and CBOR');if(t.ValidityType!==e.validityType)throw new zt('Field "validityType" did not match between protobuf and CBOR');if(t.Sequence!==e.sequence)throw new zt('Field "sequence" did not match between protobuf and CBOR');if(t.TTL!==e.ttl)throw new zt('Field "ttl" did not match between protobuf and CBOR')}function dh(e){return e.bytes instanceof Uint8Array}function hh(e){return typeof e?.toCID=="function"}function ph(e){if(hh(e))return e.toCID();try{return J.parse(e)}catch{}return J.asCID(e)}function Xn(e,t){return e.code===t}var mh=ye("ipns"),mu=5*60*1e9,yh="/ipns/",iw=yh.length,yu={v1Compatible:!0,ttlNs:mu};async function gu(e,t,r,n,o=yu){let i=new pu.default(Date.now()+Number(n)),s=pt.ValidityType.EOL,a=BigInt(o.ttlNs??mu);return gh(e,t,r,s,i.toString(),a,o)}var gh=async(e,t,r,n,o,i,s=yu)=>{r=BigInt(r);let a=G(o),c=hu(t),f=G(c),u=lu(f,n,a,r,i),l=Jn(u),y=await e.sign(l),D;if(e.type==="RSA"&&(D=be(e.publicKey)),s.v1Compatible===!0){let T=await xh(e,f,n,a),m={value:c,signatureV1:T,validity:o,validityType:n,sequence:r,ttl:i,signatureV2:y,data:u};return D!=null&&(m.pubKey=D),m}else{let T={value:c,validity:o,validityType:n,sequence:r,ttl:i,signatureV2:y,data:u};return D!=null&&(T.pubKey=D),T}},xh=async(e,t,r,n)=>{try{let o=uu(t,r,n);return await e.sign(o)}catch(o){throw mh.error("record signature creation failed",o),new Pn("Record signature creation failed")}};var Yi=Qr(Ln(),1);function to(e,t){let r=t.map((n,o)=>({record:Jt(n),index:o}));return r.sort((n,o)=>{let i=n.record.sequence,s=o.record.sequence;if(i>s)return-1;if(i<s)return 1;if(n.record.validityType===pt.ValidityType.EOL&&o.record.validityType===pt.ValidityType.EOL){let a=Yi.default.fromString(n.record.validity).toDate(),c=Yi.default.fromString(o.record.validity).toDate();if(a.getTime()>c.getTime())return-1;if(a.getTime()<c.getTime())return 1}return 0}),r[0].index}var xu=Qr(Ln(),1);var eo=ye("ipns:validator"),wh=1024*10,bh=async(e,t)=>{let r=Jt(t),n;try{let o=Jn(r.data);n=await e.verify(o,r.signatureV2)}catch{n=!1}if(!n)throw eo.error("record signature verification failed"),new zt("Record signature verification failed");if(r.validityType===pt.ValidityType.EOL){if(xu.default.fromString(r.validity).toDate().getTime()<Date.now())throw eo.error("record has expired"),new kn("record has expired")}else if(r.validityType!=null)throw eo.error("the validity type is unsupported"),new ze("The validity type is unsupported");eo("ipns record for %s is valid",r.value)};async function Wr(e,t){if(t.byteLength>wh)throw new Kn("The record is too large");let r=fu(e),n;Xn(r,0)&&(n=In(r));let o=Jt(t),i=jr(o)??n;if(i==null)throw new qr("Could not extract public key from IPNS record or routing key");let s=Ge(i.toMultihash());if(!ot(s,e))throw new qr("Embedded public key did not match routing key");await bh(i,t)}var xt=class extends Event{type;detail;constructor(t,r){super(t),this.type=t,this.detail=r}};var Ah=Qr(bu(),1);var de;(function(e){e[e.A=1]="A",e[e.CNAME=5]="CNAME",e[e.TXT=16]="TXT",e[e.AAAA=28]="AAAA"})(de||(de={}));var ro=class extends Error{static name="DNSLinkNotFoundError";constructor(t="DNSLink not found"){super(t),this.name="DNSLinkNotFoundError"}},no=class extends Error{static name="RecordsFailedValidationError";constructor(t="Records failed validation"){super(t),this.name="RecordsFailedValidationError"}},oo=class extends Error{static name="UnsupportedMultibasePrefixError";constructor(t="Unsupported multibase prefix"){super(t),this.name="UnsupportedMultibasePrefixError"}},io=class extends Error{static name="UnsupportedMultihashCodecError";constructor(t="Unsupported multihash codec"){super(t),this.name="UnsupportedMultihashCodecError"}},so=class extends Error{static name="InvalidValueError";constructor(t="Invalid value"){super(t),this.name="InvalidValueError"}};var vh=32;async function Eu(e,t,r,n,o={}){if(t===0)throw new Error("recursion limit exceeded");n("query %s for TXT and CNAME records",e);let s=((await r.query(e,{...o,types:[de.TXT]}))?.Answer??[]).sort((f,u)=>f.data.localeCompare(u.data));n("found %d TXT records for %s",s.length,e);for(let f of s)try{let u=f.data;if(u.startsWith('"')&&u.endsWith('"')&&(u=u.substring(1,u.length-1)),!u.startsWith("dnslink="))continue;n("%s TXT %s",f.name,u),u=u.replace("dnslink=","");let[,l,y,...D]=u.split("/");if(l==="ipfs")try{return{value:`/ipfs/${J.parse(y)}${D.length>0?`/${D.join("/")}`:""}`,answer:f}}catch{}else if(l==="ipns"){try{let T;return y.charAt(0)==="1"||y.charAt(0)==="Q"?T=Rn(y):T=Ki(J.parse(y)),{value:`/ipns/${T}${D.length>0?`/${D.join("/")}`:""}`,answer:f}}catch{}return await ao(y,t-1,r,n,o)}else{if(l==="dnslink")return await ao(y,t-1,r,n,o);n('unknown protocol "%s" in DNSLink record for domain: %s',l,e);continue}}catch(u){n.error("could not parse DNS link record for domain %s, %s",e,f.data,u)}n("no DNSLink records found for %s, falling back to CNAME",e);let c=((await r.query(e,{...o,types:[de.CNAME]}))?.Answer??[]).sort((f,u)=>f.data.localeCompare(u.data));n("found %d CNAME records for %s",c.length,e);for(let f of c)try{return await ao(f.data,t-1,r,n,o)}catch(u){n.error("domain %s cname %s had no DNSLink records",e,f.data,u)}throw new ro(`No DNSLink records found for domain: ${e}`)}async function ao(e,t,r,n,o={}){if(t===0)throw new Error("recursion limit exceeded");e.startsWith("_dnslink.")||(e=`_dnslink.${e}`);try{return await Eu(e,t,r,n,o)}catch(i){if(i.code!=="ENOTFOUND"&&i.code!=="ENODATA"&&i.name!=="DNSLinkNotFoundError"&&i.name!=="NotFoundError")throw i;return e.startsWith("_dnslink.")?e=e.replace("_dnslink.",""):e=`_dnslink.${e}`,Eu(e,t,r,n,o)}}async function Su(e,t,r,n={}){return ao(e,n.maxRecursiveDepth??vh,t,r,n)}var ji=class{routing;constructor(t){this.routing=t}async put(t,r,n={}){try{await this.routing.put(t,r,n)}catch(o){throw n.onProgress?.(new xt("ipns:routing:helia:error",o)),o}}async get(t,r={}){try{return await this.routing.get(t,r)}catch(n){throw r.onProgress?.(new xt("ipns:routing:helia:error",n)),n}}};function Au(e){return new ji(e)}var Xr;(function(e){let t;e.codec=()=>(t==null&&(t=Ue((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.key!=null&&r.key.byteLength>0&&(n.uint32(10),n.bytes(r.key)),r.value!=null&&r.value.byteLength>0&&(n.uint32(18),n.bytes(r.value)),r.timeReceived!=null&&r.timeReceived!==""&&(n.uint32(42),n.string(r.timeReceived)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let i={key:Pt(0),value:Pt(0),timeReceived:""},s=n==null?r.len:r.pos+n;for(;r.pos<s;){let a=r.uint32();switch(a>>>3){case 1:{i.key=r.bytes();break}case 2:{i.value=r.bytes();break}case 5:{i.timeReceived=r.string();break}default:{r.skipType(a&7);break}}}return i})),t),e.encode=r=>_e(r,e.codec()),e.decode=(r,n)=>Ie(r,e.codec(),n)})(Xr||(Xr={}));function vu(e){let t=e.getUTCFullYear(),r=String(e.getUTCMonth()+1).padStart(2,"0"),n=String(e.getUTCDate()).padStart(2,"0"),o=String(e.getUTCHours()).padStart(2,"0"),i=String(e.getUTCMinutes()).padStart(2,"0"),s=String(e.getUTCSeconds()).padStart(2,"0"),a=e.getUTCMilliseconds(),c=String(a*1e3*1e3).padStart(9,"0");return`${t}-${r}-${n}T${o}:${i}:${s}.${c}Z`}function Tu(e){let t=new RegExp("(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})\\.(\\d+)Z"),r=String(e).trim().match(t);if(r==null)throw new Error("Invalid format");let n=parseInt(r[1],10),o=parseInt(r[2],10)-1,i=parseInt(r[3],10),s=parseInt(r[4],10),a=parseInt(r[5],10),c=parseInt(r[6],10),f=parseInt(r[7].slice(0,-6),10);return new Date(Date.UTC(n,o,i,s,a,c,f))}var Ze=class e{key;value;timeReceived;constructor(t,r,n){if(!(t instanceof Uint8Array))throw new Error("key must be a Uint8Array");if(!(r instanceof Uint8Array))throw new Error("value must be a Uint8Array");this.key=t,this.value=r,this.timeReceived=n}serialize(){return Xr.encode(this.prepareSerialize())}prepareSerialize(){return{key:this.key,value:this.value,timeReceived:vu(this.timeReceived)}}static deserialize(t){let r=Xr.decode(t);return new e(r.key,r.value,new Date(r.timeReceived))}static fromDeserialized(t){let r=Tu(t.timeReceived);if(t.key==null)throw new Error("key missing from deserialized object");if(t.value==null)throw new Error("value missing from deserialized object");return new e(t.key,t.value,r)}};var Cu;(function(e){e[e.SEND_QUERY=0]="SEND_QUERY",e[e.PEER_RESPONSE=1]="PEER_RESPONSE",e[e.FINAL_PEER=2]="FINAL_PEER",e[e.QUERY_ERROR=3]="QUERY_ERROR",e[e.PROVIDER=4]="PROVIDER",e[e.VALUE=5]="VALUE",e[e.ADD_PEER=6]="ADD_PEER",e[e.DIAL_PEER=7]="DIAL_PEER",e[e.PATH_ENDED=8]="PATH_ENDED"})(Cu||(Cu={}));function co(e){return new Vr("/dht/record/"+j(e,"base32"),!1)}function Bu(e){return{async put(t,r,n={}){try{let o=co(t);try{let s=await e.get(o),a=Ze.deserialize(s);if(ot(a.value,r))return}catch(s){if(s.name!=="NotFoundError")throw s}let i=new Ze(t,r,new Date);n.onProgress?.(new xt("ipns:routing:datastore:put")),await e.put(o,i.serialize(),n)}catch(o){throw n.onProgress?.(new xt("ipns:routing:datastore:error",o)),o}},async get(t,r={}){try{let n=co(t);r.onProgress?.(new xt("ipns:routing:datastore:get"));let o=await e.get(n,r),i=Ze.deserialize(o);return{record:i.value,created:i.timeReceived}}catch(n){throw r.onProgress?.(new xt("ipns:routing:datastore:error",n)),n}},async has(t,r={}){let n=co(t);return e.has(n,r)},async delete(t,r){let n=co(t);return e.delete(n,r)}}}var Wi="/ipns/";function Xi(e,t){return e.code===t}var he=ye("helia:ipns"),Uu=60*1e3,Du=60*Uu,Ih=48*Du,Ji=23*Du,Iu=BigInt(Uu)*5000000n,_u={[Mt.prefix]:Mt,[X.prefix]:X},Qi=class{routers;localStore;timeout;dns;log;constructor(t,r=[]){this.routers=[Au(t.routing),...r],this.localStore=Bu(t.datastore),this.dns=t.dns,this.log=t.logger.forComponent("helia:ipns")}async publish(t,r,n={}){try{let o=1n,i=Ge(t.publicKey.toMultihash());if(await this.localStore.has(i,n)){let{record:f}=await this.localStore.get(i,n);o=Jt(f).sequence+1n}let s=n.ttl!=null?BigInt(n.ttl)*1000000n:Iu,a=await gu(t,r,o,n.lifetime??Ih,{...n,ttlNs:s}),c=Qn(a);return await this.localStore.put(i,c,n),n.offline!==!0&&await Promise.all(this.routers.map(async f=>{await f.put(i,c,n)})),a}catch(o){throw n.onProgress?.(new xt("ipns:publish:error",o)),o}}async resolve(t,r={}){let n=ns(t)?t.toMultihash():t,o=Ge(n),i=await this.#e(o,r);return{...await this.#t(i.value,r),record:i}}async resolveDNSLink(t,r={}){let n=await Su(t,this.dns,this.log,r);return{...await this.#t(n.value,r),answer:n.answer}}republish(t={}){if(this.timeout!=null)throw new Error("Republish is already running");t.signal?.addEventListener("abort",()=>{clearTimeout(this.timeout)});async function r(){let n=Date.now();t.onProgress?.(new xt("ipns:republish:start"));let i=Date.now()-n,s=Ji-i;s<0&&(s=t.interval??Ji),setTimeout(()=>{r().catch(a=>{he.error("error republishing",a)})},s)}this.timeout=setTimeout(()=>{r().catch(n=>{he.error("error republishing",n)})},t.interval??Ji)}async#t(t,r={}){let n=t.split("/");try{let o=n[1];if(o==="ipns"){let i=n[2],s=i.substring(0,1),a;if(s==="1"||s==="Q")a=X.decode(`z${i}`);else if(_u[s]!=null)a=_u[s].decode(i);else throw new oo(`Unsupported multibase prefix "${s}"`);let c;try{c=te(a)}catch{c=J.decode(a).multihash}if(!Xi(c,0)&&!Xi(c,18))throw new io(`Unsupported multihash codec "${c.code}"`);let{cid:f}=await this.resolve(c,r),u=n.slice(3).join("/");return{cid:f,path:u}}else if(o==="ipfs"){let i=J.parse(n[2]),s=n.slice(3).join("/");return{cid:i,path:s}}}catch(o){he.error("error parsing ipfs path",o)}throw he.error("invalid ipfs path %s",t),new so("Invalid value")}async#e(t,r={}){let n=[];if(await this.localStore.has(t,r))if(he("record is present in the cache"),r.nocache!==!0)try{let{record:a,created:c}=await this.localStore.get(t,r);this.log("record retrieved from cache"),await Wr(t,a),this.log("record was valid");let f=Jt(a),u=Number((f.ttl??Iu)/1000000n);if(c.getTime()+u>Date.now())return this.log("record TTL was valid"),f;if(r.offline===!0)return this.log("record TTL has been reached but we are resolving offline-only, returning record"),f;this.log("record TTL has been reached, searching routing for updates"),n.push(a)}catch(a){this.log("cached record was invalid",a),await this.localStore.delete(t,r)}else he("ignoring local cache due to nocache=true option");if(r.offline===!0)throw new xr("Record was not present in the cache or has expired");he("did not have record locally");let i=0;if(await Promise.all(this.routers.map(async a=>{let c;try{c=await a.get(t,{...r,validate:!1})}catch(f){he.error("error finding IPNS record",f);return}try{await Wr(t,c),n.push(c)}catch(f){i++,he.error("error finding IPNS record",f)}})),n.length===0)throw i>0?new no(`${i>1?`${i} records`:"Record"} found for routing key ${i>1?"were":"was"} invalid`):new xr("Could not find record for routing key");let s=n[to(t,n)];return await this.localStore.put(t,s,r),Jt(s)}async republishRecord(t,r,n={}){let o;try{if(o=jr(r)?.toMultihash(),o==null)if(typeof t=="string"){t.startsWith(Wi)&&(t=t.slice(Wi.length));try{o=Rn(t).toMultihash()}catch(a){throw new Error(`Invalid string key: ${a.message}`)}}else o=t;if(o==null)throw new Error("No public key multihash found to determine the routing key");let i=Ge(o),s=Qn(r);await Wr(i,s),await this.localStore.put(i,s,n),n.offline!==!0&&await Promise.all(this.routers.map(async a=>{await a.put(i,s,n)}))}catch(i){throw n.onProgress?.(new xt("ipns:republish:error",{key:o,record:r,err:i})),i}}};function _h(e,{routers:t=[]}={}){return new Qi(e,t)}return Vu(Uh);})();
|
|
2
|
+
"use strict";var HeliaIpns=(()=>{var ju=Object.create;var cn=Object.defineProperty;var Xu=Object.getOwnPropertyDescriptor;var Wu=Object.getOwnPropertyNames;var Ju=Object.getPrototypeOf,Qu=Object.prototype.hasOwnProperty;var xs=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),bt=(e,t)=>{for(var r in t)cn(e,r,{get:t[r],enumerable:!0})},ws=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Wu(t))!Qu.call(e,o)&&o!==r&&cn(e,o,{get:()=>t[o],enumerable:!(n=Xu(t,o))||n.enumerable});return e};var un=(e,t,r)=>(r=e!=null?ju(Ju(e)):{},ws(t||!e||!e.__esModule?cn(r,"default",{value:e,enumerable:!0}):r,e)),tf=e=>ws(cn({},"__esModule",{value:!0}),e);var $n=xs((px,ts)=>{var hx=function(){typeof ts<"u"&&(ts.exports=b);var e=86400,t=3200,r=146097*t/400,n=e*r,o=1e3*n,i=864e13,s=4294967296,a=1e6,c="000000000",l=Math.trunc||function(v){var m=v-v%1;return m==0&&(v<0||v===0&&1/v!=1/0)?-0:m},u=b.prototype,d=(b.fromDate=function(v){return new b(+v)},b.fromInt64BE=N(0,1,2,3,0,4),b.fromInt64LE=N(3,2,1,0,4,0),b.fromString=function(I){var m,C=new b,I=(I+="").replace(/^\s*[+\-]?\d+/,function(x){var x=+x,g=1970+(x-1970)%400;return C.year=x-g,g}).replace(/(?:Z|([+\-]\d{2}):?(\d{2}))$/,function(B,x,g){return x<0&&(g*=-1),m=6e4*(60*+x+ +g),""}).replace(/\.\d+$/,function(B){return C.nano=+(B+c).substr(1,9),""}).split(/\D+/);if(1<I.length?I[1]--:I[1]=0,C.time=m=Date.UTC.apply(Date,I)-(m||0),isNaN(m))throw new TypeError("Invalid Date");return T(C)},b.fromTimeT=function(v){return U(v,0)},u.year=0,u.time=0,u.nano=0,u.addNano=function(v){return this.nano+=+v||0,this},u.getNano=function(){var v=T(this);return(v.time%1e3*a+ +v.nano+1e9)%1e9},u.getTimeT=function(){var m=T(this),v=Math.floor(m.time/1e3),m=m.year;return m&&(v+=m*r*e/t),v},u.getYear=function(){return this.toDate().getUTCFullYear()+this.year},u.toDate=function(){return E(T(this).time)},u.toJSON=function(){return this.toString().replace(/0{1,6}Z$/,"Z")},u.toString=function(v){var m=this,C=m.toDate(),I={H:function(){return M(C.getUTCHours())},L:function(){return F(C.getUTCMilliseconds(),3)},M:function(){return M(C.getUTCMinutes())},N:function(){return F(m.getNano(),9)},S:function(){return M(C.getUTCSeconds())},Y:function(){var B=m.getYear();return 999999<B?"+"+B:9999<B?"+"+F(B,6):0<=B?F(B,4):-999999<=B?"-"+F(-B,6):B},a:function(){return y[C.getUTCDay()]},b:function(){return f[C.getUTCMonth()]},d:function(){return M(C.getUTCDate())},e:function(){return function(B){return(9<B?"":" ")+(0|B)}(C.getUTCDate())},m:function(){return M(C.getUTCMonth()+1)}};return function B(x){return x.replace(/%./g,function(g){var A=g[1],h=p[A],A=I[A];return h?B(h):A?A():g})}(v||d)},u.writeInt64BE=S(0,1,2,3,0,4),u.writeInt64LE=S(3,2,1,0,4,0),"%Y-%m-%dT%H:%M:%S.%NZ"),f=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],y=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],p={"%":"%",F:"%Y-%m-%d",n:`
|
|
3
|
+
`,R:"%H:%M",T:"%H:%M:%S",t:" ",X:"%T",Z:"GMT",z:"+0000"};return b;function b(v,m,C){var I=this;if(!(I instanceof b))return new b(v,m,C);I.time=+v||0,I.nano=+m||0,I.year=+C||0,T(I)}function T(v){var m,C,I,B=v.year,x=v.time,g=v.nano,h=((g<0||a<=g)&&(g-=(C=Math.floor(g/a))*a,x+=C,C=1),B%t);return(x<-i||i<x||h)&&((m=l(x/o))&&(B+=m*t,x-=m*o),(I=E(x)).setUTCFullYear(h+I.getUTCFullYear()),I=(x=+I)+(m=l((B-=h)/t))*o,m&&-i<=I&&I<=i&&(B-=m*t,x=I),C=1),C&&(v.year=B,v.time=x,v.nano=g),v}function E(v){var m=new Date(0);return m.setTime(v),m}function U(B,I){B=+B||0;var C=l((I=(I|0)*s)/n)+l(B/n),I=I%n+B%n,B=l(I/n);return B&&(C+=B,I-=B*n),new b(1e3*I,0,C*t)}function S(v,m,C,I,B,x){return function(h,A){var k=T(this);h=h||new Array(8),P(h,A|=0);var L=Math.floor(k.time/1e3),k=k.year*(r*e/t),D=l(k/s)+l(L/s),k=k%s+L%s,L=Math.floor(k/s);return L&&(D+=L,k-=L*s),g(h,A+B,D),g(h,A+x,k),h};function g(h,A,D){h[A+v]=D>>24&255,h[A+m]=D>>16&255,h[A+C]=D>>8&255,h[A+I]=255&D}}function N(v,m,C,I,B,x){return function(h,A){P(h,A|=0);var D=g(h,A+B);return U(g(h,A+x),D)};function g(h,A){return 16777216*h[A+v]+(h[A+m]<<16|h[A+C]<<8|h[A+I])}}function P(v,m){if(v=v&&v.length,v==null)throw new TypeError("Invalid Buffer");if(v<m+8)throw new RangeError("Out of range")}function M(v){return(9<v?"":"0")+(0|v)}function F(v,m){return(c+(0|v)).substr(-m)}}()});var Ku=xs((ub,ku)=>{ku.exports=function(e){if(!e)throw Error("hashlru must have a max value, of type number, greater than 0");var t=0,r=Object.create(null),n=Object.create(null);function o(i,s){r[i]=s,t++,t>=e&&(t=0,n=r,r=Object.create(null))}return{has:function(i){return r[i]!==void 0||n[i]!==void 0},remove:function(i){r[i]!==void 0&&(r[i]=void 0),n[i]!==void 0&&(n[i]=void 0)},get:function(i){var s=r[i];if(s!==void 0)return s;if((s=n[i])!==void 0)return o(i,s),s},set:function(i,s){r[i]!==void 0?r[i]=s:o(i,s)},clear:function(){r=Object.create(null),n=Object.create(null)}}}});var rp={};bt(rp,{ipns:()=>ep,ipnsSelector:()=>fo,ipnsValidator:()=>nn});function bs(e){return e==null?!1:(e.type==="RSA"||e.type==="Ed25519"||e.type==="secp256k1"||e.type==="ECDSA")&&e.raw instanceof Uint8Array&&typeof e.equals=="function"&&typeof e.toMultihash=="function"&&typeof e.toCID=="function"&&typeof e.verify=="function"}var Eo=Symbol.for("@libp2p/peer-id");var it=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},je=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Ar=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}};var fn=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},Xe=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var We=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var To={};bt(To,{base32:()=>ge,base32hex:()=>lf,base32hexpad:()=>hf,base32hexpadupper:()=>pf,base32hexupper:()=>df,base32pad:()=>uf,base32padupper:()=>ff,base32upper:()=>cf,base32z:()=>mf});var ap=new Uint8Array(0);function Es(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Xt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function Ss(e){return new TextEncoder().encode(e)}function As(e){return new TextDecoder().decode(e)}function ef(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var i=e.charAt(o),s=i.charCodeAt(0);if(r[s]!==255)throw new TypeError(i+" is ambiguous");r[s]=o}var a=e.length,c=e.charAt(0),l=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function d(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var b=0,T=0,E=0,U=p.length;E!==U&&p[E]===0;)E++,b++;for(var S=(U-E)*u+1>>>0,N=new Uint8Array(S);E!==U;){for(var P=p[E],M=0,F=S-1;(P!==0||M<T)&&F!==-1;F--,M++)P+=256*N[F]>>>0,N[F]=P%a>>>0,P=P/a>>>0;if(P!==0)throw new Error("Non-zero carry");T=M,E++}for(var v=S-T;v!==S&&N[v]===0;)v++;for(var m=c.repeat(b);v<S;++v)m+=e.charAt(N[v]);return m}function f(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var b=0;if(p[b]!==" "){for(var T=0,E=0;p[b]===c;)T++,b++;for(var U=(p.length-b)*l+1>>>0,S=new Uint8Array(U);p[b];){var N=r[p.charCodeAt(b)];if(N===255)return;for(var P=0,M=U-1;(N!==0||P<E)&&M!==-1;M--,P++)N+=a*S[M]>>>0,S[M]=N%256>>>0,N=N/256>>>0;if(N!==0)throw new Error("Non-zero carry");E=P,b++}if(p[b]!==" "){for(var F=U-E;F!==U&&S[F]===0;)F++;for(var v=new Uint8Array(T+(U-F)),m=T;F!==U;)v[m++]=S[F++];return v}}}function y(p){var b=f(p);if(b)return b;throw new Error(`Non-${t} character`)}return{encode:d,decodeUnsafe:f,decode:y}}var rf=ef,nf=rf,Bs=nf;var So=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Ao=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Ts(this,t)}},vo=class{decoders;constructor(t){this.decoders=t}or(t){return Ts(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Ts(e,t){return new vo({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var Bo=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new So(t,r,n),this.decoder=new Ao(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Je({name:e,prefix:t,encode:r,decode:n}){return new Bo(e,t,r,n)}function ye({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Bs(r,e);return Je({prefix:t,name:e,encode:n,decode:i=>Xt(o(i))})}function of(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let i=new Uint8Array(o*r/8|0),s=0,a=0,c=0;for(let l=0;l<o;++l){let u=t[e[l]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|u,s+=r,s>=8&&(s-=8,i[c++]=255&a>>s)}if(s>=r||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function sf(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,i="",s=0,a=0;for(let c=0;c<e.length;++c)for(a=a<<8|e[c],s+=8;s>r;)s-=r,i+=t[o&a>>s];if(s!==0&&(i+=t[o&a<<r-s]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function af(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function et({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=af(n);return Je({prefix:t,name:e,encode(i){return sf(i,n,r)},decode(i){return of(i,o,r,e)}})}var ge=et({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),cf=et({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),uf=et({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),ff=et({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),lf=et({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),df=et({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),hf=et({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),pf=et({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),mf=et({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Co={};bt(Co,{base58btc:()=>G,base58flickr:()=>yf});var G=ye({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),yf=ye({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var _o={};bt(_o,{base64:()=>Io,base64pad:()=>gf,base64url:()=>xf,base64urlpad:()=>wf});var Io=et({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),gf=et({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),xf=et({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),wf=et({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});function bf(e,t){try{if(typeof e=="string"&&e.length>0)return Ef(e);if(typeof e=="number"&&isFinite(e))return t?.long?Af(e):Sf(e);throw new Error("Value is not a string or number.")}catch(r){let n=vf(r)?`${r.message}. value=${JSON.stringify(e)}`:"An unknown error has occured.";throw new Error(n)}}function Ef(e){if(e=String(e),e.length>100)throw new Error("Value exceeds the maximum length of 100 characters.");let t=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);if(!t)return NaN;let r=parseFloat(t[1]),n=(t[2]||"ms").toLowerCase();switch(n){case"years":case"year":case"yrs":case"yr":case"y":return r*315576e5;case"weeks":case"week":case"w":return r*6048e5;case"days":case"day":case"d":return r*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return r*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return r*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return r*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return r;default:throw new Error(`The unit ${n} was matched, but no matching case exists.`)}}var dn=bf;function Sf(e){let t=Math.abs(e);return t>=864e5?`${Math.round(e/864e5)}d`:t>=36e5?`${Math.round(e/36e5)}h`:t>=6e4?`${Math.round(e/6e4)}m`:t>=1e3?`${Math.round(e/1e3)}s`:`${e}ms`}function Af(e){let t=Math.abs(e);return t>=864e5?ln(e,t,864e5,"day"):t>=36e5?ln(e,t,36e5,"hour"):t>=6e4?ln(e,t,6e4,"minute"):t>=1e3?ln(e,t,1e3,"second"):`${e} ms`}function ln(e,t,r,n){let o=t>=r*1.5;return`${Math.round(e/r)} ${n}${o?"s":""}`}function vf(e){return typeof e=="object"&&e!==null&&"message"in e}function Uo(e){r.debug=r,r.default=r,r.coerce=c,r.disable=i,r.enable=o,r.enabled=s,r.humanize=dn,r.destroy=l,Object.keys(e).forEach(u=>{r[u]=e[u]}),r.names=[],r.skips=[],r.formatters={};function t(u){let d=0;for(let f=0;f<u.length;f++)d=(d<<5)-d+u.charCodeAt(f),d|=0;return r.colors[Math.abs(d)%r.colors.length]}r.selectColor=t;function r(u){let d,f=null,y,p;function b(...T){if(!b.enabled)return;let E=b,U=Number(new Date),S=U-(d||U);E.diff=S,E.prev=d,E.curr=U,d=U,T[0]=r.coerce(T[0]),typeof T[0]!="string"&&T.unshift("%O");let N=0;T[0]=T[0].replace(/%([a-zA-Z%])/g,(M,F)=>{if(M==="%%")return"%";N++;let v=r.formatters[F];if(typeof v=="function"){let m=T[N];M=v.call(E,m),T.splice(N,1),N--}return M}),r.formatArgs.call(E,T),(E.log||r.log).apply(E,T)}return b.namespace=u,b.useColors=r.useColors(),b.color=r.selectColor(u),b.extend=n,b.destroy=r.destroy,Object.defineProperty(b,"enabled",{enumerable:!0,configurable:!1,get:()=>f!==null?f:(y!==r.namespaces&&(y=r.namespaces,p=r.enabled(u)),p),set:T=>{f=T}}),typeof r.init=="function"&&r.init(b),b}function n(u,d){let f=r(this.namespace+(typeof d>"u"?":":d)+u);return f.log=this.log,f}function o(u){r.save(u),r.namespaces=u,r.names=[],r.skips=[];let d,f=(typeof u=="string"?u:"").split(/[\s,]+/),y=f.length;for(d=0;d<y;d++)f[d]&&(u=f[d].replace(/\*/g,".*?"),u[0]==="-"?r.skips.push(new RegExp("^"+u.substr(1)+"$")):r.names.push(new RegExp("^"+u+"$")))}function i(){let u=[...r.names.map(a),...r.skips.map(a).map(d=>"-"+d)].join(",");return r.enable(""),u}function s(u){if(u[u.length-1]==="*")return!0;let d,f;for(d=0,f=r.skips.length;d<f;d++)if(r.skips[d].test(u))return!1;for(d=0,f=r.names.length;d<f;d++)if(r.names[d].test(u))return!0;return!1}function a(u){return u.toString().substring(2,u.toString().length-2).replace(/\.\*\?$/,"*")}function c(u){return u instanceof Error?u.stack??u.message:u}function l(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return r.setupFormatters(r.formatters),r.enable(r.load()),r}var hn=Df(),Bf=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function Tf(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/(edge|trident)\/(\d+)/)!=null?!1:typeof document<"u"&&document.documentElement?.style?.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/firefox\/(\d+)/)!=null&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/applewebkit\/(\d+)/)}function Cf(e){if(e[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+e[0]+(this.useColors?"%c ":" ")+"+"+dn(this.diff),!this.useColors)return;let t="color: "+this.color;e.splice(1,0,t,"color: inherit");let r=0,n=0;e[0].replace(/%[a-zA-Z%]/g,o=>{o!=="%%"&&(r++,o==="%c"&&(n=r))}),e.splice(n,0,t)}var If=console.debug??console.log??(()=>{});function _f(e){try{e?hn?.setItem("debug",e):hn?.removeItem("debug")}catch{}}function Uf(){let e;try{e=hn?.getItem("debug")}catch{}return!e&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(e=globalThis.process.env.DEBUG),e}function Df(){try{return localStorage}catch{}}function Rf(e){e.j=function(t){try{return JSON.stringify(t)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var Cs=Uo({formatArgs:Cf,save:_f,load:Uf,useColors:Tf,setupFormatters:Rf,colors:Bf,storage:hn,log:If});var Et=Cs;Et.formatters.b=e=>e==null?"undefined":G.baseEncode(e);Et.formatters.t=e=>e==null?"undefined":ge.baseEncode(e);Et.formatters.m=e=>e==null?"undefined":Io.baseEncode(e);Et.formatters.p=e=>e==null?"undefined":e.toString();Et.formatters.c=e=>e==null?"undefined":e.toString();Et.formatters.k=e=>e==null?"undefined":e.toString();Et.formatters.a=e=>e==null?"undefined":e.toString();Et.formatters.e=e=>e==null?"undefined":Is(e.stack)??Is(e.message)??e.toString();function Lf(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 xe(e){let t=Lf(`${e}:trace`);return Et.enabled(`${e}:trace`)&&Et.names.map(r=>r.toString()).find(r=>r.includes(":trace"))!=null&&(t=Et(`${e}:trace`)),Object.assign(Et(e),{error:Et(`${e}:error`),trace:t})}function Is(e){if(e!=null&&(e=e.trim(),e.length!==0))return e}var Do={};bt(Do,{base36:()=>Ot,base36upper:()=>Nf});var Ot=ye({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Nf=ye({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var kf=Ds,_s=128,Kf=127,Pf=~Kf,Of=Math.pow(2,31);function Ds(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Of;)t[r++]=e&255|_s,e/=128;for(;e&Pf;)t[r++]=e&255|_s,e>>>=7;return t[r]=e|0,Ds.bytes=r-n+1,t}var Mf=Ro,Ff=128,Us=127;function Ro(e,n){var r=0,n=n||0,o=0,i=n,s,a=e.length;do{if(i>=a)throw Ro.bytes=0,new RangeError("Could not decode varint");s=e[i++],r+=o<28?(s&Us)<<o:(s&Us)*Math.pow(2,o),o+=7}while(s>=Ff);return Ro.bytes=i-n,r}var Vf=Math.pow(2,7),qf=Math.pow(2,14),Hf=Math.pow(2,21),$f=Math.pow(2,28),zf=Math.pow(2,35),Zf=Math.pow(2,42),Gf=Math.pow(2,49),Yf=Math.pow(2,56),jf=Math.pow(2,63),Xf=function(e){return e<Vf?1:e<qf?2:e<Hf?3:e<$f?4:e<zf?5:e<Zf?6:e<Gf?7:e<Yf?8:e<jf?9:10},Wf={encode:kf,decode:Mf,encodingLength:Xf},Jf=Wf,vr=Jf;function Br(e,t=0){return[vr.decode(e,t),vr.decode.bytes]}function Qe(e,t,r=0){return vr.encode(e,t,r),t}function tr(e){return vr.encodingLength(e)}function Mt(e,t){let r=t.byteLength,n=tr(e),o=n+tr(r),i=new Uint8Array(o+r);return Qe(e,i,0),Qe(r,i,n),i.set(t,o),new er(e,r,t,i)}function Wt(e){let t=Xt(e),[r,n]=Br(t),[o,i]=Br(t.subarray(n)),s=t.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new er(r,o,s,t)}function Rs(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Es(e.bytes,r.bytes)}}var er=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function Ls(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return tl(r,Lo(e),t??G.encoder);default:return el(r,Lo(e),t??ge.encoder)}}var Ns=new WeakMap;function Lo(e){let t=Ns.get(e);if(t==null){let r=new Map;return Ns.set(e,r),r}return t}var Y=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==Tr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==rl)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:r}=this.multihash,n=Mt(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&Rs(t.multihash,n.multihash)}toString(t){return Ls(this,t)}toJSON(){return{"/":Ls(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:i,bytes:s}=r;return new e(n,o,i,s??ks(n,o,i.bytes))}else if(r[nl]===!0){let{version:n,multihash:o,code:i}=r,s=Wt(o);return e.create(n,i,s)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==Tr)throw new Error(`Version 0 CID must use dag-pb (code: ${Tr}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=ks(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,Tr,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=Xt(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=o.subarray(r.multihashSize-r.digestSize),s=new er(r.multihashCode,r.digestSize,i,o);return[r.version===0?e.createV0(s):e.createV1(r.codec,s),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[d,f]=Br(t.subarray(r));return r+=f,d},o=n(),i=Tr;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=r,a=n(),c=n(),l=r+c,u=l-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:u,size:l}}static parse(t,r){let[n,o]=Qf(t,r),i=e.decode(o);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Lo(i).set(n,t),i}};function Qf(e,t){switch(e[0]){case"Q":{let r=t??G;return[G.prefix,r.decode(`${G.prefix}${e}`)]}case G.prefix:{let r=t??G;return[G.prefix,r.decode(e)]}case ge.prefix:{let r=t??ge;return[ge.prefix,r.decode(e)]}case Ot.prefix:{let r=t??Ot;return[Ot.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function tl(e,t,r){let{prefix:n}=r;if(n!==G.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let i=r.encode(e).slice(1);return t.set(n,i),i}else return o}function el(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let i=r.encode(e);return t.set(n,i),i}else return o}var Tr=112,rl=18;function ks(e,t,r){let n=tr(e),o=n+tr(t),i=new Uint8Array(o+r.byteLength);return Qe(e,i,0),Qe(t,i,n),i.set(r,o),i}var nl=Symbol.for("@ipld/js-cid/CID");var No={};bt(No,{identity:()=>Ft});var Ks=0,ol="identity",Ps=Xt;function il(e){return Mt(Ks,Ps(e))}var Ft={code:Ks,name:ol,encode:Ps,digest:il};function nt(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Lt(e=0){return new Uint8Array(e)}function vt(e=0){return new Uint8Array(e)}function be(e,t){t==null&&(t=e.reduce((o,i)=>o+i.length,0));let r=vt(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var Ms=Symbol.for("@achingbrain/uint8arraylist");function Os(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let o=r+n.byteLength;if(t<o)return{buf:n,index:t-r};r=o}throw new RangeError("index is out of bounds")}function mn(e){return!!e?.[Ms]}var Bt=class e{bufs;length;[Ms]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(mn(n))r+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...t){this.prependAll(t)}prependAll(t){let r=0;for(let n of t.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(mn(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(t){let r=Os(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Os(this.bufs,t);n.buf[n.index]=r}write(t,r=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(r+n,t[n]);else if(mn(t))for(let n=0;n<t.length;n++)this.set(r+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,r){let{bufs:n,length:o}=this._subList(t,r);return be(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:be(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),i=new e;return i.length=o,i.bufs=[...n],i}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let i=0;i<this.bufs.length;i++){let s=this.bufs[i],a=o,c=a+s.byteLength;if(o=c,t>=c)continue;let l=t>=a&&t<c,u=r>a&&r<=c;if(l&&u){if(t===a&&r===c){n.push(s);break}let d=t-a;n.push(s.subarray(d,d+(r-t)));break}if(l){if(t===0){n.push(s);continue}n.push(s.subarray(t-a));continue}if(u){if(r===c){n.push(s);break}n.push(s.subarray(0,r-a));break}n.push(s)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!mn(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,s=new Int32Array(i);for(let d=0;d<i;d++)s[d]=-1;for(let d=0;d<o;d++)s[n[d]]=d;let a=s,c=this.byteLength-n.byteLength,l=n.byteLength-1,u;for(let d=r;d<=c;d+=u){u=0;for(let f=l;f>=0;f--){let y=this.get(d+f);if(n[f]!==y){u=Math.max(1,f-a[y]);break}}if(u===0)return d}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=vt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=Lt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=Lt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=Lt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=vt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=Lt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=Lt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=Lt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=Lt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=Lt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!nt(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,i)=>o+i.byteLength,0)),n.length=r,n}};var ko={};bt(ko,{base10:()=>sl});var sl=ye({prefix:"9",name:"base10",alphabet:"0123456789"});var Ko={};bt(Ko,{base16:()=>al,base16upper:()=>cl});var al=et({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),cl=et({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Po={};bt(Po,{base2:()=>ul});var ul=et({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Oo={};bt(Oo,{base256emoji:()=>pl});var Fs=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),fl=Fs.reduce((e,t,r)=>(e[r]=t,e),[]),ll=Fs.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function dl(e){return e.reduce((t,r)=>(t+=fl[r],t),"")}function hl(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=ll[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var pl=Je({prefix:"\u{1F680}",name:"base256emoji",encode:dl,decode:hl});var Mo={};bt(Mo,{base8:()=>ml});var ml=et({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Fo={};bt(Fo,{identity:()=>yl});var yl=Je({prefix:"\0",name:"identity",encode:e=>As(e),decode:e=>Ss(e)});var n0=new TextEncoder,o0=new TextDecoder;var Ho={};bt(Ho,{sha256:()=>Cr,sha512:()=>wl});function qo({name:e,code:t,encode:r}){return new Vo(e,t,r)}var Vo=class{name;code;encode;constructor(t,r,n){this.name=t,this.code=r,this.encode=n}digest(t){if(t instanceof Uint8Array){let r=this.encode(t);return r instanceof Uint8Array?Mt(this.code,r):r.then(n=>Mt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function qs(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var Cr=qo({name:"sha2-256",code:18,encode:qs("SHA-256")}),wl=qo({name:"sha2-512",code:19,encode:qs("SHA-512")});var $o={...Fo,...Po,...Mo,...ko,...Ko,...To,...Do,...Co,..._o,...Oo},y0={...Ho,...No};function $s(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Hs=$s("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),zo=$s("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=vt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),bl={utf8:Hs,"utf-8":Hs,hex:$o.base16,latin1:zo,ascii:zo,binary:zo,...$o},yn=bl;function $(e,t="utf8"){let r=yn[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function z(e,t="utf8"){let r=yn[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var El=parseInt("11111",2),Zo=parseInt("10000000",2),Sl=parseInt("01111111",2),zs={0:Ir,1:Ir,2:Al,3:Tl,4:Cl,5:Bl,6:vl,16:Ir,22:Ir,48:Ir};function Jt(e,t={offset:0}){let r=e[t.offset]&El;if(t.offset++,zs[r]!=null)return zs[r](e,t);throw new Error("No decoder for tag "+r)}function _r(e,t){let r=0;if((e[t.offset]&Zo)===Zo){let n=e[t.offset]&Sl,o="0x";t.offset++;for(let i=0;i<n;i++,t.offset++)o+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=e[t.offset],t.offset++;return r}function Ir(e,t){_r(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Jt(e,t);if(n===null)break;r.push(n)}return r}function Al(e,t){let r=_r(e,t),n=t.offset,o=t.offset+r,i=[];for(let s=n;s<o;s++)s===n&&e[s]===0||i.push(e[s]);return t.offset+=r,Uint8Array.from(i)}function vl(e,t){let r=_r(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let i=0,s=0;o<40?(i=0,s=o):o<80?(i=1,s=o-40):(i=2,s=o-80);let a=`${i}.${s}`,c=[];for(;t.offset<n;){let l=e[t.offset];if(t.offset++,c.push(l&127),l<128){c.reverse();let u=0;for(let d=0;d<c.length;d++)u+=c[d]<<d*7;a+=`.${u}`,c=[]}}return a}function Bl(e,t){return t.offset++,null}function Tl(e,t){let r=_r(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Cl(e,t){let r=_r(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function Il(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new Bt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function Go(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=Il(e.byteLength);return new Bt(Uint8Array.from([t.byteLength|Zo]),t)}function St(e){let t=new Bt,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new Bt(Uint8Array.from([2]),Go(t),t)}function gn(e){let t=Uint8Array.from([0]),r=new Bt(t,e);return new Bt(Uint8Array.from([3]),Go(r),r)}function Ee(e,t=48){let r=new Bt;for(let n of e)r.append(n);return new Bt(Uint8Array.from([t]),Go(r),r)}async function Zs(e,t,r,n){let o=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let i=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,r.subarray());return n?.signal?.throwIfAborted(),i}var _l=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Ul=Uint8Array.from([6,5,43,129,4,0,34]),Dl=Uint8Array.from([6,5,43,129,4,0,35]),Rl={ext:!0,kty:"EC",crv:"P-256"},Ll={ext:!0,kty:"EC",crv:"P-384"},Nl={ext:!0,kty:"EC",crv:"P-521"},Yo=32,jo=48,Xo=66;function Wo(e){let t=Jt(e);return Gs(t)}function Gs(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Yo*2+1)return n=z(t.subarray(r,r+Yo),"base64url"),o=z(t.subarray(r+Yo),"base64url"),new rr({...Rl,key_ops:["verify"],x:n,y:o});if(t.byteLength===jo*2+1)return n=z(t.subarray(r,r+jo),"base64url"),o=z(t.subarray(r+jo),"base64url"),new rr({...Ll,key_ops:["verify"],x:n,y:o});if(t.byteLength===Xo*2+1)return n=z(t.subarray(r,r+Xo),"base64url"),o=z(t.subarray(r+Xo),"base64url"),new rr({...Nl,key_ops:["verify"],x:n,y:o});throw new it(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Ys(e){return Ee([St(Uint8Array.from([1])),Ee([kl(e.crv)],160),Ee([gn(new Bt(Uint8Array.from([4]),$(e.x??"","base64url"),$(e.y??"","base64url")))],161)]).subarray()}function kl(e){if(e==="P-256")return _l;if(e==="P-384")return Ul;if(e==="P-521")return Dl;throw new it(`Invalid curve ${e}`)}var rr=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Ys(this.jwk)),this._raw}toMultihash(){return Ft.digest(Se(this))}toCID(){return Y.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:nt(this.raw,t.raw)}async verify(t,r,n){return Zs(this.jwk,r,t,n)}};var Pe=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function te(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Ur(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function At(e,...t){if(!te(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function xn(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Ur(e.outputLen),Ur(e.blockLen)}function or(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Xs(e,t){At(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function ee(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function wn(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Vt(e,t){return e<<32-t|e>>>t}var Ws=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Kl=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Nt(e){if(At(e),Ws)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Kl[e[r]];return t}var Qt={_0:48,_9:57,A:65,F:70,a:97,f:102};function js(e){if(e>=Qt._0&&e<=Qt._9)return e-Qt._0;if(e>=Qt.A&&e<=Qt.F)return e-(Qt.A-10);if(e>=Qt.a&&e<=Qt.f)return e-(Qt.a-10)}function Oe(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(Ws)return Uint8Array.fromHex(e);let t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,i=0;o<r;o++,i+=2){let s=js(e.charCodeAt(i)),a=js(e.charCodeAt(i+1));if(s===void 0||a===void 0){let c=e[i]+e[i+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+i)}n[o]=s*16+a}return n}function Jo(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function Dr(e){return typeof e=="string"&&(e=Jo(e)),At(e),e}function yt(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];At(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let i=e[n];r.set(i,o),o+=i.length}return r}var nr=class{};function Qo(e){let t=n=>e().update(Dr(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function ir(e=32){if(Pe&&typeof Pe.getRandomValues=="function")return Pe.getRandomValues(new Uint8Array(e));if(Pe&&typeof Pe.randomBytes=="function")return Uint8Array.from(Pe.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function Pl(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let o=BigInt(32),i=BigInt(4294967295),s=Number(r>>o&i),a=Number(r&i),c=n?4:0,l=n?0:4;e.setUint32(t+c,s,n),e.setUint32(t+l,a,n)}function Js(e,t,r){return e&t^~e&r}function Qs(e,t,r){return e&t^e&r^t&r}var Rr=class extends nr{constructor(t,r,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=wn(this.buffer)}update(t){or(this),t=Dr(t),At(t);let{view:r,buffer:n,blockLen:o}=this,i=t.length;for(let s=0;s<i;){let a=Math.min(o-this.pos,i-s);if(a===o){let c=wn(t);for(;o<=i-s;s+=o)this.process(c,s);continue}n.set(t.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){or(this),Xs(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;r[s++]=128,ee(this.buffer.subarray(s)),this.padOffset>o-s&&(this.process(n,0),s=0);for(let d=s;d<o;d++)r[d]=0;Pl(n,o-8,BigInt(this.length*8),i),this.process(n,0);let a=wn(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let l=c/4,u=this.get();if(l>u.length)throw new Error("_sha2: outputLen bigger than state");for(let d=0;d<l;d++)a.setUint32(4*d,u[d],i)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:i,destroyed:s,pos:a}=this;return t.destroyed=s,t.finished=i,t.length=o,t.pos=a,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},re=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ft=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var bn=BigInt(4294967295),ta=BigInt(32);function Ol(e,t=!1){return t?{h:Number(e&bn),l:Number(e>>ta&bn)}:{h:Number(e>>ta&bn)|0,l:Number(e&bn)|0}}function ea(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let i=0;i<r;i++){let{h:s,l:a}=Ol(e[i],t);[n[i],o[i]]=[s,a]}return[n,o]}var ti=(e,t,r)=>e>>>r,ei=(e,t,r)=>e<<32-r|t>>>r,Me=(e,t,r)=>e>>>r|t<<32-r,Fe=(e,t,r)=>e<<32-r|t>>>r,Lr=(e,t,r)=>e<<64-r|t>>>r-32,Nr=(e,t,r)=>e>>>r-32|t<<64-r;function Zt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var ra=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),na=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,oa=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),ia=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,sa=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),aa=(e,t,r,n,o,i)=>t+r+n+o+i+(e/2**32|0)|0;var Fl=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Ae=new Uint32Array(64),En=class extends Rr{constructor(t=32){super(64,t,8,!1),this.A=re[0]|0,this.B=re[1]|0,this.C=re[2]|0,this.D=re[3]|0,this.E=re[4]|0,this.F=re[5]|0,this.G=re[6]|0,this.H=re[7]|0}get(){let{A:t,B:r,C:n,D:o,E:i,F:s,G:a,H:c}=this;return[t,r,n,o,i,s,a,c]}set(t,r,n,o,i,s,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}process(t,r){for(let d=0;d<16;d++,r+=4)Ae[d]=t.getUint32(r,!1);for(let d=16;d<64;d++){let f=Ae[d-15],y=Ae[d-2],p=Vt(f,7)^Vt(f,18)^f>>>3,b=Vt(y,17)^Vt(y,19)^y>>>10;Ae[d]=b+Ae[d-7]+p+Ae[d-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:l,H:u}=this;for(let d=0;d<64;d++){let f=Vt(a,6)^Vt(a,11)^Vt(a,25),y=u+f+Js(a,c,l)+Fl[d]+Ae[d]|0,b=(Vt(n,2)^Vt(n,13)^Vt(n,22))+Qs(n,o,i)|0;u=l,l=c,c=a,a=s+y|0,s=i,i=o,o=n,n=y+b|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,l=l+this.G|0,u=u+this.H|0,this.set(n,o,i,s,a,c,l,u)}roundClean(){ee(Ae)}destroy(){this.set(0,0,0,0,0,0,0,0),ee(this.buffer)}};var ca=ea(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))),Vl=ca[0],ql=ca[1],ve=new Uint32Array(80),Be=new Uint32Array(80),ri=class extends Rr{constructor(t=64){super(128,t,16,!1),this.Ah=ft[0]|0,this.Al=ft[1]|0,this.Bh=ft[2]|0,this.Bl=ft[3]|0,this.Ch=ft[4]|0,this.Cl=ft[5]|0,this.Dh=ft[6]|0,this.Dl=ft[7]|0,this.Eh=ft[8]|0,this.El=ft[9]|0,this.Fh=ft[10]|0,this.Fl=ft[11]|0,this.Gh=ft[12]|0,this.Gl=ft[13]|0,this.Hh=ft[14]|0,this.Hl=ft[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:i,Cl:s,Dh:a,Dl:c,Eh:l,El:u,Fh:d,Fl:f,Gh:y,Gl:p,Hh:b,Hl:T}=this;return[t,r,n,o,i,s,a,c,l,u,d,f,y,p,b,T]}set(t,r,n,o,i,s,a,c,l,u,d,f,y,p,b,T){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=i|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=l|0,this.El=u|0,this.Fh=d|0,this.Fl=f|0,this.Gh=y|0,this.Gl=p|0,this.Hh=b|0,this.Hl=T|0}process(t,r){for(let S=0;S<16;S++,r+=4)ve[S]=t.getUint32(r),Be[S]=t.getUint32(r+=4);for(let S=16;S<80;S++){let N=ve[S-15]|0,P=Be[S-15]|0,M=Me(N,P,1)^Me(N,P,8)^ti(N,P,7),F=Fe(N,P,1)^Fe(N,P,8)^ei(N,P,7),v=ve[S-2]|0,m=Be[S-2]|0,C=Me(v,m,19)^Lr(v,m,61)^ti(v,m,6),I=Fe(v,m,19)^Nr(v,m,61)^ei(v,m,6),B=oa(F,I,Be[S-7],Be[S-16]),x=ia(B,M,C,ve[S-7],ve[S-16]);ve[S]=x|0,Be[S]=B|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:l,Dl:u,Eh:d,El:f,Fh:y,Fl:p,Gh:b,Gl:T,Hh:E,Hl:U}=this;for(let S=0;S<80;S++){let N=Me(d,f,14)^Me(d,f,18)^Lr(d,f,41),P=Fe(d,f,14)^Fe(d,f,18)^Nr(d,f,41),M=d&y^~d&b,F=f&p^~f&T,v=sa(U,P,F,ql[S],Be[S]),m=aa(v,E,N,M,Vl[S],ve[S]),C=v|0,I=Me(n,o,28)^Lr(n,o,34)^Lr(n,o,39),B=Fe(n,o,28)^Nr(n,o,34)^Nr(n,o,39),x=n&i^n&a^i&a,g=o&s^o&c^s&c;E=b|0,U=T|0,b=y|0,T=p|0,y=d|0,p=f|0,{h:d,l:f}=Zt(l|0,u|0,m|0,C|0),l=a|0,u=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let h=ra(C,B,g);n=na(h,m,I,x),o=h|0}({h:n,l:o}=Zt(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=Zt(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=Zt(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:u}=Zt(this.Dh|0,this.Dl|0,l|0,u|0),{h:d,l:f}=Zt(this.Eh|0,this.El|0,d|0,f|0),{h:y,l:p}=Zt(this.Fh|0,this.Fl|0,y|0,p|0),{h:b,l:T}=Zt(this.Gh|0,this.Gl|0,b|0,T|0),{h:E,l:U}=Zt(this.Hh|0,this.Hl|0,E|0,U|0),this.set(n,o,i,s,a,c,l,u,d,f,y,p,b,T,E,U)}roundClean(){ee(ve,Be)}destroy(){ee(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Sn=Qo(()=>new En);var ua=Qo(()=>new ri);var ii=BigInt(0),oi=BigInt(1);function ne(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}"`;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function Tt(e,t,r=""){let n=te(e),o=e?.length,i=t!==void 0;if(!n||i&&o!==t){let s=r&&`"${r}" `,a=i?` of length ${t}`:"",c=n?`length=${o}`:`type=${typeof e}`;throw new Error(s+"expected Uint8Array"+a+", got "+c)}return e}function kr(e){let t=e.toString(16);return t.length&1?"0"+t:t}function fa(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?ii:BigInt("0x"+e)}function sr(e){return fa(Nt(e))}function oe(e){return At(e),fa(Nt(Uint8Array.from(e).reverse()))}function An(e,t){return Oe(e.toString(16).padStart(t*2,"0"))}function si(e,t){return An(e,t).reverse()}function j(e,t,r){let n;if(typeof t=="string")try{n=Oe(t)}catch(i){throw new Error(e+" must be hex string or Uint8Array, cause: "+i)}else if(te(t))n=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");let o=n.length;if(typeof r=="number"&&o!==r)throw new Error(e+" of length "+r+" expected, got "+o);return n}function la(e,t){if(e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}function ai(e){return Uint8Array.from(e)}var ni=e=>typeof e=="bigint"&&ii<=e;function da(e,t,r){return ni(e)&&ni(t)&&ni(r)&&t<=e&&e<r}function Kr(e,t,r,n){if(!da(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function vn(e){let t;for(t=0;e>ii;e>>=oi,t+=1);return t}var Te=e=>(oi<<BigInt(e))-oi;function ha(e,t,r){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=y=>new Uint8Array(y),o=y=>Uint8Array.of(y),i=n(e),s=n(e),a=0,c=()=>{i.fill(1),s.fill(0),a=0},l=(...y)=>r(s,i,...y),u=(y=n(0))=>{s=l(o(0),y),i=l(),y.length!==0&&(s=l(o(1),y),i=l())},d=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let y=0,p=[];for(;y<t;){i=l();let b=i.slice();p.push(b),y+=i.length}return yt(...p)};return(y,p)=>{c(),u(y);let b;for(;!(b=p(d()));)u();return c(),b}}function Ce(e,t,r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(o,i,s){let a=e[o];if(s&&a===void 0)return;let c=typeof a;if(c!==i||a===null)throw new Error(`param "${o}" is invalid: expected ${i}, got ${c}`)}Object.entries(t).forEach(([o,i])=>n(o,i,!1)),Object.entries(r).forEach(([o,i])=>n(o,i,!0))}var ci=()=>{throw new Error("not implemented")};function ar(e){let t=new WeakMap;return(r,...n)=>{let o=t.get(r);if(o!==void 0)return o;let i=e(r,...n);return t.set(r,i),i}}var gt=BigInt(0),at=BigInt(1),Ve=BigInt(2),ya=BigInt(3),ga=BigInt(4),xa=BigInt(5),Hl=BigInt(7),wa=BigInt(8),$l=BigInt(9),ba=BigInt(16);function rt(e,t){let r=e%t;return r>=gt?r:t+r}function W(e,t,r){let n=e;for(;t-- >gt;)n*=n,n%=r;return n}function pa(e,t){if(e===gt)throw new Error("invert: expected non-zero number");if(t<=gt)throw new Error("invert: expected positive modulus, got "+t);let r=rt(e,t),n=t,o=gt,i=at,s=at,a=gt;for(;r!==gt;){let l=n/r,u=n%r,d=o-s*l,f=i-a*l;n=r,r=u,o=s,i=a,s=d,a=f}if(n!==at)throw new Error("invert: does not exist");return rt(o,t)}function ui(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function Ea(e,t){let r=(e.ORDER+at)/ga,n=e.pow(t,r);return ui(e,n,t),n}function zl(e,t){let r=(e.ORDER-xa)/wa,n=e.mul(t,Ve),o=e.pow(n,r),i=e.mul(t,o),s=e.mul(e.mul(i,Ve),o),a=e.mul(i,e.sub(s,e.ONE));return ui(e,a,t),a}function Zl(e){let t=Ct(e),r=Sa(e),n=r(t,t.neg(t.ONE)),o=r(t,n),i=r(t,t.neg(n)),s=(e+Hl)/ba;return(a,c)=>{let l=a.pow(c,s),u=a.mul(l,n),d=a.mul(l,o),f=a.mul(l,i),y=a.eql(a.sqr(u),c),p=a.eql(a.sqr(d),c);l=a.cmov(l,u,y),u=a.cmov(f,d,p);let b=a.eql(a.sqr(u),c),T=a.cmov(l,u,b);return ui(a,T,c),T}}function Sa(e){if(e<ya)throw new Error("sqrt is not defined for small field");let t=e-at,r=0;for(;t%Ve===gt;)t/=Ve,r++;let n=Ve,o=Ct(e);for(;ma(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Ea;let i=o.pow(n,t),s=(t+at)/Ve;return function(c,l){if(c.is0(l))return l;if(ma(c,l)!==1)throw new Error("Cannot find square root");let u=r,d=c.mul(c.ONE,i),f=c.pow(l,t),y=c.pow(l,s);for(;!c.eql(f,c.ONE);){if(c.is0(f))return c.ZERO;let p=1,b=c.sqr(f);for(;!c.eql(b,c.ONE);)if(p++,b=c.sqr(b),p===u)throw new Error("Cannot find square root");let T=at<<BigInt(u-p-1),E=c.pow(d,T);u=p,d=c.sqr(E),f=c.mul(f,d),y=c.mul(y,E)}return y}}function Gl(e){return e%ga===ya?Ea:e%wa===xa?zl:e%ba===$l?Zl(e):Sa(e)}var ie=(e,t)=>(rt(e,t)&at)===at,Yl=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function fi(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=Yl.reduce((n,o)=>(n[o]="function",n),t);return Ce(e,r),e}function jl(e,t,r){if(r<gt)throw new Error("invalid exponent, negatives unsupported");if(r===gt)return e.ONE;if(r===at)return t;let n=e.ONE,o=t;for(;r>gt;)r&at&&(n=e.mul(n,o)),o=e.sqr(o),r>>=at;return n}function Pr(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((s,a,c)=>e.is0(a)?s:(n[c]=s,e.mul(s,a)),e.ONE),i=e.inv(o);return t.reduceRight((s,a,c)=>e.is0(a)?s:(n[c]=e.mul(s,n[c]),e.mul(s,a)),i),n}function ma(e,t){let r=(e.ORDER-at)/Ve,n=e.pow(t,r),o=e.eql(n,e.ONE),i=e.eql(n,e.ZERO),s=e.eql(n,e.neg(e.ONE));if(!o&&!i&&!s)throw new Error("invalid Legendre symbol result");return o?1:i?0:-1}function Bn(e,t){t!==void 0&&Ur(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function Ct(e,t,r=!1,n={}){if(e<=gt)throw new Error("invalid field: expected ORDER > 0, got "+e);let o,i,s=!1,a;if(typeof t=="object"&&t!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let f=t;f.BITS&&(o=f.BITS),f.sqrt&&(i=f.sqrt),typeof f.isLE=="boolean"&&(r=f.isLE),typeof f.modFromBytes=="boolean"&&(s=f.modFromBytes),a=f.allowedLengths}else typeof t=="number"&&(o=t),n.sqrt&&(i=n.sqrt);let{nBitLength:c,nByteLength:l}=Bn(e,o);if(l>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let u,d=Object.freeze({ORDER:e,isLE:r,BITS:c,BYTES:l,MASK:Te(c),ZERO:gt,ONE:at,allowedLengths:a,create:f=>rt(f,e),isValid:f=>{if(typeof f!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof f);return gt<=f&&f<e},is0:f=>f===gt,isValidNot0:f=>!d.is0(f)&&d.isValid(f),isOdd:f=>(f&at)===at,neg:f=>rt(-f,e),eql:(f,y)=>f===y,sqr:f=>rt(f*f,e),add:(f,y)=>rt(f+y,e),sub:(f,y)=>rt(f-y,e),mul:(f,y)=>rt(f*y,e),pow:(f,y)=>jl(d,f,y),div:(f,y)=>rt(f*pa(y,e),e),sqrN:f=>f*f,addN:(f,y)=>f+y,subN:(f,y)=>f-y,mulN:(f,y)=>f*y,inv:f=>pa(f,e),sqrt:i||(f=>(u||(u=Gl(e)),u(d,f))),toBytes:f=>r?si(f,l):An(f,l),fromBytes:(f,y=!0)=>{if(a){if(!a.includes(f.length)||f.length>l)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+f.length);let b=new Uint8Array(l);b.set(f,r?0:b.length-f.length),f=b}if(f.length!==l)throw new Error("Field.fromBytes: expected "+l+" bytes, got "+f.length);let p=r?oe(f):sr(f);if(s&&(p=rt(p,e)),!y&&!d.isValid(p))throw new Error("invalid field element: outside of range 0..ORDER");return p},invertBatch:f=>Pr(d,f),cmov:(f,y,p)=>p?y:f});return Object.freeze(d)}function Aa(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function li(e){let t=Aa(e);return t+Math.ceil(t/2)}function di(e,t,r=!1){let n=e.length,o=Aa(t),i=li(t);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=r?oe(e):sr(e),a=rt(s,t-at)+at;return r?si(a,o):An(a,o)}var cr=BigInt(0),qe=BigInt(1);function Or(e,t){let r=t.negate();return e?r:t}function se(e,t){let r=Pr(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function Ca(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function hi(e,t){Ca(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,i=Te(e),s=BigInt(e);return{windows:r,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function va(e,t,r){let{windowSize:n,mask:o,maxNumber:i,shiftBy:s}=r,a=Number(e&o),c=e>>s;a>n&&(a-=i,c+=qe);let l=t*n,u=l+Math.abs(a)-1,d=a===0,f=a<0,y=t%2!==0;return{nextN:c,offset:u,isZero:d,isNeg:f,isNegF:y,offsetF:l}}function Xl(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function Wl(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((r,n)=>{if(!t.isValid(r))throw new Error("invalid scalar at index "+n)})}var pi=new WeakMap,Ia=new WeakMap;function mi(e){return Ia.get(e)||1}function Ba(e){if(e!==cr)throw new Error("invalid wNAF")}var ur=class{constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let o=t;for(;r>cr;)r&qe&&(n=n.add(o)),o=o.double(),r>>=qe;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=hi(r,this.bits),i=[],s=t,a=s;for(let c=0;c<n;c++){a=s,i.push(a);for(let l=1;l<o;l++)a=a.add(s),i.push(a);s=a.double()}return i}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,i=this.BASE,s=hi(t,this.bits);for(let a=0;a<s.windows;a++){let{nextN:c,offset:l,isZero:u,isNeg:d,isNegF:f,offsetF:y}=va(n,a,s);n=c,u?i=i.add(Or(f,r[y])):o=o.add(Or(d,r[l]))}return Ba(n),{p:o,f:i}}wNAFUnsafe(t,r,n,o=this.ZERO){let i=hi(t,this.bits);for(let s=0;s<i.windows&&n!==cr;s++){let{nextN:a,offset:c,isZero:l,isNeg:u}=va(n,s,i);if(n=a,!l){let d=r[c];o=o.add(u?d.negate():d)}}return Ba(n),o}getPrecomputes(t,r,n){let o=pi.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),pi.set(r,o))),o}cached(t,r,n){let o=mi(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let i=mi(t);return i===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(i,this.getPrecomputes(i,t,n),r,o)}createCache(t,r){Ca(r,this.bits),Ia.set(t,r),pi.delete(t)}hasCache(t){return mi(t)!==1}};function _a(e,t,r,n){let o=t,i=e.ZERO,s=e.ZERO;for(;r>cr||n>cr;)r&qe&&(i=i.add(o)),n&qe&&(s=s.add(o)),o=o.double(),r>>=qe,n>>=qe;return{p1:i,p2:s}}function fr(e,t,r,n){Xl(r,e),Wl(n,t);let o=r.length,i=n.length;if(o!==i)throw new Error("arrays of points and scalars must have equal length");let s=e.ZERO,a=vn(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let l=Te(c),u=new Array(Number(l)+1).fill(s),d=Math.floor((t.BITS-1)/c)*c,f=s;for(let y=d;y>=0;y-=c){u.fill(s);for(let b=0;b<i;b++){let T=n[b],E=Number(T>>BigInt(y)&l);u[E]=u[E].add(r[b])}let p=s;for(let b=u.length-1,T=s;b>0;b--)T=T.add(u[b]),p=p.add(T);if(f=f.add(p),y!==0)for(let b=0;b<c;b++)f=f.double()}return f}function Ta(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return fi(t),t}else return Ct(e,{isLE:r})}function Tn(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let c of["p","n","h"]){let l=t[c];if(!(typeof l=="bigint"&&l>cr))throw new Error(`CURVE.${c} must be positive bigint`)}let o=Ta(t.p,r.Fp,n),i=Ta(t.n,r.Fn,n),a=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:i}}var Ie=BigInt(0),ct=BigInt(1),yi=BigInt(2),Jl=BigInt(8);function Ql(e,t,r,n){let o=e.sqr(r),i=e.sqr(n),s=e.add(e.mul(t.a,o),i),a=e.add(e.ONE,e.mul(t.d,e.mul(o,i)));return e.eql(s,a)}function td(e,t={}){let r=Tn("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r,i=r.CURVE,{h:s}=i;Ce(t,{},{uvRatio:"function"});let a=yi<<BigInt(o.BYTES*8)-ct,c=T=>n.create(T),l=t.uvRatio||((T,E)=>{try{return{isValid:!0,value:n.sqrt(n.div(T,E))}}catch{return{isValid:!1,value:Ie}}});if(!Ql(n,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function u(T,E,U=!1){let S=U?ct:Ie;return Kr("coordinate "+T,E,S,a),E}function d(T){if(!(T instanceof p))throw new Error("ExtendedPoint expected")}let f=ar((T,E)=>{let{X:U,Y:S,Z:N}=T,P=T.is0();E==null&&(E=P?Jl:n.inv(N));let M=c(U*E),F=c(S*E),v=n.mul(N,E);if(P)return{x:Ie,y:ct};if(v!==ct)throw new Error("invZ was invalid");return{x:M,y:F}}),y=ar(T=>{let{a:E,d:U}=i;if(T.is0())throw new Error("bad point: ZERO");let{X:S,Y:N,Z:P,T:M}=T,F=c(S*S),v=c(N*N),m=c(P*P),C=c(m*m),I=c(F*E),B=c(m*c(I+v)),x=c(C+c(U*c(F*v)));if(B!==x)throw new Error("bad point: equation left != right (1)");let g=c(S*N),h=c(P*M);if(g!==h)throw new Error("bad point: equation left != right (2)");return!0});class p{constructor(E,U,S,N){this.X=u("x",E),this.Y=u("y",U),this.Z=u("z",S,!0),this.T=u("t",N),Object.freeze(this)}static CURVE(){return i}static fromAffine(E){if(E instanceof p)throw new Error("extended point not allowed");let{x:U,y:S}=E||{};return u("x",U),u("y",S),new p(U,S,ct,c(U*S))}static fromBytes(E,U=!1){let S=n.BYTES,{a:N,d:P}=i;E=ai(Tt(E,S,"point")),ne(U,"zip215");let M=ai(E),F=E[S-1];M[S-1]=F&-129;let v=oe(M),m=U?a:n.ORDER;Kr("point.y",v,Ie,m);let C=c(v*v),I=c(C-ct),B=c(P*C-N),{isValid:x,value:g}=l(I,B);if(!x)throw new Error("bad point: invalid y coordinate");let h=(g&ct)===ct,A=(F&128)!==0;if(!U&&g===Ie&&A)throw new Error("bad point: x=0 and x_0=1");return A!==h&&(g=c(-g)),p.fromAffine({x:g,y:v})}static fromHex(E,U=!1){return p.fromBytes(j("point",E),U)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(E=8,U=!0){return b.createCache(this,E),U||this.multiply(yi),this}assertValidity(){y(this)}equals(E){d(E);let{X:U,Y:S,Z:N}=this,{X:P,Y:M,Z:F}=E,v=c(U*F),m=c(P*N),C=c(S*F),I=c(M*N);return v===m&&C===I}is0(){return this.equals(p.ZERO)}negate(){return new p(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:E}=i,{X:U,Y:S,Z:N}=this,P=c(U*U),M=c(S*S),F=c(yi*c(N*N)),v=c(E*P),m=U+S,C=c(c(m*m)-P-M),I=v+M,B=I-F,x=v-M,g=c(C*B),h=c(I*x),A=c(C*x),D=c(B*I);return new p(g,h,D,A)}add(E){d(E);let{a:U,d:S}=i,{X:N,Y:P,Z:M,T:F}=this,{X:v,Y:m,Z:C,T:I}=E,B=c(N*v),x=c(P*m),g=c(F*S*I),h=c(M*C),A=c((N+P)*(v+m)-B-x),D=h-g,k=h+g,L=c(x-U*B),K=c(A*D),O=c(k*L),q=c(A*L),J=c(D*k);return new p(K,O,J,q)}subtract(E){return this.add(E.negate())}multiply(E){if(!o.isValidNot0(E))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:U,f:S}=b.cached(this,E,N=>se(p,N));return se(p,[U,S])[0]}multiplyUnsafe(E,U=p.ZERO){if(!o.isValid(E))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return E===Ie?p.ZERO:this.is0()||E===ct?this:b.unsafe(this,E,S=>se(p,S),U)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}isTorsionFree(){return b.unsafe(this,i.n).is0()}toAffine(E){return f(this,E)}clearCofactor(){return s===ct?this:this.multiplyUnsafe(s)}toBytes(){let{x:E,y:U}=this.toAffine(),S=n.toBytes(U);return S[S.length-1]|=E&ct?128:0,S}toHex(){return Nt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(E){return se(p,E)}static msm(E,U){return fr(p,o,E,U)}_setWindowSize(E){this.precompute(E)}toRawBytes(){return this.toBytes()}}p.BASE=new p(i.Gx,i.Gy,ct,c(i.Gx*i.Gy)),p.ZERO=new p(Ie,ct,ct,Ie),p.Fp=n,p.Fn=o;let b=new ur(p,o.BITS);return p.BASE.precompute(8),p}var Cn=class{constructor(t){this.ep=t}static fromBytes(t){ci()}static fromHex(t){ci()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(t){return this.ep.toAffine(t)}toHex(){return Nt(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(t){return this.assertSame(t),this.init(this.ep.add(t.ep))}subtract(t){return this.assertSame(t),this.init(this.ep.subtract(t.ep))}multiply(t){return this.init(this.ep.multiply(t))}multiplyUnsafe(t){return this.init(this.ep.multiplyUnsafe(t))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(t,r){return this.init(this.ep.precompute(t,r))}toRawBytes(){return this.toBytes()}};function ed(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');Ce(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:o,Fp:i,Fn:s}=e,a=r.randomBytes||ir,c=r.adjustScalarBytes||(m=>m),l=r.domain||((m,C,I)=>{if(ne(I,"phflag"),C.length||I)throw new Error("Contexts/pre-hash are not supported");return m});function u(m){return s.create(oe(m))}function d(m){let C=S.secretKey;m=j("private key",m,C);let I=j("hashed private key",t(m),2*C),B=c(I.slice(0,C)),x=I.slice(C,2*C),g=u(B);return{head:B,prefix:x,scalar:g}}function f(m){let{head:C,prefix:I,scalar:B}=d(m),x=o.multiply(B),g=x.toBytes();return{head:C,prefix:I,scalar:B,point:x,pointBytes:g}}function y(m){return f(m).pointBytes}function p(m=Uint8Array.of(),...C){let I=yt(...C);return u(t(l(I,j("context",m),!!n)))}function b(m,C,I={}){m=j("message",m),n&&(m=n(m));let{prefix:B,scalar:x,pointBytes:g}=f(C),h=p(I.context,B,m),A=o.multiply(h).toBytes(),D=p(I.context,A,g,m),k=s.create(h+D*x);if(!s.isValid(k))throw new Error("sign failed: invalid s");let L=yt(A,s.toBytes(k));return Tt(L,S.signature,"result")}let T={zip215:!0};function E(m,C,I,B=T){let{context:x,zip215:g}=B,h=S.signature;m=j("signature",m,h),C=j("message",C),I=j("publicKey",I,S.publicKey),g!==void 0&&ne(g,"zip215"),n&&(C=n(C));let A=h/2,D=m.subarray(0,A),k=oe(m.subarray(A,h)),L,K,O;try{L=e.fromBytes(I,g),K=e.fromBytes(D,g),O=o.multiplyUnsafe(k)}catch{return!1}if(!g&&L.isSmallOrder())return!1;let q=p(x,K.toBytes(),L.toBytes(),C);return K.add(L.multiplyUnsafe(q)).subtract(O).clearCofactor().is0()}let U=i.BYTES,S={secretKey:U,publicKey:U,signature:2*U,seed:U};function N(m=a(S.seed)){return Tt(m,S.seed,"seed")}function P(m){let C=v.randomSecretKey(m);return{secretKey:C,publicKey:y(C)}}function M(m){return te(m)&&m.length===s.BYTES}function F(m,C){try{return!!e.fromBytes(m,C)}catch{return!1}}let v={getExtendedPublicKey:f,randomSecretKey:N,isValidSecretKey:M,isValidPublicKey:F,toMontgomery(m){let{y:C}=e.fromBytes(m),I=S.publicKey,B=I===32;if(!B&&I!==57)throw new Error("only defined for 25519 and 448");let x=B?i.div(ct+C,ct-C):i.div(C-ct,C+ct);return i.toBytes(x)},toMontgomeryPriv(m){let C=S.secretKey;Tt(m,C);let I=t(m.subarray(0,C));return c(I).subarray(0,C)},randomPrivateKey:N,precompute(m=8,C=e.BASE){return C.precompute(m,!1)}};return Object.freeze({keygen:P,getPublicKey:y,sign:b,verify:E,utils:v,Point:e,lengths:S})}function rd(e){let t={a:e.a,d:e.d,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=Ct(t.n,e.nBitLength,!0),o={Fp:r,Fn:n,uvRatio:e.uvRatio},i={randomBytes:e.randomBytes,adjustScalarBytes:e.adjustScalarBytes,domain:e.domain,prehash:e.prehash,mapToCurve:e.mapToCurve};return{CURVE:t,curveOpts:o,hash:e.hash,eddsaOpts:i}}function nd(e,t){let r=t.Point;return Object.assign({},t,{ExtendedPoint:r,CURVE:e,nBitLength:r.Fn.BITS,nByteLength:r.Fn.BYTES})}function Ua(e){let{CURVE:t,curveOpts:r,hash:n,eddsaOpts:o}=rd(e),i=td(t,r),s=ed(i,n,o);return nd(e,s)}var od=BigInt(0),ae=BigInt(1),Da=BigInt(2),vm=BigInt(3),id=BigInt(5),sd=BigInt(8),lr=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Mr={p:lr,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:sd,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function ad(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),i=lr,a=e*e%i*e%i,c=W(a,Da,i)*a%i,l=W(c,ae,i)*e%i,u=W(l,id,i)*l%i,d=W(u,t,i)*u%i,f=W(d,r,i)*d%i,y=W(f,n,i)*f%i,p=W(y,o,i)*y%i,b=W(p,o,i)*y%i,T=W(b,t,i)*u%i;return{pow_p_5_8:W(T,Da,i)*e%i,b2:a}}function cd(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var gi=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function bi(e,t){let r=lr,n=rt(t*t*t,r),o=rt(n*n*t,r),i=ad(e*o).pow_p_5_8,s=rt(e*n*i,r),a=rt(t*s*s,r),c=s,l=rt(s*gi,r),u=a===e,d=a===rt(-e,r),f=a===rt(-e*gi,r);return u&&(s=c),(d||f)&&(s=l),ie(s,r)&&(s=rt(-s,r)),{isValid:u||d,value:s}}var _e=Ct(Mr.p,{isLE:!0}),ud=Ct(Mr.n,{isLE:!0}),fd={...Mr,Fp:_e,hash:ua,adjustScalarBytes:cd,uvRatio:bi},ce=Ua(fd);var xi=gi,ld=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),dd=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),hd=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),pd=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Ra=e=>bi(ae,e),md=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),wi=e=>ce.Point.Fp.create(oe(e)&md);function La(e){let{d:t}=Mr,r=lr,n=E=>_e.create(E),o=n(xi*e*e),i=n((o+ae)*hd),s=BigInt(-1),a=n((s-t*o)*n(o+t)),{isValid:c,value:l}=bi(i,a),u=n(l*e);ie(u,r)||(u=n(-u)),c||(l=u),c||(s=o);let d=n(s*(o-ae)*pd-a),f=l*l,y=n((l+l)*a),p=n(d*ld),b=n(ae-f),T=n(ae+f);return new ce.Point(n(y*T),n(b*p),n(p*T),n(y*b))}function yd(e){At(e,64);let t=wi(e.subarray(0,32)),r=La(t),n=wi(e.subarray(32,64)),o=La(n);return new ue(r.add(o))}var ue=class e extends Cn{constructor(t){super(t)}static fromAffine(t){return new e(ce.Point.fromAffine(t))}assertSame(t){if(!(t instanceof e))throw new Error("RistrettoPoint expected")}init(t){return new e(t)}static hashToCurve(t){return yd(j("ristrettoHash",t,64))}static fromBytes(t){At(t,32);let{a:r,d:n}=Mr,o=lr,i=N=>_e.create(N),s=wi(t);if(!la(_e.toBytes(s),t)||ie(s,o))throw new Error("invalid ristretto255 encoding 1");let a=i(s*s),c=i(ae+r*a),l=i(ae-r*a),u=i(c*c),d=i(l*l),f=i(r*n*u-d),{isValid:y,value:p}=Ra(i(f*d)),b=i(p*l),T=i(p*b*f),E=i((s+s)*b);ie(E,o)&&(E=i(-E));let U=i(c*T),S=i(E*U);if(!y||ie(S,o)||U===od)throw new Error("invalid ristretto255 encoding 2");return new e(new ce.Point(E,U,ae,S))}static fromHex(t){return e.fromBytes(j("ristrettoHex",t,32))}static msm(t,r){return fr(e,ce.Point.Fn,t,r)}toBytes(){let{X:t,Y:r,Z:n,T:o}=this.ep,i=lr,s=T=>_e.create(T),a=s(s(n+r)*s(n-r)),c=s(t*r),l=s(c*c),{value:u}=Ra(s(a*l)),d=s(u*a),f=s(u*c),y=s(d*f*o),p;if(ie(o*y,i)){let T=s(r*xi),E=s(t*xi);t=T,r=E,p=s(d*dd)}else p=f;ie(t*y,i)&&(r=s(-r));let b=s((n-r)*p);return ie(b,i)&&(b=s(-b)),_e.toBytes(b)}equals(t){this.assertSame(t);let{X:r,Y:n}=this.ep,{X:o,Y:i}=t.ep,s=l=>_e.create(l),a=s(r*i)===s(n*o),c=s(n*i)===s(r*o);return a||c}is0(){return this.equals(e.ZERO)}};ue.BASE=new ue(ce.Point.BASE);ue.ZERO=new ue(ce.Point.ZERO);ue.Fp=_e;ue.Fn=ud;var Fr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},In=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Na={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new In("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var kt=Na;var _n=32;var Ei,gd=(async()=>{try{return await kt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function xd(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await kt.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await kt.get().subtle.verify({name:"Ed25519"},n,t,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function wd(e,t,r){return ce.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function ka(e,t,r){return Ei==null&&(Ei=await gd),Ei?xd(e,t,r):wd(e,t,r)}function Un(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var Dn=class{type="Ed25519";raw;constructor(t){this.raw=Si(t,_n)}toMultihash(){return Ft.digest(Se(this))}toCID(){return Y.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:nt(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=ka(this.raw,r,t);return Un(o)?o.then(i=>(n?.signal?.throwIfAborted(),i)):o}};function Ai(e){return e=Si(e,_n),new Dn(e)}function Si(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new it(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var Ed=Math.pow(2,7),Sd=Math.pow(2,14),Ad=Math.pow(2,21),Pa=Math.pow(2,28),Oa=Math.pow(2,35),Ma=Math.pow(2,42),Fa=Math.pow(2,49),xt=128,Ue=127;function Vr(e){if(e<Ed)return 1;if(e<Sd)return 2;if(e<Ad)return 3;if(e<Pa)return 4;if(e<Oa)return 5;if(e<Ma)return 6;if(e<Fa)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Va(e,t,r=0){switch(Vr(e)){case 8:t[r++]=e&255|xt,e/=128;case 7:t[r++]=e&255|xt,e/=128;case 6:t[r++]=e&255|xt,e/=128;case 5:t[r++]=e&255|xt,e/=128;case 4:t[r++]=e&255|xt,e>>>=7;case 3:t[r++]=e&255|xt,e>>>=7;case 2:t[r++]=e&255|xt,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function qa(e,t){let r=e[t],n=0;if(n+=r&Ue,r<xt||(r=e[t+1],n+=(r&Ue)<<7,r<xt)||(r=e[t+2],n+=(r&Ue)<<14,r<xt)||(r=e[t+3],n+=(r&Ue)<<21,r<xt)||(r=e[t+4],n+=(r&Ue)*Pa,r<xt)||(r=e[t+5],n+=(r&Ue)*Oa,r<xt)||(r=e[t+6],n+=(r&Ue)*Ma,r<xt)||(r=e[t+7],n+=(r&Ue)*Fa,r<xt))return n;throw new RangeError("Could not decode varint")}var vi=new Float32Array([-0]),De=new Uint8Array(vi.buffer);function Ha(e,t,r){vi[0]=e,t[r]=De[0],t[r+1]=De[1],t[r+2]=De[2],t[r+3]=De[3]}function $a(e,t){return De[0]=e[t],De[1]=e[t+1],De[2]=e[t+2],De[3]=e[t+3],vi[0]}var Bi=new Float64Array([-0]),pt=new Uint8Array(Bi.buffer);function za(e,t,r){Bi[0]=e,t[r]=pt[0],t[r+1]=pt[1],t[r+2]=pt[2],t[r+3]=pt[3],t[r+4]=pt[4],t[r+5]=pt[5],t[r+6]=pt[6],t[r+7]=pt[7]}function Za(e,t){return pt[0]=e[t],pt[1]=e[t+1],pt[2]=e[t+2],pt[3]=e[t+3],pt[4]=e[t+4],pt[5]=e[t+5],pt[6]=e[t+6],pt[7]=e[t+7],Bi[0]}var vd=BigInt(Number.MAX_SAFE_INTEGER),Bd=BigInt(Number.MIN_SAFE_INTEGER),It=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return He;if(t<vd&&t>Bd)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,o=t-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>Ga&&(o=0n,++n>Ga&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return He;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):He}},He=new It(0,0);He.toBigInt=function(){return 0n};He.zzEncode=He.zzDecode=function(){return this};He.length=function(){return 1};var Ga=4294967296n;function Ya(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function ja(e,t,r){if(r-t<1)return"";let o,i=[],s=0,a;for(;t<r;)a=e[t++],a<128?i[s++]=a:a>191&&a<224?i[s++]=(a&31)<<6|e[t++]&63:a>239&&a<365?(a=((a&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,i[s++]=55296+(a>>10),i[s++]=56320+(a&1023)):i[s++]=(a&15)<<12|(e[t++]&63)<<6|e[t++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function Ti(e,t,r){let n=r,o,i;for(let s=0;s<e.length;++s)o=e.charCodeAt(s),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((i=e.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function qt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function Rn(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var Ci=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,qt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw qt(this,4);return Rn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw qt(this,4);return Rn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw qt(this,4);let t=$a(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw qt(this,4);let t=Za(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw qt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return ja(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw qt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw qt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new It(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw qt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw qt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw qt(this,8);let t=Rn(this.buf,this.pos+=4),r=Rn(this.buf,this.pos+=4);return new It(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=qa(this.buf,this.pos);return this.pos+=Vr(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Ii(e){return new Ci(e instanceof Uint8Array?e:e.subarray())}function Re(e,t,r){let n=Ii(e);return t.decode(n,void 0,r)}function _i(e){let t=e??8192,r=t>>>1,n,o=t;return function(s){if(s<1||s>r)return vt(s);o+s>t&&(n=vt(t),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var $e=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function Ui(){}var Ri=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Td=_i();function Cd(e){return globalThis.Buffer!=null?vt(e):Td(e)}var Hr=class{len;head;tail;states;constructor(){this.len=0,this.head=new $e(Ui,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new $e(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Li((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(Ln,10,It.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=It.fromBigInt(t);return this._push(Ln,r.length(),r)}uint64Number(t){return this._push(Va,Vr(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=It.fromBigInt(t).zzEncode();return this._push(Ln,r.length(),r)}sint64Number(t){let r=It.fromNumber(t).zzEncode();return this._push(Ln,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Di,1,t?1:0)}fixed32(t){return this._push(qr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=It.fromBigInt(t);return this._push(qr,4,r.lo)._push(qr,4,r.hi)}fixed64Number(t){let r=It.fromNumber(t);return this._push(qr,4,r.lo)._push(qr,4,r.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Ha,4,t)}double(t){return this._push(za,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Di,1,0):this.uint32(r)._push(_d,r,t)}string(t){let r=Ya(t);return r!==0?this.uint32(r)._push(Ti,r,t):this._push(Di,1,0)}fork(){return this.states=new Ri(this),this.head=this.tail=new $e(Ui,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new $e(Ui,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=Cd(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Di(e,t,r){t[r]=e&255}function Id(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Li=class extends $e{next;constructor(t,r){super(Id,t,r),this.next=void 0}};function Ln(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function qr(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function _d(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(Hr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(Ud,t,e),this},Hr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Dd,t,e),this});function Ud(e,t,r){t.set(e,r)}function Dd(e,t,r){e.length<40?Ti(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set($(e),r)}function Ni(){return new Hr}function Le(e,t){let r=Ni();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var dr;(function(e){e[e.VARINT=0]="VARINT",e[e.BIT64=1]="BIT64",e[e.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",e[e.START_GROUP=3]="START_GROUP",e[e.END_GROUP=4]="END_GROUP",e[e.BIT32=5]="BIT32"})(dr||(dr={}));function Nn(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function $r(e){function t(o){if(e[o.toString()]==null)throw new Error("Invalid enum value");return e[o]}let r=function(i,s){let a=t(i);s.int32(a)},n=function(i){let s=i.int32();return t(s)};return Nn("enum",dr.VARINT,r,n)}function Ne(e,t){return Nn("message",dr.LENGTH_DELIMITED,e,t)}var ot;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(ot||(ot={}));var ki;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(ki||(ki={}));(function(e){e.codec=()=>$r(ki)})(ot||(ot={}));var Gt;(function(e){let t;e.codec=()=>(t==null&&(t=Ne((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),ot.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let i={},s=n==null?r.len:r.pos+n;for(;r.pos<s;){let a=r.uint32();switch(a>>>3){case 1:{i.Type=ot.codec().decode(r);break}case 2:{i.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return i})),t),e.encode=r=>Le(r,e.codec()),e.decode=(r,n)=>Re(r,e.codec(),n)})(Gt||(Gt={}));var Ki;(function(e){let t;e.codec=()=>(t==null&&(t=Ne((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),ot.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let i={},s=n==null?r.len:r.pos+n;for(;r.pos<s;){let a=r.uint32();switch(a>>>3){case 1:{i.Type=ot.codec().decode(r);break}case 2:{i.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return i})),t),e.encode=r=>Le(r,e.codec()),e.decode=(r,n)=>Re(r,e.codec(),n)})(Ki||(Ki={}));var Zr={};bt(Zr,{MAX_RSA_KEY_SIZE:()=>Pi,generateRSAKeyPair:()=>ec,jwkToJWKKeyPair:()=>rc,jwkToPkcs1:()=>kd,jwkToPkix:()=>Vi,jwkToRSAPrivateKey:()=>zi,pkcs1MessageToJwk:()=>Mi,pkcs1MessageToRSAPrivateKey:()=>qi,pkcs1ToJwk:()=>Nd,pkcs1ToRSAPrivateKey:()=>tc,pkixMessageToJwk:()=>Fi,pkixMessageToRSAPublicKey:()=>$i,pkixToJwk:()=>Kd,pkixToRSAPublicKey:()=>Hi});var kn=Sn;var hr=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Zr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return Y.createV1(114,this._multihash)}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:nt(this.raw,t.raw)}verify(t,r,n){return Qa(this.jwk,r,t,n)}},zr=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Zr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:nt(this.raw,t.raw)}sign(t,r){return Ja(this.jwk,t,r)}};var Pi=8192,Oi=18,Rd=1062,Ld=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Nd(e){let t=Jt(e);return Mi(t)}function Mi(e){return{n:z(e[1],"base64url"),e:z(e[2],"base64url"),d:z(e[3],"base64url"),p:z(e[4],"base64url"),q:z(e[5],"base64url"),dp:z(e[6],"base64url"),dq:z(e[7],"base64url"),qi:z(e[8],"base64url"),kty:"RSA"}}function kd(e){if(e.n==null||e.e==null||e.d==null||e.p==null||e.q==null||e.dp==null||e.dq==null||e.qi==null)throw new it("JWK was missing components");return Ee([St(Uint8Array.from([0])),St($(e.n,"base64url")),St($(e.e,"base64url")),St($(e.d,"base64url")),St($(e.p,"base64url")),St($(e.q,"base64url")),St($(e.dp,"base64url")),St($(e.dq,"base64url")),St($(e.qi,"base64url"))]).subarray()}function Kd(e){let t=Jt(e,{offset:0});return Fi(t)}function Fi(e){let t=Jt(e[1],{offset:0});return{kty:"RSA",n:z(t[0],"base64url"),e:z(t[1],"base64url")}}function Vi(e){if(e.n==null||e.e==null)throw new it("JWK was missing components");return Ee([Ld,gn(Ee([St($(e.n,"base64url")),St($(e.e,"base64url"))]))]).subarray()}function tc(e){let t=Jt(e);return qi(t)}function qi(e){let t=Mi(e);return zi(t)}function Hi(e,t){if(e.byteLength>=Rd)throw new je("Key size is too large");let r=Jt(e,{offset:0});return $i(r,e,t)}function $i(e,t,r){let n=Fi(e);if(r==null){let o=kn(Gt.encode({Type:ot.RSA,Data:t}));r=Mt(Oi,o)}return new hr(n,r)}function zi(e){if(oc(e)>Pi)throw new it("Key size is too large");let t=rc(e),r=kn(Gt.encode({Type:ot.RSA,Data:Vi(t.publicKey)})),n=Mt(Oi,r);return new zr(t.privateKey,new hr(t.publicKey,n))}async function ec(e){if(e>Pi)throw new it("Key size is too large");let t=await nc(e),r=kn(Gt.encode({Type:ot.RSA,Data:Vi(t.publicKey)})),n=Mt(Oi,r);return new zr(t.privateKey,new hr(t.publicKey,n))}function rc(e){if(e==null)throw new it("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function nc(e,t){let r=await kt.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await Pd(r,t);return{privateKey:n[0],publicKey:n[1]}}async function Ja(e,t,r){let n=await kt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await kt.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Qa(e,t,r,n){let o=await kt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let i=await kt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),i}async function Pd(e,t){if(e.privateKey==null||e.publicKey==null)throw new it("Private and public key are required");let r=await Promise.all([kt.get().subtle.exportKey("jwk",e.privateKey),kt.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function oc(e){if(e.kty!=="RSA")throw new it("invalid key type");if(e.n==null)throw new it("invalid key modulus");return $(e.n,"base64url").length*8}var Kn=class extends nr{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,xn(t);let n=Dr(r);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,i=new Uint8Array(o);i.set(n.length>o?t.create().update(n).digest():n);for(let s=0;s<i.length;s++)i[s]^=54;this.iHash.update(i),this.oHash=t.create();for(let s=0;s<i.length;s++)i[s]^=106;this.oHash.update(i),ee(i)}update(t){return or(this),this.iHash.update(t),this}digestInto(t){or(this),At(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:o,destroyed:i,blockLen:s,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=i,t.blockLen=s,t.outputLen=a,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Zi=(e,t,r)=>new Kn(e,t).update(r).digest();Zi.create=(e,t)=>new Kn(e,t);var ic=(e,t)=>(e+(e>=0?t:-t)/sc)/t;function Od(e,t,r){let[[n,o],[i,s]]=t,a=ic(s*e,r),c=ic(-o*e,r),l=e-a*n-c*i,u=-a*o-c*s,d=l<le,f=u<le;d&&(l=-l),f&&(u=-u);let y=Te(Math.ceil(vn(r)/2))+mr;if(l<le||l>=y||u<le||u>=y)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:d,k1:l,k2neg:f,k2:u}}function Yi(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Gi(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return ne(r.lowS,"lowS"),ne(r.prehash,"prehash"),r.format!==void 0&&Yi(r.format),r}var ji=class extends Error{constructor(t=""){super(t)}},fe={Err:ji,_tlv:{encode:(e,t)=>{let{Err:r}=fe;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=kr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let i=n>127?kr(o.length/2|128):"";return kr(e)+i+o+t},decode(e,t){let{Err:r}=fe,n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],i=!!(o&128),s=0;if(!i)s=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let l=t.subarray(n,n+c);if(l.length!==c)throw new r("tlv.decode: length bytes not complete");if(l[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let u of l)s=s<<8|u;if(n+=c,s<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+s);if(a.length!==s)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+s)}}},_int:{encode(e){let{Err:t}=fe;if(e<le)throw new t("integer: negative integers are not allowed");let r=kr(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=fe;if(e[0]&128)throw new t("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return sr(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=fe,o=j("signature",e),{v:i,l:s}=n.decode(48,o);if(s.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,i),{v:l,l:u}=n.decode(2,c);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(l)}},hexFromSig(e){let{_tlv:t,_int:r}=fe,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),i=n+o;return t.encode(48,i)}},le=BigInt(0),mr=BigInt(1),sc=BigInt(2),Pn=BigInt(3),Md=BigInt(4);function pr(e,t){let{BYTES:r}=e,n;if(typeof t=="bigint")n=t;else{let o=j("private key",t);try{n=e.fromBytes(o)}catch{throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof t}`)}}if(!e.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function Fd(e,t={}){let r=Tn("weierstrass",e,t),{Fp:n,Fn:o}=r,i=r.CURVE,{h:s,n:a}=i;Ce(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:c}=t;if(c&&(!n.is0(i.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let l=cc(n,o);function u(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function d(B,x,g){let{x:h,y:A}=x.toAffine(),D=n.toBytes(h);if(ne(g,"isCompressed"),g){u();let k=!n.isOdd(A);return yt(ac(k),D)}else return yt(Uint8Array.of(4),D,n.toBytes(A))}function f(B){Tt(B,void 0,"Point");let{publicKey:x,publicKeyUncompressed:g}=l,h=B.length,A=B[0],D=B.subarray(1);if(h===x&&(A===2||A===3)){let k=n.fromBytes(D);if(!n.isValid(k))throw new Error("bad point: is not on curve, wrong x");let L=b(k),K;try{K=n.sqrt(L)}catch(J){let X=J instanceof Error?": "+J.message:"";throw new Error("bad point: is not on curve, sqrt error"+X)}u();let O=n.isOdd(K);return(A&1)===1!==O&&(K=n.neg(K)),{x:k,y:K}}else if(h===g&&A===4){let k=n.BYTES,L=n.fromBytes(D.subarray(0,k)),K=n.fromBytes(D.subarray(k,k*2));if(!T(L,K))throw new Error("bad point: is not on curve");return{x:L,y:K}}else throw new Error(`bad point: got length ${h}, expected compressed=${x} or uncompressed=${g}`)}let y=t.toBytes||d,p=t.fromBytes||f;function b(B){let x=n.sqr(B),g=n.mul(x,B);return n.add(n.add(g,n.mul(B,i.a)),i.b)}function T(B,x){let g=n.sqr(x),h=b(B);return n.eql(g,h)}if(!T(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let E=n.mul(n.pow(i.a,Pn),Md),U=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(E,U)))throw new Error("bad curve params: a or b");function S(B,x,g=!1){if(!n.isValid(x)||g&&n.is0(x))throw new Error(`bad point coordinate ${B}`);return x}function N(B){if(!(B instanceof m))throw new Error("ProjectivePoint expected")}function P(B){if(!c||!c.basises)throw new Error("no endo");return Od(B,c.basises,o.ORDER)}let M=ar((B,x)=>{let{X:g,Y:h,Z:A}=B;if(n.eql(A,n.ONE))return{x:g,y:h};let D=B.is0();x==null&&(x=D?n.ONE:n.inv(A));let k=n.mul(g,x),L=n.mul(h,x),K=n.mul(A,x);if(D)return{x:n.ZERO,y:n.ZERO};if(!n.eql(K,n.ONE))throw new Error("invZ was invalid");return{x:k,y:L}}),F=ar(B=>{if(B.is0()){if(t.allowInfinityPoint&&!n.is0(B.Y))return;throw new Error("bad point: ZERO")}let{x,y:g}=B.toAffine();if(!n.isValid(x)||!n.isValid(g))throw new Error("bad point: x or y not field elements");if(!T(x,g))throw new Error("bad point: equation left != right");if(!B.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function v(B,x,g,h,A){return g=new m(n.mul(g.X,B),g.Y,g.Z),x=Or(h,x),g=Or(A,g),x.add(g)}class m{constructor(x,g,h){this.X=S("x",x),this.Y=S("y",g,!0),this.Z=S("z",h),Object.freeze(this)}static CURVE(){return i}static fromAffine(x){let{x:g,y:h}=x||{};if(!x||!n.isValid(g)||!n.isValid(h))throw new Error("invalid affine point");if(x instanceof m)throw new Error("projective point not allowed");return n.is0(g)&&n.is0(h)?m.ZERO:new m(g,h,n.ONE)}static fromBytes(x){let g=m.fromAffine(p(Tt(x,void 0,"point")));return g.assertValidity(),g}static fromHex(x){return m.fromBytes(j("pointHex",x))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(x=8,g=!0){return I.createCache(this,x),g||this.multiply(Pn),this}assertValidity(){F(this)}hasEvenY(){let{y:x}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(x)}equals(x){N(x);let{X:g,Y:h,Z:A}=this,{X:D,Y:k,Z:L}=x,K=n.eql(n.mul(g,L),n.mul(D,A)),O=n.eql(n.mul(h,L),n.mul(k,A));return K&&O}negate(){return new m(this.X,n.neg(this.Y),this.Z)}double(){let{a:x,b:g}=i,h=n.mul(g,Pn),{X:A,Y:D,Z:k}=this,L=n.ZERO,K=n.ZERO,O=n.ZERO,q=n.mul(A,A),J=n.mul(D,D),X=n.mul(k,k),H=n.mul(A,D);return H=n.add(H,H),O=n.mul(A,k),O=n.add(O,O),L=n.mul(x,O),K=n.mul(h,X),K=n.add(L,K),L=n.sub(J,K),K=n.add(J,K),K=n.mul(L,K),L=n.mul(H,L),O=n.mul(h,O),X=n.mul(x,X),H=n.sub(q,X),H=n.mul(x,H),H=n.add(H,O),O=n.add(q,q),q=n.add(O,q),q=n.add(q,X),q=n.mul(q,H),K=n.add(K,q),X=n.mul(D,k),X=n.add(X,X),q=n.mul(X,H),L=n.sub(L,q),O=n.mul(X,J),O=n.add(O,O),O=n.add(O,O),new m(L,K,O)}add(x){N(x);let{X:g,Y:h,Z:A}=this,{X:D,Y:k,Z:L}=x,K=n.ZERO,O=n.ZERO,q=n.ZERO,J=i.a,X=n.mul(i.b,Pn),H=n.mul(g,D),Q=n.mul(h,k),st=n.mul(A,L),wt=n.add(g,h),tt=n.add(D,k);wt=n.mul(wt,tt),tt=n.add(H,Q),wt=n.sub(wt,tt),tt=n.add(g,A);let ht=n.add(D,L);return tt=n.mul(tt,ht),ht=n.add(H,st),tt=n.sub(tt,ht),ht=n.add(h,A),K=n.add(k,L),ht=n.mul(ht,K),K=n.add(Q,st),ht=n.sub(ht,K),q=n.mul(J,tt),K=n.mul(X,st),q=n.add(K,q),K=n.sub(Q,q),q=n.add(Q,q),O=n.mul(K,q),Q=n.add(H,H),Q=n.add(Q,H),st=n.mul(J,st),tt=n.mul(X,tt),Q=n.add(Q,st),st=n.sub(H,st),st=n.mul(J,st),tt=n.add(tt,st),H=n.mul(Q,tt),O=n.add(O,H),H=n.mul(ht,tt),K=n.mul(wt,K),K=n.sub(K,H),H=n.mul(wt,Q),q=n.mul(ht,q),q=n.add(q,H),new m(K,O,q)}subtract(x){return this.add(x.negate())}is0(){return this.equals(m.ZERO)}multiply(x){let{endo:g}=t;if(!o.isValidNot0(x))throw new Error("invalid scalar: out of range");let h,A,D=k=>I.cached(this,k,L=>se(m,L));if(g){let{k1neg:k,k1:L,k2neg:K,k2:O}=P(x),{p:q,f:J}=D(L),{p:X,f:H}=D(O);A=J.add(H),h=v(g.beta,q,X,k,K)}else{let{p:k,f:L}=D(x);h=k,A=L}return se(m,[h,A])[0]}multiplyUnsafe(x){let{endo:g}=t,h=this;if(!o.isValid(x))throw new Error("invalid scalar: out of range");if(x===le||h.is0())return m.ZERO;if(x===mr)return h;if(I.hasCache(this))return this.multiply(x);if(g){let{k1neg:A,k1:D,k2neg:k,k2:L}=P(x),{p1:K,p2:O}=_a(m,h,D,L);return v(g.beta,K,O,A,k)}else return I.unsafe(h,x)}multiplyAndAddUnsafe(x,g,h){let A=this.multiplyUnsafe(g).add(x.multiplyUnsafe(h));return A.is0()?void 0:A}toAffine(x){return M(this,x)}isTorsionFree(){let{isTorsionFree:x}=t;return s===mr?!0:x?x(m,this):I.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:x}=t;return s===mr?this:x?x(m,this):this.multiplyUnsafe(s)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}toBytes(x=!0){return ne(x,"isCompressed"),this.assertValidity(),y(m,this,x)}toHex(x=!0){return Nt(this.toBytes(x))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(x=!0){return this.toBytes(x)}_setWindowSize(x){this.precompute(x)}static normalizeZ(x){return se(m,x)}static msm(x,g){return fr(m,o,x,g)}static fromPrivateKey(x){return m.BASE.multiply(pr(o,x))}}m.BASE=new m(i.Gx,i.Gy,n.ONE),m.ZERO=new m(n.ZERO,n.ONE,n.ZERO),m.Fp=n,m.Fn=o;let C=o.BITS,I=new ur(m,t.endo?Math.ceil(C/2):C);return m.BASE.precompute(8),m}function ac(e){return Uint8Array.of(e?2:3)}function cc(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Vd(e,t={}){let{Fn:r}=e,n=t.randomBytes||ir,o=Object.assign(cc(e.Fp,r),{seed:li(r.ORDER)});function i(y){try{return!!pr(r,y)}catch{return!1}}function s(y,p){let{publicKey:b,publicKeyUncompressed:T}=o;try{let E=y.length;return p===!0&&E!==b||p===!1&&E!==T?!1:!!e.fromBytes(y)}catch{return!1}}function a(y=n(o.seed)){return di(Tt(y,o.seed,"seed"),r.ORDER)}function c(y,p=!0){return e.BASE.multiply(pr(r,y)).toBytes(p)}function l(y){let p=a(y);return{secretKey:p,publicKey:c(p)}}function u(y){if(typeof y=="bigint")return!1;if(y instanceof e)return!0;let{secretKey:p,publicKey:b,publicKeyUncompressed:T}=o;if(r.allowedLengths||p===b)return;let E=j("key",y).length;return E===b||E===T}function d(y,p,b=!0){if(u(y)===!0)throw new Error("first arg must be private key");if(u(p)===!1)throw new Error("second arg must be public key");let T=pr(r,y);return e.fromHex(p).multiply(T).toBytes(b)}return Object.freeze({getPublicKey:c,getSharedSecret:d,keygen:l,Point:e,utils:{isValidSecretKey:i,isValidPublicKey:s,randomSecretKey:a,isValidPrivateKey:i,randomPrivateKey:a,normPrivateKeyToScalar:y=>pr(r,y),precompute(y=8,p=e.BASE){return p.precompute(y,!1)}},lengths:o})}function qd(e,t,r={}){xn(t),Ce(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=r.randomBytes||ir,o=r.hmac||((g,...h)=>Zi(t,g,yt(...h))),{Fp:i,Fn:s}=e,{ORDER:a,BITS:c}=s,{keygen:l,getPublicKey:u,getSharedSecret:d,utils:f,lengths:y}=Vd(e,r),p={prehash:!1,lowS:typeof r.lowS=="boolean"?r.lowS:!1,format:void 0,extraEntropy:!1},b="compact";function T(g){let h=a>>mr;return g>h}function E(g,h){if(!s.isValidNot0(h))throw new Error(`invalid signature ${g}: out of range 1..Point.Fn.ORDER`);return h}function U(g,h){Yi(h);let A=y.signature,D=h==="compact"?A:h==="recovered"?A+1:void 0;return Tt(g,D,`${h} signature`)}class S{constructor(h,A,D){this.r=E("r",h),this.s=E("s",A),D!=null&&(this.recovery=D),Object.freeze(this)}static fromBytes(h,A=b){U(h,A);let D;if(A==="der"){let{r:O,s:q}=fe.toSig(Tt(h));return new S(O,q)}A==="recovered"&&(D=h[0],A="compact",h=h.subarray(1));let k=s.BYTES,L=h.subarray(0,k),K=h.subarray(k,k*2);return new S(s.fromBytes(L),s.fromBytes(K),D)}static fromHex(h,A){return this.fromBytes(Oe(h),A)}addRecoveryBit(h){return new S(this.r,this.s,h)}recoverPublicKey(h){let A=i.ORDER,{r:D,s:k,recovery:L}=this;if(L==null||![0,1,2,3].includes(L))throw new Error("recovery id invalid");if(a*sc<A&&L>1)throw new Error("recovery id is ambiguous for h>1 curve");let O=L===2||L===3?D+a:D;if(!i.isValid(O))throw new Error("recovery id 2 or 3 invalid");let q=i.toBytes(O),J=e.fromBytes(yt(ac((L&1)===0),q)),X=s.inv(O),H=P(j("msgHash",h)),Q=s.create(-H*X),st=s.create(k*X),wt=e.BASE.multiplyUnsafe(Q).add(J.multiplyUnsafe(st));if(wt.is0())throw new Error("point at infinify");return wt.assertValidity(),wt}hasHighS(){return T(this.s)}toBytes(h=b){if(Yi(h),h==="der")return Oe(fe.hexFromSig(this));let A=s.toBytes(this.r),D=s.toBytes(this.s);if(h==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return yt(Uint8Array.of(this.recovery),A,D)}return yt(A,D)}toHex(h){return Nt(this.toBytes(h))}assertValidity(){}static fromCompact(h){return S.fromBytes(j("sig",h),"compact")}static fromDER(h){return S.fromBytes(j("sig",h),"der")}normalizeS(){return this.hasHighS()?new S(this.r,s.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return Nt(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return Nt(this.toBytes("compact"))}}let N=r.bits2int||function(h){if(h.length>8192)throw new Error("input is too large");let A=sr(h),D=h.length*8-c;return D>0?A>>BigInt(D):A},P=r.bits2int_modN||function(h){return s.create(N(h))},M=Te(c);function F(g){return Kr("num < 2^"+c,g,le,M),s.toBytes(g)}function v(g,h){return Tt(g,void 0,"message"),h?Tt(t(g),void 0,"prehashed message"):g}function m(g,h,A){if(["recovered","canonical"].some(Q=>Q in A))throw new Error("sign() legacy options not supported");let{lowS:D,prehash:k,extraEntropy:L}=Gi(A,p);g=v(g,k);let K=P(g),O=pr(s,h),q=[F(O),F(K)];if(L!=null&&L!==!1){let Q=L===!0?n(y.secretKey):L;q.push(j("extraEntropy",Q))}let J=yt(...q),X=K;function H(Q){let st=N(Q);if(!s.isValidNot0(st))return;let wt=s.inv(st),tt=e.BASE.multiply(st).toAffine(),ht=s.create(tt.x);if(ht===le)return;let an=s.create(wt*s.create(X+ht*O));if(an===le)return;let ys=(tt.x===ht?0:2)|Number(tt.y&mr),gs=an;return D&&T(an)&&(gs=s.neg(an),ys^=1),new S(ht,gs,ys)}return{seed:J,k2sig:H}}function C(g,h,A={}){g=j("message",g);let{seed:D,k2sig:k}=m(g,h,A);return ha(t.outputLen,s.BYTES,o)(D,k)}function I(g){let h,A=typeof g=="string"||te(g),D=!A&&g!==null&&typeof g=="object"&&typeof g.r=="bigint"&&typeof g.s=="bigint";if(!A&&!D)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(D)h=new S(g.r,g.s);else if(A){try{h=S.fromBytes(j("sig",g),"der")}catch(k){if(!(k instanceof fe.Err))throw k}if(!h)try{h=S.fromBytes(j("sig",g),"compact")}catch{return!1}}return h||!1}function B(g,h,A,D={}){let{lowS:k,prehash:L,format:K}=Gi(D,p);if(A=j("publicKey",A),h=v(j("message",h),L),"strict"in D)throw new Error("options.strict was renamed to lowS");let O=K===void 0?I(g):S.fromBytes(j("sig",g),K);if(O===!1)return!1;try{let q=e.fromBytes(A);if(k&&O.hasHighS())return!1;let{r:J,s:X}=O,H=P(h),Q=s.inv(X),st=s.create(H*Q),wt=s.create(J*Q),tt=e.BASE.multiplyUnsafe(st).add(q.multiplyUnsafe(wt));return tt.is0()?!1:s.create(tt.x)===J}catch{return!1}}function x(g,h,A={}){let{prehash:D}=Gi(A,p);return h=v(h,D),S.fromBytes(g,"recovered").recoverPublicKey(h).toBytes()}return Object.freeze({keygen:l,getPublicKey:u,getSharedSecret:d,utils:f,lengths:y,Point:e,sign:C,verify:B,recoverPublicKey:x,Signature:S,hash:t})}function Hd(e){let t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(s=>Math.ceil(s/2)))):void 0,o=Ct(t.n,{BITS:e.nBitLength,allowedLengths:n,modFromBytes:e.wrapPrivateKey}),i={Fp:r,Fn:o,allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes};return{CURVE:t,curveOpts:i}}function $d(e){let{CURVE:t,curveOpts:r}=Hd(e),n={hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:r,hash:e.hash,ecdsaOpts:n}}function zd(e,t){let r=t.Point;return Object.assign({},t,{ProjectivePoint:r,CURVE:Object.assign({},e,Bn(r.Fn.ORDER,r.Fn.BITS))})}function uc(e){let{CURVE:t,curveOpts:r,hash:n,ecdsaOpts:o}=$d(e),i=Fd(t,r),s=qd(i,n,o);return zd(e,s)}function fc(e,t){let r=n=>uc({...e,hash:n});return{...r(t),create:r}}var Wi={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Zd={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var lc=BigInt(2);function Gd(e){let t=Wi.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),l=e*e*e%t,u=l*l*e%t,d=W(u,r,t)*u%t,f=W(d,r,t)*u%t,y=W(f,lc,t)*l%t,p=W(y,o,t)*y%t,b=W(p,i,t)*p%t,T=W(b,a,t)*b%t,E=W(T,c,t)*T%t,U=W(E,a,t)*b%t,S=W(U,r,t)*u%t,N=W(S,s,t)*p%t,P=W(N,n,t)*l%t,M=W(P,lc,t);if(!Xi.eql(Xi.sqr(M),e))throw new Error("Cannot find square root");return M}var Xi=Ct(Wi.p,{sqrt:Gd}),yr=fc({...Wi,Fp:Xi,lowS:!0,endo:Zd},Sn);function dc(e,t,r,n){let o=Cr.digest(r instanceof Uint8Array?r:r.subarray());if(Un(o))return o.then(({digest:i})=>(n?.signal?.throwIfAborted(),yr.verify(t,i,e))).catch(i=>{throw i.name==="AbortError"?i:new Fr(String(i))});try{return n?.signal?.throwIfAborted(),yr.verify(t,o.digest,e)}catch(i){throw new Fr(String(i))}}var On=class{type="secp256k1";raw;_key;constructor(t){this._key=pc(t),this.raw=hc(this._key)}toMultihash(){return Ft.digest(Se(this))}toCID(){return Y.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:nt(this.raw,t.raw)}verify(t,r,n){return dc(this._key,r,t,n)}};function Ji(e){return new On(e)}function hc(e){return yr.ProjectivePoint.fromHex(e).toRawBytes(!0)}function pc(e){try{return yr.ProjectivePoint.fromHex(e),e}catch(t){throw new je(String(t))}}function mc(e,t){let{Type:r,Data:n}=Gt.decode(e),o=n??new Uint8Array;switch(r){case ot.RSA:return Hi(o,t);case ot.Ed25519:return Ai(o);case ot.secp256k1:return Ji(o);case ot.ECDSA:return Wo(o);default:throw new We}}function Mn(e){let{Type:t,Data:r}=Gt.decode(e.digest),n=r??new Uint8Array;switch(t){case ot.Ed25519:return Ai(n);case ot.secp256k1:return Ji(n);case ot.ECDSA:return Wo(n);default:throw new We}}function Se(e){return Gt.encode({Type:ot[e.type],Data:e.raw})}var yc=Symbol.for("nodejs.util.inspect.custom"),Yd=114,Gr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Eo]=!0;toString(){return this.string==null&&(this.string=G.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return Y.createV1(Yd,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return nt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return nt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[yc](){return`PeerId(${this.toString()})`}},Fn=class extends Gr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Vn=class extends Gr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},qn=class extends Gr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},jd=2336,Yr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Ft.digest($(this.url))}[yc](){return`PeerId(${this.url})`}[Eo]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return Y.createV1(jd,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=z(t)),t.toString()===this.toString())}};var Xd=114,gc=2336;function Hn(e,t){let r;if(e.charAt(0)==="1"||e.charAt(0)==="Q")r=Wt(G.decode(`z${e}`));else{if(e.startsWith("k51qzi5uqu5")||e.startsWith("kzwfwjn5ji4")||e.startsWith("k2k4r8")||e.startsWith("bafz"))return Qi(Y.parse(e));if(t==null)throw new it('Please pass a multibase decoder for strings that do not start with "1" or "Q"');r=Wt(t.decode(e))}return xc(r)}function xc(e){if(Jd(e))return new Fn({multihash:e});if(Wd(e))try{let t=Mn(e);if(t.type==="Ed25519")return new Vn({multihash:e,publicKey:t});if(t.type==="secp256k1")return new qn({multihash:e,publicKey:t})}catch{let r=z(e.digest);return new Yr(new URL(r))}throw new Xe("Supplied PeerID Multihash is invalid")}function Qi(e){if(e?.multihash==null||e.version==null||e.version===1&&e.code!==Xd&&e.code!==gc)throw new fn("Supplied PeerID CID is invalid");if(e.code===gc){let t=z(e.multihash.digest);return new Yr(new URL(t))}return xc(e.multihash)}function Wd(e){return e.code===Ft.code}function Jd(e){return e.code===Cr.code}var Uu=un($n(),1);var zn=class extends Error{static name="SignatureCreationError";constructor(t="Record signature creation failed"){super(t),this.name="SignatureCreationError"}},Ht=class extends Error{static name="SignatureVerificationError";constructor(t="Record signature verification failed"){super(t),this.name="SignatureVerificationError"}},Zn=class extends Error{static name="RecordExpiredError";constructor(t="Record has expired"){super(t),this.name="RecordExpiredError"}},ze=class extends Error{static name="UnsupportedValidityError";constructor(t="The validity type is unsupported"){super(t),this.name="UnsupportedValidityError"}},Gn=class extends Error{static name="RecordTooLargeError";constructor(t="The record is too large"){super(t),this.name="RecordTooLargeError"}},jr=class extends Error{static name="InvalidValueError";constructor(t="Value must be a valid content path starting with /"){super(t),this.name="InvalidValueError"}},Yn=class extends Error{static name="InvalidRecordDataError";constructor(t="Invalid record data"){super(t),this.name="InvalidRecordDataError"}},Xr=class extends Error{static name="InvalidEmbeddedPublicKeyError";constructor(t="Invalid embedded public key"){super(t),this.name="InvalidEmbeddedPublicKeyError"}};var lt;(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=()=>$r(r)}(t=e.ValidityType||(e.ValidityType={}));let n;e.codec=()=>(n==null&&(n=Ne((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 a={},c=i==null?o.len:o.pos+i;for(;o.pos<c;){let l=o.uint32();switch(l>>>3){case 1:{a.value=o.bytes();break}case 2:{a.signatureV1=o.bytes();break}case 3:{a.validityType=e.ValidityType.codec().decode(o);break}case 4:{a.validity=o.bytes();break}case 5:{a.sequence=o.uint64();break}case 6:{a.ttl=o.uint64();break}case 7:{a.pubKey=o.bytes();break}case 8:{a.signatureV2=o.bytes();break}case 9:{a.data=o.bytes();break}default:{o.skipType(l&7);break}}}return a})),n),e.encode=o=>Le(o,e.codec()),e.decode=(o,i)=>Re(o,e.codec(),i)})(lt||(lt={}));var Qd=["string","number","bigint","symbol"],th=["Function","Generator","AsyncGenerator","GeneratorFunction","AsyncGeneratorFunction","AsyncFunction","Observable","Array","Buffer","Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function wc(e){if(e===null)return"null";if(e===void 0)return"undefined";if(e===!0||e===!1)return"boolean";let t=typeof e;if(Qd.includes(t))return t;if(t==="function")return"Function";if(Array.isArray(e))return"Array";if(eh(e))return"Buffer";let r=rh(e);return r||"Object"}function eh(e){return e&&e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer.call(null,e)}function rh(e){let t=Object.prototype.toString.call(e).slice(8,-1);if(th.includes(t))return t}var w=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}};w.uint=new w(0,"uint",!0);w.negint=new w(1,"negint",!0);w.bytes=new w(2,"bytes",!0);w.string=new w(3,"string",!0);w.array=new w(4,"array",!1);w.map=new w(5,"map",!1);w.tag=new w(6,"tag",!1);w.float=new w(7,"float",!0);w.false=new w(7,"false",!0);w.true=new w(7,"true",!0);w.null=new w(7,"null",!0);w.undefined=new w(7,"undefined",!0);w.break=new w(7,"break",!0);var R=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 gr=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",nh=new TextDecoder,oh=new TextEncoder;function jn(e){return gr&&globalThis.Buffer.isBuffer(e)}function es(e){return e instanceof Uint8Array?jn(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e:Uint8Array.from(e)}var Ac=gr?(e,t,r)=>r-t>64?globalThis.Buffer.from(e.subarray(t,r)).toString("utf8"):Ec(e,t,r):(e,t,r)=>r-t>64?nh.decode(e.subarray(t,r)):Ec(e,t,r),vc=gr?e=>e.length>64?globalThis.Buffer.from(e):bc(e):e=>e.length>64?oh.encode(e):bc(e),Yt=e=>Uint8Array.from(e),xr=gr?(e,t,r)=>jn(e)?new Uint8Array(e.subarray(t,r)):e.slice(t,r):(e,t,r)=>e.slice(t,r),Bc=gr?(e,t)=>(e=e.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),es(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},Tc=gr?e=>globalThis.Buffer.allocUnsafe(e):e=>new Uint8Array(e);function Cc(e,t){if(jn(e)&&jn(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 bc(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):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128)}return t}function Ec(e,t,r){let n=[];for(;t<r;){let o=e[t],i=null,s=o>239?4:o>223?3:o>191?2:1;if(t+s<=r){let a,c,l,u;switch(s){case 1:o<128&&(i=o);break;case 2:a=e[t+1],(a&192)===128&&(u=(o&31)<<6|a&63,u>127&&(i=u));break;case 3:a=e[t+1],c=e[t+2],(a&192)===128&&(c&192)===128&&(u=(o&15)<<12|(a&63)<<6|c&63,u>2047&&(u<55296||u>57343)&&(i=u));break;case 4:a=e[t+1],c=e[t+2],l=e[t+3],(a&192)===128&&(c&192)===128&&(l&192)===128&&(u=(o&15)<<18|(a&63)<<12|(c&63)<<6|l&63,u>65535&&u<1114112&&(i=u))}}i===null?(i=65533,s=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),t+=s}return ih(n)}var Sc=4096;function ih(e){let t=e.length;if(t<=Sc)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=Sc));return r}var sh=256,Wr=class{constructor(t=sh){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=Tc(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=xr(n,0,this.cursor)}else r=Bc(this.chunks,this.cursor);return t&&this.reset(),r}};var V="CBOR decode error:",rs="CBOR encode error:",Jr=[];Jr[23]=1;Jr[24]=2;Jr[25]=3;Jr[26]=5;Jr[27]=9;function de(e,t,r){if(e.length-t<r)throw new Error(`${V} not enough data for type`)}var ut=[24,256,65536,4294967296,BigInt("18446744073709551616")];function _t(e,t,r){de(e,t,1);let n=e[t];if(r.strict===!0&&n<ut[0])throw new Error(`${V} integer encoded in more bytes than necessary (strict decode)`);return n}function Ut(e,t,r){de(e,t,2);let n=e[t]<<8|e[t+1];if(r.strict===!0&&n<ut[1])throw new Error(`${V} integer encoded in more bytes than necessary (strict decode)`);return n}function Dt(e,t,r){de(e,t,4);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];if(r.strict===!0&&n<ut[2])throw new Error(`${V} integer encoded in more bytes than necessary (strict decode)`);return n}function Rt(e,t,r){de(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<ut[3])throw new Error(`${V} 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(`${V} integers outside of the safe integer range are not supported`)}function Ic(e,t,r,n){return new R(w.uint,_t(e,t+1,n),2)}function _c(e,t,r,n){return new R(w.uint,Ut(e,t+1,n),3)}function Uc(e,t,r,n){return new R(w.uint,Dt(e,t+1,n),5)}function Dc(e,t,r,n){return new R(w.uint,Rt(e,t+1,n),9)}function Kt(e,t){return dt(e,0,t.value)}function dt(e,t,r){if(r<ut[0]){let n=Number(r);e.push([t|n])}else if(r<ut[1]){let n=Number(r);e.push([t|24,n])}else if(r<ut[2]){let n=Number(r);e.push([t|25,n>>>8,n&255])}else if(r<ut[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<ut[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(`${V} encountered BigInt larger than allowable range`)}}Kt.encodedSize=function(t){return dt.encodedSize(t.value)};dt.encodedSize=function(t){return t<ut[0]?1:t<ut[1]?2:t<ut[2]?3:t<ut[3]?5:9};Kt.compareTokens=function(t,r){return t.value<r.value?-1:t.value>r.value?1:0};function Rc(e,t,r,n){return new R(w.negint,-1-_t(e,t+1,n),2)}function Lc(e,t,r,n){return new R(w.negint,-1-Ut(e,t+1,n),3)}function Nc(e,t,r,n){return new R(w.negint,-1-Dt(e,t+1,n),5)}var ns=BigInt(-1),kc=BigInt(1);function Kc(e,t,r,n){let o=Rt(e,t+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new R(w.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${V} integers outside of the safe integer range are not supported`);return new R(w.negint,ns-BigInt(o),9)}function Xn(e,t){let r=t.value,n=typeof r=="bigint"?r*ns-kc:r*-1-1;dt(e,t.type.majorEncoded,n)}Xn.encodedSize=function(t){let r=t.value,n=typeof r=="bigint"?r*ns-kc:r*-1-1;return n<ut[0]?1:n<ut[1]?2:n<ut[2]?3:n<ut[3]?5:9};Xn.compareTokens=function(t,r){return t.value<r.value?1:t.value>r.value?-1:0};function Qr(e,t,r,n){de(e,t,r+n);let o=xr(e,t+r,t+r+n);return new R(w.bytes,o,r+n)}function Pc(e,t,r,n){return Qr(e,t,1,r)}function Oc(e,t,r,n){return Qr(e,t,2,_t(e,t+1,n))}function Mc(e,t,r,n){return Qr(e,t,3,Ut(e,t+1,n))}function Fc(e,t,r,n){return Qr(e,t,5,Dt(e,t+1,n))}function Vc(e,t,r,n){let o=Rt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${V} 64-bit integer bytes lengths not supported`);return Qr(e,t,9,o)}function Wn(e){return e.encodedBytes===void 0&&(e.encodedBytes=e.type===w.string?vc(e.value):e.value),e.encodedBytes}function wr(e,t){let r=Wn(t);dt(e,t.type.majorEncoded,r.length),e.push(r)}wr.encodedSize=function(t){let r=Wn(t);return dt.encodedSize(r.length)+r.length};wr.compareTokens=function(t,r){return ch(Wn(t),Wn(r))};function ch(e,t){return e.length<t.length?-1:e.length>t.length?1:Cc(e,t)}function tn(e,t,r,n,o){let i=r+n;de(e,t,i);let s=new R(w.string,Ac(e,t+r,t+i),i);return o.retainStringBytes===!0&&(s.byteValue=xr(e,t+r,t+i)),s}function qc(e,t,r,n){return tn(e,t,1,r,n)}function Hc(e,t,r,n){return tn(e,t,2,_t(e,t+1,n),n)}function $c(e,t,r,n){return tn(e,t,3,Ut(e,t+1,n),n)}function zc(e,t,r,n){return tn(e,t,5,Dt(e,t+1,n),n)}function Zc(e,t,r,n){let o=Rt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${V} 64-bit integer string lengths not supported`);return tn(e,t,9,o,n)}var Gc=wr;function br(e,t,r,n){return new R(w.array,n,r)}function Yc(e,t,r,n){return br(e,t,1,r)}function jc(e,t,r,n){return br(e,t,2,_t(e,t+1,n))}function Xc(e,t,r,n){return br(e,t,3,Ut(e,t+1,n))}function Wc(e,t,r,n){return br(e,t,5,Dt(e,t+1,n))}function Jc(e,t,r,n){let o=Rt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${V} 64-bit integer array lengths not supported`);return br(e,t,9,o)}function Qc(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${V} indefinite length items not allowed`);return br(e,t,1,1/0)}function Jn(e,t){dt(e,w.array.majorEncoded,t.value)}Jn.compareTokens=Kt.compareTokens;Jn.encodedSize=function(t){return dt.encodedSize(t.value)};function Er(e,t,r,n){return new R(w.map,n,r)}function tu(e,t,r,n){return Er(e,t,1,r)}function eu(e,t,r,n){return Er(e,t,2,_t(e,t+1,n))}function ru(e,t,r,n){return Er(e,t,3,Ut(e,t+1,n))}function nu(e,t,r,n){return Er(e,t,5,Dt(e,t+1,n))}function ou(e,t,r,n){let o=Rt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${V} 64-bit integer map lengths not supported`);return Er(e,t,9,o)}function iu(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${V} indefinite length items not allowed`);return Er(e,t,1,1/0)}function Qn(e,t){dt(e,w.map.majorEncoded,t.value)}Qn.compareTokens=Kt.compareTokens;Qn.encodedSize=function(t){return dt.encodedSize(t.value)};function su(e,t,r,n){return new R(w.tag,r,1)}function au(e,t,r,n){return new R(w.tag,_t(e,t+1,n),2)}function cu(e,t,r,n){return new R(w.tag,Ut(e,t+1,n),3)}function uu(e,t,r,n){return new R(w.tag,Dt(e,t+1,n),5)}function fu(e,t,r,n){return new R(w.tag,Rt(e,t+1,n),9)}function to(e,t){dt(e,w.tag.majorEncoded,t.value)}to.compareTokens=Kt.compareTokens;to.encodedSize=function(t){return dt.encodedSize(t.value)};var ph=20,mh=21,yh=22,gh=23;function lu(e,t,r,n){if(n.allowUndefined===!1)throw new Error(`${V} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new R(w.null,null,1):new R(w.undefined,void 0,1)}function du(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${V} indefinite length items not allowed`);return new R(w.break,void 0,1)}function os(e,t,r){if(r){if(r.allowNaN===!1&&Number.isNaN(e))throw new Error(`${V} NaN values are not supported`);if(r.allowInfinity===!1&&(e===1/0||e===-1/0))throw new Error(`${V} Infinity values are not supported`)}return new R(w.float,e,t)}function hu(e,t,r,n){return os(is(e,t+1),3,n)}function pu(e,t,r,n){return os(ss(e,t+1),5,n)}function mu(e,t,r,n){return os(wu(e,t+1),9,n)}function eo(e,t,r){let n=t.value;if(n===!1)e.push([w.float.majorEncoded|ph]);else if(n===!0)e.push([w.float.majorEncoded|mh]);else if(n===null)e.push([w.float.majorEncoded|yh]);else if(n===void 0)e.push([w.float.majorEncoded|gh]);else{let o,i=!1;(!r||r.float64!==!0)&&(gu(n),o=is($t,1),n===o||Number.isNaN(n)?($t[0]=249,e.push($t.slice(0,3)),i=!0):(xu(n),o=ss($t,1),n===o&&($t[0]=250,e.push($t.slice(0,5)),i=!0))),i||(xh(n),o=wu($t,1),$t[0]=251,e.push($t.slice(0,9)))}}eo.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){gu(n);let o=is($t,1);if(n===o||Number.isNaN(n))return 3;if(xu(n),o=ss($t,1),n===o)return 5}return 9};var yu=new ArrayBuffer(9),Pt=new DataView(yu,1),$t=new Uint8Array(yu,0);function gu(e){if(e===1/0)Pt.setUint16(0,31744,!1);else if(e===-1/0)Pt.setUint16(0,64512,!1);else if(Number.isNaN(e))Pt.setUint16(0,32256,!1);else{Pt.setFloat32(0,e);let t=Pt.getUint32(0),r=(t&2139095040)>>23,n=t&8388607;if(r===255)Pt.setUint16(0,31744,!1);else if(r===0)Pt.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?Pt.setUint16(0,0):o<-14?Pt.setUint16(0,(t&2147483648)>>16|1<<24+o,!1):Pt.setUint16(0,(t&2147483648)>>16|o+15<<10|n>>13,!1)}}}function is(e,t){if(e.length-t<2)throw new Error(`${V} 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 xu(e){Pt.setFloat32(0,e,!1)}function ss(e,t){if(e.length-t<4)throw new Error(`${V} not enough data for float32`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,4).getFloat32(0,!1)}function xh(e){Pt.setFloat64(0,e,!1)}function wu(e,t){if(e.length-t<8)throw new Error(`${V} not enough data for float64`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,8).getFloat64(0,!1)}eo.compareTokens=Kt.compareTokens;function Z(e,t,r){throw new Error(`${V} encountered invalid minor (${r}) for major ${e[t]>>>5}`)}function ro(e){return()=>{throw new Error(`${V} ${e}`)}}var _=[];for(let e=0;e<=23;e++)_[e]=Z;_[24]=Ic;_[25]=_c;_[26]=Uc;_[27]=Dc;_[28]=Z;_[29]=Z;_[30]=Z;_[31]=Z;for(let e=32;e<=55;e++)_[e]=Z;_[56]=Rc;_[57]=Lc;_[58]=Nc;_[59]=Kc;_[60]=Z;_[61]=Z;_[62]=Z;_[63]=Z;for(let e=64;e<=87;e++)_[e]=Pc;_[88]=Oc;_[89]=Mc;_[90]=Fc;_[91]=Vc;_[92]=Z;_[93]=Z;_[94]=Z;_[95]=ro("indefinite length bytes/strings are not supported");for(let e=96;e<=119;e++)_[e]=qc;_[120]=Hc;_[121]=$c;_[122]=zc;_[123]=Zc;_[124]=Z;_[125]=Z;_[126]=Z;_[127]=ro("indefinite length bytes/strings are not supported");for(let e=128;e<=151;e++)_[e]=Yc;_[152]=jc;_[153]=Xc;_[154]=Wc;_[155]=Jc;_[156]=Z;_[157]=Z;_[158]=Z;_[159]=Qc;for(let e=160;e<=183;e++)_[e]=tu;_[184]=eu;_[185]=ru;_[186]=nu;_[187]=ou;_[188]=Z;_[189]=Z;_[190]=Z;_[191]=iu;for(let e=192;e<=215;e++)_[e]=su;_[216]=au;_[217]=cu;_[218]=uu;_[219]=fu;_[220]=Z;_[221]=Z;_[222]=Z;_[223]=Z;for(let e=224;e<=243;e++)_[e]=ro("simple values are not supported");_[244]=Z;_[245]=Z;_[246]=Z;_[247]=lu;_[248]=ro("simple values are not supported");_[249]=hu;_[250]=pu;_[251]=mu;_[252]=Z;_[253]=Z;_[254]=Z;_[255]=du;var zt=[];for(let e=0;e<24;e++)zt[e]=new R(w.uint,e,1);for(let e=-1;e>=-24;e--)zt[31-e]=new R(w.negint,e,1);zt[64]=new R(w.bytes,new Uint8Array(0),1);zt[96]=new R(w.string,"",1);zt[128]=new R(w.array,0,1);zt[160]=new R(w.map,0,1);zt[244]=new R(w.false,!1,1);zt[245]=new R(w.true,!0,1);zt[246]=new R(w.null,null,1);function bu(e){switch(e.type){case w.false:return Yt([244]);case w.true:return Yt([245]);case w.null:return Yt([246]);case w.bytes:return e.value.length?void 0:Yt([64]);case w.string:return e.value===""?Yt([96]):void 0;case w.array:return e.value===0?Yt([128]):void 0;case w.map:return e.value===0?Yt([160]):void 0;case w.uint:return e.value<24?Yt([Number(e.value)]):void 0;case w.negint:if(e.value>=-24)return Yt([31-Number(e.value)])}}var bh={float64:!1,mapSorter:Ah,quickEncodeToken:bu};function Eh(){let e=[];return e[w.uint.major]=Kt,e[w.negint.major]=Xn,e[w.bytes.major]=wr,e[w.string.major]=Gc,e[w.array.major]=Jn,e[w.map.major]=Qn,e[w.tag.major]=to,e[w.float.major]=eo,e}var Eu=Eh(),as=new Wr,oo=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(`${rs} object contains circular references`);return new e(r,t)}},ke={null:new R(w.null,null),undefined:new R(w.undefined,void 0),true:new R(w.true,!0),false:new R(w.false,!1),emptyArray:new R(w.array,0),emptyMap:new R(w.map,0)},Ke={number(e,t,r,n){return!Number.isInteger(e)||!Number.isSafeInteger(e)?new R(w.float,e):e>=0?new R(w.uint,e):new R(w.negint,e)},bigint(e,t,r,n){return e>=BigInt(0)?new R(w.uint,e):new R(w.negint,e)},Uint8Array(e,t,r,n){return new R(w.bytes,e)},string(e,t,r,n){return new R(w.string,e)},boolean(e,t,r,n){return e?ke.true:ke.false},null(e,t,r,n){return ke.null},undefined(e,t,r,n){return ke.undefined},ArrayBuffer(e,t,r,n){return new R(w.bytes,new Uint8Array(e))},DataView(e,t,r,n){return new R(w.bytes,new Uint8Array(e.buffer,e.byteOffset,e.byteLength))},Array(e,t,r,n){if(!e.length)return r.addBreakTokens===!0?[ke.emptyArray,new R(w.break)]:ke.emptyArray;n=oo.createCheck(n,e);let o=[],i=0;for(let s of e)o[i++]=no(s,r,n);return r.addBreakTokens?[new R(w.array,e.length),o,new R(w.break)]:[new R(w.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;if(!s)return r.addBreakTokens===!0?[ke.emptyMap,new R(w.break)]:ke.emptyMap;n=oo.createCheck(n,e);let a=[],c=0;for(let l of i)a[c++]=[no(l,r,n),no(o?e.get(l):e[l],r,n)];return Sh(a,r),r.addBreakTokens?[new R(w.map,s),a,new R(w.break)]:[new R(w.map,s),a]}};Ke.Map=Ke.Object;Ke.Buffer=Ke.Uint8Array;for(let e of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))Ke[`${e}Array`]=Ke.DataView;function no(e,t={},r){let n=wc(e),o=t&&t.typeEncoders&&t.typeEncoders[n]||Ke[n];if(typeof o=="function"){let s=o(e,n,t,r);if(s!=null)return s}let i=Ke[n];if(!i)throw new Error(`${rs} unsupported type: ${n}`);return i(e,n,t,r)}function Sh(e,t){t.mapSorter&&e.sort(t.mapSorter)}function Ah(e,t){let r=Array.isArray(e[0])?e[0][0]:e[0],n=Array.isArray(t[0])?t[0][0]:t[0];if(r.type!==n.type)return r.type.compare(n.type);let o=r.type.major,i=Eu[o].compareTokens(r,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function Su(e,t,r,n){if(Array.isArray(t))for(let o of t)Su(e,o,r,n);else r[t.type.major](e,t,n)}function vh(e,t,r){let n=no(e,r);if(!Array.isArray(n)&&r.quickEncodeToken){let o=r.quickEncodeToken(n);if(o)return o;let i=t[n.type.major];if(i.encodedSize){let s=i.encodedSize(n,r),a=new Wr(s);if(i(a,n,r),a.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return es(a.chunks[0])}}return as.reset(),Su(as,n,t,r),as.toBytes(!0)}function cs(e,t){return t=Object.assign({},bh,t),vh(e,Eu,t)}var Bh={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},io=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=zt[t];if(r===void 0){let n=_[t];if(!n)throw new Error(`${V} 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}},en=Symbol.for("DONE"),so=Symbol.for("BREAK");function Th(e,t,r){let n=[];for(let o=0;o<e.value;o++){let i=Sr(t,r);if(i===so){if(e.value===1/0)break;throw new Error(`${V} got unexpected break to lengthed array`)}if(i===en)throw new Error(`${V} found array but not enough entries (got ${o}, expected ${e.value})`);n[o]=i}return n}function Ch(e,t,r){let n=r.useMaps===!0,o=n?void 0:{},i=n?new Map:void 0;for(let s=0;s<e.value;s++){let a=Sr(t,r);if(a===so){if(e.value===1/0)break;throw new Error(`${V} got unexpected break to lengthed map`)}if(a===en)throw new Error(`${V} found map but not enough entries (got ${s} [no key], expected ${e.value})`);if(n!==!0&&typeof a!="string")throw new Error(`${V} non-string keys not supported (got ${typeof a})`);if(r.rejectDuplicateMapKeys===!0&&(n&&i.has(a)||!n&&a in o))throw new Error(`${V} found repeat map key "${a}"`);let c=Sr(t,r);if(c===en)throw new Error(`${V} found map but not enough entries (got ${s} [no value], expected ${e.value})`);n?i.set(a,c):o[a]=c}return n?i:o}function Sr(e,t){if(e.done())return en;let r=e.next();if(r.type===w.break)return so;if(r.type.terminal)return r.value;if(r.type===w.array)return Th(r,e,t);if(r.type===w.map)return Ch(r,e,t);if(r.type===w.tag){if(t.tags&&typeof t.tags[r.value]=="function"){let n=Sr(e,t);return t.tags[r.value](n)}throw new Error(`${V} tag not supported (${r.value})`)}throw new Error("unsupported")}function Au(e,t){if(!(e instanceof Uint8Array))throw new Error(`${V} data to decode must be a Uint8Array`);t=Object.assign({},Bh,t);let r=t.tokenizer||new io(e,t),n=Sr(r,t);if(n===en)throw new Error(`${V} did not find any content to decode`);if(n===so)throw new Error(`${V} got unexpected break`);return[n,e.subarray(r.pos())]}function us(e,t){let[r,n]=Au(e,t);if(n.length>0)throw new Error(`${V} too many terminals, data makes no sense`);return r}var _h=xe("ipns:utils"),vu=$("/ipns/"),Uh=114,Dh=0,Rh=18;function rn(e){let t;if(e.pubKey!=null)try{t=mc(e.pubKey)}catch(r){throw _h.error(r),r}if(t!=null)return t}function Bu(e,t,r){let n=$(t);return be([e,r,n])}function co(e){let t=$("ipns-signature:");return be([t,e])}function uo(e){return"signatureV1"in e?lt.encode({value:$(e.value),signatureV1:e.signatureV1,validityType:e.validityType,validity:$(e.validity),sequence:e.sequence,ttl:e.ttl,pubKey:e.pubKey,signatureV2:e.signatureV2,data:e.data}):lt.encode({pubKey:e.pubKey,signatureV2:e.signatureV2,data:e.data})}function jt(e){let t=lt.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=Iu(t.data),n=Lh(r.Value),o=z(r.Validity);if(t.value!=null&&t.signatureV1!=null)return Nh(t),{value:n,validityType:lt.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:lt.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 Ge(e){return be([vu,e.bytes])}function Tu(e){let t=Wt(e.slice(vu.length));if(!ao(t,Dh)&&!ao(t,Rh))throw new Xe("Multihash in IPNS key was not identity or sha2-256");return t}function Cu(e,t,r,n,o){let i;if(t===lt.ValidityType.EOL)i=0;else throw new ze("The validity type is unsupported");return cs({Value:e,Validity:r,ValidityType:i,Sequence:n,TTL:o})}function Iu(e){let t=us(e);if(t.ValidityType===0)t.ValidityType=lt.ValidityType.EOL;else throw new ze("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 Lh(e){let t=z(e).trim();if(t.startsWith("/"))return t;try{return`/ipfs/${Y.decode(e).toV1().toString()}`}catch{}try{return`/ipfs/${Y.parse(t).toV1().toString()}`}catch{}throw new jr("Value must be a valid content path starting with /")}function _u(e){if(e!=null){let t=Ph(e);if(t!=null)return t.code===Uh?`/ipns/${t.toString(Ot)}`:`/ipfs/${t.toV1().toString()}`;if(kh(e))return`/ipns/${Ot.encode(e.bytes)}`;let r=e.toString().trim();if(r.startsWith("/")&&r.length>1)return r}throw new jr("Value must be a valid content path starting with /")}function Nh(e){if(e.data==null)throw new Yn("Record data is missing");let t=Iu(e.data);if(!nt(t.Value,e.value??new Uint8Array(0)))throw new Ht('Field "value" did not match between protobuf and CBOR');if(!nt(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 kh(e){return e.bytes instanceof Uint8Array}function Kh(e){return typeof e?.toCID=="function"}function Ph(e){if(Kh(e))return e.toCID();try{return Y.parse(e)}catch{}return Y.asCID(e)}function ao(e,t){return e.code===t}var Oh=xe("ipns"),Du=300*1e9,Mh="/ipns/",Lw=Mh.length,Ru={v1Compatible:!0,ttlNs:Du};async function Lu(e,t,r,n,o=Ru){let i=new Uu.default(Date.now()+Number(n)),s=lt.ValidityType.EOL,a=BigInt(o.ttlNs??Du);return Fh(e,t,r,s,i.toString(),a,o)}var Fh=async(e,t,r,n,o,i,s=Ru)=>{r=BigInt(r);let a=$(o),c=_u(t),l=$(c),u=Cu(l,n,a,r,i),d=co(u),f=await e.sign(d),y;if(e.type==="RSA"&&(y=Se(e.publicKey)),s.v1Compatible===!0){let p=await Vh(e,l,n,a),b={value:c,signatureV1:p,validity:o,validityType:n,sequence:r,ttl:i,signatureV2:f,data:u};return y!=null&&(b.pubKey=y),b}else{let p={value:c,validity:o,validityType:n,sequence:r,ttl:i,signatureV2:f,data:u};return y!=null&&(p.pubKey=y),p}},Vh=async(e,t,r,n)=>{try{let o=Bu(t,r,n);return await e.sign(o)}catch(o){throw Oh.error("record signature creation failed",o),new zn("Record signature creation failed")}};var fs=un($n(),1);function fo(e,t){let r=t.map((n,o)=>({record:jt(n),index:o}));return r.sort((n,o)=>{let i=n.record.sequence,s=o.record.sequence;if(i>s)return-1;if(i<s)return 1;if(n.record.validityType===lt.ValidityType.EOL&&o.record.validityType===lt.ValidityType.EOL){let a=fs.default.fromString(n.record.validity).toDate(),c=fs.default.fromString(o.record.validity).toDate();if(a.getTime()>c.getTime())return-1;if(a.getTime()<c.getTime())return 1}return 0}),r[0].index}var Nu=un($n(),1);var lo=xe("ipns:validator"),qh=1024*10;async function Hh(e,t){let r=jt(t),n;try{let o=co(r.data);n=await e.verify(o,r.signatureV2)}catch{n=!1}if(!n)throw lo.error("record signature verification failed"),new Ht("Record signature verification failed");if(r.validityType===lt.ValidityType.EOL){if(Nu.default.fromString(r.validity).toDate().getTime()<Date.now())throw lo.error("record has expired"),new Zn("record has expired")}else if(r.validityType!=null)throw lo.error("the validity type is unsupported"),new ze("The validity type is unsupported");lo("ipns record for %s is valid",r.value)}async function nn(e,t){if(t.byteLength>qh)throw new Gn("The record is too large");let r=Tu(e),n;ao(r,0)&&(n=Mn(r));let o=jt(t),i=rn(o)??n;if(i==null)throw new Xr("Could not extract public key from IPNS record or routing key");let s=Ge(i.toMultihash());if(!nt(s,e))throw new Xr("Embedded public key did not match routing key");await Hh(i,t)}var mt=class extends Event{type;detail;constructor(t,r){super(t),this.type=t,this.detail=r}};var Zh=un(Ku(),1);var he;(function(e){e[e.A=1]="A",e[e.CNAME=5]="CNAME",e[e.TXT=16]="TXT",e[e.AAAA=28]="AAAA"})(he||(he={}));var ho=class extends Error{static name="DNSLinkNotFoundError";constructor(t="DNSLink not found"){super(t),this.name="DNSLinkNotFoundError"}},po=class extends Error{static name="RecordsFailedValidationError";constructor(t="Records failed validation"){super(t),this.name="RecordsFailedValidationError"}},mo=class extends Error{static name="UnsupportedMultibasePrefixError";constructor(t="Unsupported multibase prefix"){super(t),this.name="UnsupportedMultibasePrefixError"}},yo=class extends Error{static name="UnsupportedMultihashCodecError";constructor(t="Unsupported multihash codec"){super(t),this.name="UnsupportedMultihashCodecError"}},go=class extends Error{static name="InvalidValueError";constructor(t="Invalid value"){super(t),this.name="InvalidValueError"}};var Gh=32;async function Pu(e,t,r,n,o={}){if(t===0)throw new Error("recursion limit exceeded");n("query %s for TXT and CNAME records",e);let s=((await r.query(e,{...o,types:[he.TXT]}))?.Answer??[]).sort((l,u)=>l.data.localeCompare(u.data));n("found %d TXT records for %s",s.length,e);for(let l of s)try{let u=l.data;if(u.startsWith('"')&&u.endsWith('"')&&(u=u.substring(1,u.length-1)),!u.startsWith("dnslink="))continue;n("%s TXT %s",l.name,u),u=u.replace("dnslink=","");let[,d,f,...y]=u.split("/");if(d==="ipfs")try{return{value:`/ipfs/${Y.parse(f)}${y.length>0?`/${y.join("/")}`:""}`,answer:l}}catch{}else if(d==="ipns"){try{let p;return f.charAt(0)==="1"||f.charAt(0)==="Q"?p=Hn(f):p=Qi(Y.parse(f)),{value:`/ipns/${p}${y.length>0?`/${y.join("/")}`:""}`,answer:l}}catch{}return await xo(f,t-1,r,n,o)}else{if(d==="dnslink")return await xo(f,t-1,r,n,o);n('unknown protocol "%s" in DNSLink record for domain: %s',d,e);continue}}catch(u){n.error("could not parse DNS link record for domain %s, %s",e,l.data,u)}n("no DNSLink records found for %s, falling back to CNAME",e);let c=((await r.query(e,{...o,types:[he.CNAME]}))?.Answer??[]).sort((l,u)=>l.data.localeCompare(u.data));n("found %d CNAME records for %s",c.length,e);for(let l of c)try{return await xo(l.data,t-1,r,n,o)}catch(u){n.error("domain %s cname %s had no DNSLink records",e,l.data,u)}throw new ho(`No DNSLink records found for domain: ${e}`)}async function xo(e,t,r,n,o={}){if(t===0)throw new Error("recursion limit exceeded");e.startsWith("_dnslink.")||(e=`_dnslink.${e}`);try{return await Pu(e,t,r,n,o)}catch(i){if(i.code!=="ENOTFOUND"&&i.code!=="ENODATA"&&i.name!=="DNSLinkNotFoundError"&&i.name!=="NotFoundError")throw i;return e.startsWith("_dnslink.")?e=e.replace("_dnslink.",""):e=`_dnslink.${e}`,Pu(e,t,r,n,o)}}async function Ou(e,t,r,n={}){return xo(e,n.maxRecursiveDepth??Gh,t,r,n)}var ls=class{routing;constructor(t){this.routing=t}async put(t,r,n={}){try{await this.routing.put(t,r,n)}catch(o){throw n.onProgress?.(new mt("ipns:routing:helia:error",o)),o}}async get(t,r={}){try{return await this.routing.get(t,r)}catch(n){throw r.onProgress?.(new mt("ipns:routing:helia:error",n)),n}}};function Mu(e){return new ls(e)}var on;(function(e){let t;e.codec=()=>(t==null&&(t=Ne((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.key!=null&&r.key.byteLength>0&&(n.uint32(10),n.bytes(r.key)),r.value!=null&&r.value.byteLength>0&&(n.uint32(18),n.bytes(r.value)),r.timeReceived!=null&&r.timeReceived!==""&&(n.uint32(42),n.string(r.timeReceived)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let i={key:Lt(0),value:Lt(0),timeReceived:""},s=n==null?r.len:r.pos+n;for(;r.pos<s;){let a=r.uint32();switch(a>>>3){case 1:{i.key=r.bytes();break}case 2:{i.value=r.bytes();break}case 5:{i.timeReceived=r.string();break}default:{r.skipType(a&7);break}}}return i})),t),e.encode=r=>Le(r,e.codec()),e.decode=(r,n)=>Re(r,e.codec(),n)})(on||(on={}));function Fu(e){let t=e.getUTCFullYear(),r=String(e.getUTCMonth()+1).padStart(2,"0"),n=String(e.getUTCDate()).padStart(2,"0"),o=String(e.getUTCHours()).padStart(2,"0"),i=String(e.getUTCMinutes()).padStart(2,"0"),s=String(e.getUTCSeconds()).padStart(2,"0"),a=e.getUTCMilliseconds(),c=String(a*1e3*1e3).padStart(9,"0");return`${t}-${r}-${n}T${o}:${i}:${s}.${c}Z`}function Vu(e){let t=new RegExp("(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})\\.(\\d+)Z"),r=String(e).trim().match(t);if(r==null)throw new Error("Invalid format");let n=parseInt(r[1],10),o=parseInt(r[2],10)-1,i=parseInt(r[3],10),s=parseInt(r[4],10),a=parseInt(r[5],10),c=parseInt(r[6],10),l=parseInt(r[7].slice(0,-6),10);return new Date(Date.UTC(n,o,i,s,a,c,l))}var Ye=class e{key;value;timeReceived;constructor(t,r,n){if(!(t instanceof Uint8Array))throw new Error("key must be a Uint8Array");if(!(r instanceof Uint8Array))throw new Error("value must be a Uint8Array");this.key=t,this.value=r,this.timeReceived=n}serialize(){return on.encode(this.prepareSerialize())}prepareSerialize(){return{key:this.key,value:this.value,timeReceived:Fu(this.timeReceived)}}static deserialize(t){let r=on.decode(t);return new e(r.key,r.value,new Date(r.timeReceived))}static fromDeserialized(t){let r=Vu(t.timeReceived);if(t.key==null)throw new Error("key missing from deserialized object");if(t.value==null)throw new Error("value missing from deserialized object");return new e(t.key,t.value,r)}};var pe="/",qu=new TextEncoder().encode(pe),wo=qu[0],sn=class e{_buf;constructor(t,r){if(typeof t=="string")this._buf=$(t);else if(t instanceof Uint8Array)this._buf=t;else throw new Error("Invalid key, should be String of Uint8Array");if(r==null&&(r=!0),r&&this.clean(),this._buf.byteLength===0||this._buf[0]!==wo)throw new Error("Invalid key")}toString(t="utf8"){return z(this._buf,t)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(t){return new e(t.join(pe))}static random(){return new e(Math.random().toString().substring(2))}static asKey(t){return t instanceof Uint8Array||typeof t=="string"?new e(t):typeof t.uint8Array=="function"?new e(t.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=qu),this._buf[0]!==wo){let t=new Uint8Array(this._buf.byteLength+1);t.fill(wo,0,1),t.set(this._buf,1),this._buf=t}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===wo;)this._buf=this._buf.subarray(0,-1)}less(t){let r=this.list(),n=t.list();for(let o=0;o<r.length;o++){if(n.length<o+1)return!1;let i=r[o],s=n[o];if(i<s)return!0;if(i>s)return!1}return r.length<n.length}reverse(){return e.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let t=this.namespaces();return t[t.length-1]}list(){return this.toString().split(pe).slice(1)}type(){return jh(this.baseNamespace())}name(){return Xh(this.baseNamespace())}instance(t){return new e(this.toString()+":"+t)}path(){let t=this.parent().toString();return t.endsWith(pe)||(t+=pe),t+=this.type(),new e(t)}parent(){let t=this.list();return t.length===1?new e(pe):new e(t.slice(0,-1).join(pe))}child(t){return this.toString()===pe?t:t.toString()===pe?this:new e(this.toString()+t.toString(),!1)}isAncestorOf(t){return t.toString()===this.toString()?!1:t.toString().startsWith(this.toString())}isDecendantOf(t){return t.toString()===this.toString()?!1:this.toString().startsWith(t.toString())}isTopLevel(){return this.list().length===1}concat(...t){return e.withNamespaces([...this.namespaces(),...Wh(t.map(r=>r.namespaces()))])}};function jh(e){let t=e.split(":");return t.length<2?"":t.slice(0,-1).join(":")}function Xh(e){let t=e.split(":");return t[t.length-1]}function Wh(e){return[].concat(...e)}var Hu;(function(e){e[e.SEND_QUERY=0]="SEND_QUERY",e[e.PEER_RESPONSE=1]="PEER_RESPONSE",e[e.FINAL_PEER=2]="FINAL_PEER",e[e.QUERY_ERROR=3]="QUERY_ERROR",e[e.PROVIDER=4]="PROVIDER",e[e.VALUE=5]="VALUE",e[e.ADD_PEER=6]="ADD_PEER",e[e.DIAL_PEER=7]="DIAL_PEER",e[e.PATH_ENDED=8]="PATH_ENDED"})(Hu||(Hu={}));function bo(e){return new sn("/dht/record/"+z(e,"base32"),!1)}function $u(e){return{async put(t,r,n={}){try{let o=bo(t);try{let s=await e.get(o),a=Ye.deserialize(s);if(nt(a.value,r))return}catch(s){if(s.name!=="NotFoundError")throw s}let i=new Ye(t,r,new Date);n.onProgress?.(new mt("ipns:routing:datastore:put")),await e.put(o,i.serialize(),n)}catch(o){throw n.onProgress?.(new mt("ipns:routing:datastore:error",o)),o}},async get(t,r={}){try{let n=bo(t);r.onProgress?.(new mt("ipns:routing:datastore:get"));let o=await e.get(n,r),i=Ye.deserialize(o);return{record:i.value,created:i.timeReceived}}catch(n){throw r.onProgress?.(new mt("ipns:routing:datastore:error",n)),n}},async has(t,r={}){let n=bo(t);return e.has(n,r)},async delete(t,r){let n=bo(t);return e.delete(n,r)}}}var ds="/ipns/";function hs(e,t){return e.code===t}var me=xe("helia:ipns"),Gu=60*1e3,Yu=60*Gu,tp=48*Yu,ps=23*Yu,zu=BigInt(Gu)*5000000n,Zu={[Ot.prefix]:Ot,[G.prefix]:G},ms=class{routers;localStore;timeout;dns;log;constructor(t,r=[]){this.routers=[Mu(t.routing),...r],this.localStore=$u(t.datastore),this.dns=t.dns,this.log=t.logger.forComponent("helia:ipns")}async publish(t,r,n={}){try{let o=1n,i=Ge(t.publicKey.toMultihash());if(await this.localStore.has(i,n)){let{record:l}=await this.localStore.get(i,n);o=jt(l).sequence+1n}let s=n.ttl!=null?BigInt(n.ttl)*1000000n:zu,a=await Lu(t,r,o,n.lifetime??tp,{...n,ttlNs:s}),c=uo(a);return await this.localStore.put(i,c,n),n.offline!==!0&&await Promise.all(this.routers.map(async l=>{await l.put(i,c,n)})),a}catch(o){throw n.onProgress?.(new mt("ipns:publish:error",o)),o}}async resolve(t,r={}){let n=bs(t)?t.toMultihash():t,o=Ge(n),i=await this.#e(o,r);return{...await this.#t(i.value,r),record:i}}async resolveDNSLink(t,r={}){let n=await Ou(t,this.dns,this.log,r);return{...await this.#t(n.value,r),answer:n.answer}}republish(t={}){if(this.timeout!=null)throw new Error("Republish is already running");t.signal?.addEventListener("abort",()=>{clearTimeout(this.timeout)});async function r(){let n=Date.now();t.onProgress?.(new mt("ipns:republish:start"));let i=Date.now()-n,s=ps-i;s<0&&(s=t.interval??ps),setTimeout(()=>{r().catch(a=>{me.error("error republishing",a)})},s)}this.timeout=setTimeout(()=>{r().catch(n=>{me.error("error republishing",n)})},t.interval??ps)}async#t(t,r={}){let n=t.split("/");try{let o=n[1];if(o==="ipns"){let i=n[2],s=i.substring(0,1),a;if(s==="1"||s==="Q")a=G.decode(`z${i}`);else if(Zu[s]!=null)a=Zu[s].decode(i);else throw new mo(`Unsupported multibase prefix "${s}"`);let c;try{c=Wt(a)}catch{c=Y.decode(a).multihash}if(!hs(c,0)&&!hs(c,18))throw new yo(`Unsupported multihash codec "${c.code}"`);let{cid:l}=await this.resolve(c,r),u=n.slice(3).join("/");return{cid:l,path:u}}else if(o==="ipfs"){let i=Y.parse(n[2]),s=n.slice(3).join("/");return{cid:i,path:s}}}catch(o){me.error("error parsing ipfs path",o)}throw me.error("invalid ipfs path %s",t),new go("Invalid value")}async#e(t,r={}){let n=[];if(await this.localStore.has(t,r))if(me("record is present in the cache"),r.nocache!==!0)try{let{record:a,created:c}=await this.localStore.get(t,r);this.log("record retrieved from cache"),await nn(t,a),this.log("record was valid");let l=jt(a),u=Number((l.ttl??zu)/1000000n);if(c.getTime()+u>Date.now())return this.log("record TTL was valid"),l;if(r.offline===!0)return this.log("record TTL has been reached but we are resolving offline-only, returning record"),l;this.log("record TTL has been reached, searching routing for updates"),n.push(a)}catch(a){this.log("cached record was invalid",a),await this.localStore.delete(t,r)}else me("ignoring local cache due to nocache=true option");if(r.offline===!0)throw new Ar("Record was not present in the cache or has expired");me("did not have record locally");let i=0;if(await Promise.all(this.routers.map(async a=>{let c;try{c=await a.get(t,{...r,validate:!1})}catch(l){me.error("error finding IPNS record",l);return}try{await nn(t,c),n.push(c)}catch(l){i++,me.error("error finding IPNS record",l)}})),n.length===0)throw i>0?new po(`${i>1?`${i} records`:"Record"} found for routing key ${i>1?"were":"was"} invalid`):new Ar("Could not find record for routing key");let s=n[fo(t,n)];return await this.localStore.put(t,s,r),jt(s)}async republishRecord(t,r,n={}){let o;try{if(o=rn(r)?.toMultihash(),o==null)if(typeof t=="string"){t.startsWith(ds)&&(t=t.slice(ds.length));try{o=Hn(t).toMultihash()}catch(a){throw new Error(`Invalid string key: ${a.message}`)}}else o=t;if(o==null)throw new Error("No public key multihash found to determine the routing key");let i=Ge(o),s=uo(r);await nn(i,s),await this.localStore.put(i,s,n),n.offline!==!0&&await Promise.all(this.routers.map(async a=>{await a.put(i,s,n)}))}catch(i){throw n.onProgress?.(new mt("ipns:republish:error",{key:o,record:r,err:i})),i}}};function ep(e,{routers:t=[]}={}){return new ms(e,t)}return tf(rp);})();
|
|
4
4
|
/*! Bundled license information:
|
|
5
5
|
|
|
6
6
|
@noble/hashes/esm/utils.js:
|
|
7
7
|
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
8
8
|
|
|
9
|
-
@noble/curves/esm/
|
|
9
|
+
@noble/curves/esm/utils.js:
|
|
10
10
|
@noble/curves/esm/abstract/modular.js:
|
|
11
11
|
@noble/curves/esm/abstract/curve.js:
|
|
12
12
|
@noble/curves/esm/abstract/edwards.js:
|