@helia/ipns 8.2.3-a0266903 → 8.2.4-34d3ecd7

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 CHANGED
@@ -1,19 +1,19 @@
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 Bu=Object.create;var Yr=Object.defineProperty;var Iu=Object.getOwnPropertyDescriptor;var Cu=Object.getOwnPropertyNames;var _u=Object.getPrototypeOf,Du=Object.prototype.hasOwnProperty;var ji=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),yt=(e,t)=>{for(var r in t)Yr(e,r,{get:t[r],enumerable:!0})},Yi=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Cu(t))!Du.call(e,o)&&o!==r&&Yr(e,o,{get:()=>t[o],enumerable:!(n=Iu(t,o))||n.enumerable});return e};var Wr=(e,t,r)=>(r=e!=null?Bu(_u(e)):{},Yi(t||!e||!e.__esModule?Yr(r,"default",{value:e,enumerable:!0}):r,e)),Uu=e=>Yi(Yr({},"__esModule",{value:!0}),e);var Ln=ji((Vg,Ri)=>{var Mg=function(){typeof Ri<"u"&&(Ri.exports=A);var e=86400,t=3200,r=146097*t/400,n=e*r,o=1e3*n,i=864e13,s=4294967296,a=1e6,u="000000000",d=Math.trunc||function(g){var f=g-g%1;return f==0&&(g<0||g===0&&1/g!=1/0)?-0:f},c=A.prototype,l=(A.fromDate=function(g){return new A(+g)},A.fromInt64BE=K(0,1,2,3,0,4),A.fromInt64LE=K(3,2,1,0,4,0),A.fromString=function(h){var f,x=new A,h=(h+="").replace(/^\s*[+\-]?\d+/,function(S){var S=+S,B=1970+(S-1970)%400;return x.year=S-B,B}).replace(/(?:Z|([+\-]\d{2}):?(\d{2}))$/,function(p,S,B){return S<0&&(B*=-1),f=6e4*(60*+S+ +B),""}).replace(/\.\d+$/,function(p){return x.nano=+(p+u).substr(1,9),""}).split(/\D+/);if(1<h.length?h[1]--:h[1]=0,x.time=f=Date.UTC.apply(Date,h)-(f||0),isNaN(f))throw new TypeError("Invalid Date");return w(x)},A.fromTimeT=function(g){return U(g,0)},c.year=0,c.time=0,c.nano=0,c.addNano=function(g){return this.nano+=+g||0,this},c.getNano=function(){var g=w(this);return(g.time%1e3*a+ +g.nano+1e9)%1e9},c.getTimeT=function(){var f=w(this),g=Math.floor(f.time/1e3),f=f.year;return f&&(g+=f*r*e/t),g},c.getYear=function(){return this.toDate().getUTCFullYear()+this.year},c.toDate=function(){return C(w(this).time)},c.toJSON=function(){return this.toString().replace(/0{1,6}Z$/,"Z")},c.toString=function(g){var f=this,x=f.toDate(),h={H:function(){return R(x.getUTCHours())},L:function(){return N(x.getUTCMilliseconds(),3)},M:function(){return R(x.getUTCMinutes())},N:function(){return N(f.getNano(),9)},S:function(){return R(x.getUTCSeconds())},Y:function(){var p=f.getYear();return 999999<p?"+"+p:9999<p?"+"+N(p,6):0<=p?N(p,4):-999999<=p?"-"+N(-p,6):p},a:function(){return b[x.getUTCDay()]},b:function(){return y[x.getUTCMonth()]},d:function(){return R(x.getUTCDate())},e:function(){return function(p){return(9<p?"":" ")+(0|p)}(x.getUTCDate())},m:function(){return R(x.getUTCMonth()+1)}};return function p(S){return S.replace(/%./g,function(B){var I=B[1],v=T[I],I=h[I];return v?p(v):I?I():B})}(g||l)},c.writeInt64BE=D(0,1,2,3,0,4),c.writeInt64LE=D(3,2,1,0,4,0),"%Y-%m-%dT%H:%M:%S.%NZ"),y=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],b=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],T={"%":"%",F:"%Y-%m-%d",n:`
3
- `,R:"%H:%M",T:"%H:%M:%S",t:" ",X:"%T",Z:"GMT",z:"+0000"};return A;function A(g,f,x){var h=this;if(!(h instanceof A))return new A(g,f,x);h.time=+g||0,h.nano=+f||0,h.year=+x||0,w(h)}function w(g){var f,x,h,p=g.year,S=g.time,B=g.nano,v=((B<0||a<=B)&&(B-=(x=Math.floor(B/a))*a,S+=x,x=1),p%t);return(S<-i||i<S||v)&&((f=d(S/o))&&(p+=f*t,S-=f*o),(h=C(S)).setUTCFullYear(v+h.getUTCFullYear()),h=(S=+h)+(f=d((p-=v)/t))*o,f&&-i<=h&&h<=i&&(p-=f*t,S=h),x=1),x&&(g.year=p,g.time=S,g.nano=B),g}function C(g){var f=new Date(0);return f.setTime(g),f}function U(p,h){p=+p||0;var x=d((h=(h|0)*s)/n)+d(p/n),h=h%n+p%n,p=d(h/n);return p&&(x+=p,h-=p*n),new A(1e3*h,0,x*t)}function D(g,f,x,h,p,S){return function(v,I){var P=w(this);v=v||new Array(8),E(v,I|=0);var $=Math.floor(P.time/1e3),P=P.year*(r*e/t),k=d(P/s)+d($/s),P=P%s+$%s,$=Math.floor(P/s);return $&&(k+=$,P-=$*s),B(v,I+p,k),B(v,I+S,P),v};function B(v,I,k){v[I+g]=k>>24&255,v[I+f]=k>>16&255,v[I+x]=k>>8&255,v[I+h]=255&k}}function K(g,f,x,h,p,S){return function(v,I){E(v,I|=0);var k=B(v,I+p);return U(B(v,I+S),k)};function B(v,I){return 16777216*v[I+g]+(v[I+f]<<16|v[I+x]<<8|v[I+h])}}function E(g,f){if(g=g&&g.length,g==null)throw new TypeError("Invalid Buffer");if(g<f+8)throw new RangeError("Out of range")}function R(g){return(9<g?"":"0")+(0|g)}function N(g,f){return(u+(0|g)).substr(-f)}}()});var pu=ji((Kw,hu)=>{hu.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 Ch={};yt(Ch,{ipns:()=>Ih,ipnsSelector:()=>to,ipnsValidator:()=>Zr});function Wi(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 fo=Symbol.for("@libp2p/peer-id");var et=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Oe=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var dr=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}};var Xr=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},Me=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Ve=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var yo={};yt(yo,{base32:()=>ie,base32hex:()=>Vu,base32hexpad:()=>qu,base32hexpadupper:()=>$u,base32hexupper:()=>Hu,base32pad:()=>Ou,base32padupper:()=>Mu,base32upper:()=>Fu,base32z:()=>zu});var Nh=new Uint8Array(0);function Xi(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 Gt(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 Ji(e){return new TextEncoder().encode(e)}function Qi(e){return new TextDecoder().decode(e)}function Ru(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,u=e.charAt(0),d=Math.log(a)/Math.log(256),c=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 A=0,w=0,C=0,U=T.length;C!==U&&T[C]===0;)C++,A++;for(var D=(U-C)*c+1>>>0,K=new Uint8Array(D);C!==U;){for(var E=T[C],R=0,N=D-1;(E!==0||R<w)&&N!==-1;N--,R++)E+=256*K[N]>>>0,K[N]=E%a>>>0,E=E/a>>>0;if(E!==0)throw new Error("Non-zero carry");w=R,C++}for(var g=D-w;g!==D&&K[g]===0;)g++;for(var f=u.repeat(A);g<D;++g)f+=e.charAt(K[g]);return f}function y(T){if(typeof T!="string")throw new TypeError("Expected String");if(T.length===0)return new Uint8Array;var A=0;if(T[A]!==" "){for(var w=0,C=0;T[A]===u;)w++,A++;for(var U=(T.length-A)*d+1>>>0,D=new Uint8Array(U);T[A];){var K=r[T.charCodeAt(A)];if(K===255)return;for(var E=0,R=U-1;(K!==0||E<C)&&R!==-1;R--,E++)K+=a*D[R]>>>0,D[R]=K%256>>>0,K=K/256>>>0;if(K!==0)throw new Error("Non-zero carry");C=E,A++}if(T[A]!==" "){for(var N=U-C;N!==U&&D[N]===0;)N++;for(var g=new Uint8Array(w+(U-N)),f=w;N!==U;)g[f++]=D[N++];return g}}}function b(T){var A=y(T);if(A)return A;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:y,decode:b}}var Nu=Ru,Lu=Nu,es=Lu;var lo=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")}},ho=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 rs(this,t)}},po=class{decoders;constructor(t){this.decoders=t}or(t){return rs(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 rs(e,t){return new po({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var mo=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 lo(t,r,n),this.decoder=new ho(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function He({name:e,prefix:t,encode:r,decode:n}){return new mo(e,t,r,n)}function oe({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=es(r,e);return He({prefix:t,name:e,encode:n,decode:i=>Gt(o(i))})}function Pu(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,u=0;for(let d=0;d<o;++d){let c=t[e[d]];if(c===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|c,s+=r,s>=8&&(s-=8,i[u++]=255&a>>s)}if(s>=r||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function ku(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,i="",s=0,a=0;for(let u=0;u<e.length;++u)for(a=a<<8|e[u],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 Ku(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function X({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=Ku(n);return He({prefix:t,name:e,encode(i){return ku(i,n,r)},decode(i){return Pu(i,o,r,e)}})}var ie=X({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Fu=X({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ou=X({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Mu=X({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Vu=X({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Hu=X({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),qu=X({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),$u=X({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),zu=X({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var go={};yt(go,{base58btc:()=>z,base58flickr:()=>Gu});var z=oe({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Gu=oe({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var wo={};yt(wo,{base64:()=>xo,base64pad:()=>Zu,base64url:()=>ju,base64urlpad:()=>Yu});var xo=X({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Zu=X({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),ju=X({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Yu=X({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});function Wu(e,t){try{if(typeof e=="string"&&e.length>0)return Xu(e);if(typeof e=="number"&&isFinite(e))return t?.long?Qu(e):Ju(e);throw new Error("Value is not a string or number.")}catch(r){let n=tf(r)?`${r.message}. value=${JSON.stringify(e)}`:"An unknown error has occured.";throw new Error(n)}}function Xu(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 Qr=Wu;function Ju(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 Qu(e){let t=Math.abs(e);return t>=864e5?Jr(e,t,864e5,"day"):t>=36e5?Jr(e,t,36e5,"hour"):t>=6e4?Jr(e,t,6e4,"minute"):t>=1e3?Jr(e,t,1e3,"second"):`${e} ms`}function Jr(e,t,r,n){let o=t>=r*1.5;return`${Math.round(e/r)} ${n}${o?"s":""}`}function tf(e){return typeof e=="object"&&e!==null&&"message"in e}function bo(e){r.debug=r,r.default=r,r.coerce=u,r.disable=i,r.enable=o,r.enabled=s,r.humanize=Qr,r.destroy=d,Object.keys(e).forEach(c=>{r[c]=e[c]}),r.names=[],r.skips=[],r.formatters={};function t(c){let l=0;for(let y=0;y<c.length;y++)l=(l<<5)-l+c.charCodeAt(y),l|=0;return r.colors[Math.abs(l)%r.colors.length]}r.selectColor=t;function r(c){let l,y=null,b,T;function A(...w){if(!A.enabled)return;let C=A,U=Number(new Date),D=U-(l||U);C.diff=D,C.prev=l,C.curr=U,l=U,w[0]=r.coerce(w[0]),typeof w[0]!="string"&&w.unshift("%O");let K=0;w[0]=w[0].replace(/%([a-zA-Z%])/g,(R,N)=>{if(R==="%%")return"%";K++;let g=r.formatters[N];if(typeof g=="function"){let f=w[K];R=g.call(C,f),w.splice(K,1),K--}return R}),r.formatArgs.call(C,w),(C.log||r.log).apply(C,w)}return A.namespace=c,A.useColors=r.useColors(),A.color=r.selectColor(c),A.extend=n,A.destroy=r.destroy,Object.defineProperty(A,"enabled",{enumerable:!0,configurable:!1,get:()=>y!==null?y:(b!==r.namespaces&&(b=r.namespaces,T=r.enabled(c)),T),set:w=>{y=w}}),typeof r.init=="function"&&r.init(A),A}function n(c,l){let y=r(this.namespace+(typeof l>"u"?":":l)+c);return y.log=this.log,y}function o(c){r.save(c),r.namespaces=c,r.names=[],r.skips=[];let l,y=(typeof c=="string"?c:"").split(/[\s,]+/),b=y.length;for(l=0;l<b;l++)y[l]&&(c=y[l].replace(/\*/g,".*?"),c[0]==="-"?r.skips.push(new RegExp("^"+c.substr(1)+"$")):r.names.push(new RegExp("^"+c+"$")))}function i(){let c=[...r.names.map(a),...r.skips.map(a).map(l=>"-"+l)].join(",");return r.enable(""),c}function s(c){if(c[c.length-1]==="*")return!0;let l,y;for(l=0,y=r.skips.length;l<y;l++)if(r.skips[l].test(c))return!1;for(l=0,y=r.names.length;l<y;l++)if(r.names[l].test(c))return!0;return!1}function a(c){return c.toString().substring(2,c.toString().length-2).replace(/\.\*\?$/,"*")}function u(c){return c instanceof Error?c.stack??c.message:c}function d(){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 tn=cf(),ef=["#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 rf(){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 nf(e){if(e[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+e[0]+(this.useColors?"%c ":" ")+"+"+Qr(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 of=console.debug??console.log??(()=>{});function sf(e){try{e?tn?.setItem("debug",e):tn?.removeItem("debug")}catch{}}function af(){let e;try{e=tn?.getItem("debug")}catch{}return!e&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(e=globalThis.process.env.DEBUG),e}function cf(){try{return localStorage}catch{}}function uf(e){e.j=function(t){try{return JSON.stringify(t)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var ns=bo({formatArgs:nf,save:sf,load:af,useColors:rf,setupFormatters:uf,colors:ef,storage:tn,log:of});var gt=ns;gt.formatters.b=e=>e==null?"undefined":z.baseEncode(e);gt.formatters.t=e=>e==null?"undefined":ie.baseEncode(e);gt.formatters.m=e=>e==null?"undefined":xo.baseEncode(e);gt.formatters.p=e=>e==null?"undefined":e.toString();gt.formatters.c=e=>e==null?"undefined":e.toString();gt.formatters.k=e=>e==null?"undefined":e.toString();gt.formatters.a=e=>e==null?"undefined":e.toString();gt.formatters.e=e=>e==null?"undefined":os(e.stack)??os(e.message)??e.toString();function ff(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 se(e){let t=ff(`${e}:trace`);return gt.enabled(`${e}:trace`)&&gt.names.map(r=>r.toString()).find(r=>r.includes(":trace"))!=null&&(t=gt(`${e}:trace`)),Object.assign(gt(e),{error:gt(`${e}:error`),trace:t})}function os(e){if(e!=null&&(e=e.trim(),e.length!==0))return e}var Eo={};yt(Eo,{base36:()=>Ut,base36upper:()=>lf});var Ut=oe({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),lf=oe({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var df=as,is=128,hf=127,pf=~hf,mf=Math.pow(2,31);function as(e,t,r){t=t||[],r=r||0;for(var n=r;e>=mf;)t[r++]=e&255|is,e/=128;for(;e&pf;)t[r++]=e&255|is,e>>>=7;return t[r]=e|0,as.bytes=r-n+1,t}var yf=So,gf=128,ss=127;function So(e,n){var r=0,n=n||0,o=0,i=n,s,a=e.length;do{if(i>=a)throw So.bytes=0,new RangeError("Could not decode varint");s=e[i++],r+=o<28?(s&ss)<<o:(s&ss)*Math.pow(2,o),o+=7}while(s>=gf);return So.bytes=i-n,r}var xf=Math.pow(2,7),wf=Math.pow(2,14),bf=Math.pow(2,21),Ef=Math.pow(2,28),Sf=Math.pow(2,35),Af=Math.pow(2,42),vf=Math.pow(2,49),Tf=Math.pow(2,56),Bf=Math.pow(2,63),If=function(e){return e<xf?1:e<wf?2:e<bf?3:e<Ef?4:e<Sf?5:e<Af?6:e<vf?7:e<Tf?8:e<Bf?9:10},Cf={encode:df,decode:yf,encodingLength:If},_f=Cf,hr=_f;function pr(e,t=0){return[hr.decode(e,t),hr.decode.bytes]}function qe(e,t,r=0){return hr.encode(e,t,r),t}function $e(e){return hr.encodingLength(e)}function Rt(e,t){let r=t.byteLength,n=$e(e),o=n+$e(r),i=new Uint8Array(o+r);return qe(e,i,0),qe(r,i,n),i.set(t,o),new ze(e,r,t,i)}function Zt(e){let t=Gt(e),[r,n]=pr(t),[o,i]=pr(t.subarray(n)),s=t.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new ze(r,o,s,t)}function cs(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Xi(e.bytes,r.bytes)}}var ze=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function us(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return Uf(r,Ao(e),t??z.encoder);default:return Rf(r,Ao(e),t??ie.encoder)}}var fs=new WeakMap;function Ao(e){let t=fs.get(e);if(t==null){let r=new Map;return fs.set(e,r),r}return t}var G=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!==mr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Nf)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=Rt(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&&cs(t.multihash,n.multihash)}toString(t){return us(this,t)}toJSON(){return{"/":us(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??ls(n,o,i.bytes))}else if(r[Lf]===!0){let{version:n,multihash:o,code:i}=r,s=Zt(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!==mr)throw new Error(`Version 0 CID must use dag-pb (code: ${mr}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=ls(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,mr,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=Gt(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 ze(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]=pr(t.subarray(r));return r+=y,l},o=n(),i=mr;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(),u=n(),d=r+u,c=d-s;return{version:o,codec:i,multihashCode:a,digestSize:u,multihashSize:c,size:d}}static parse(t,r){let[n,o]=Df(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 Ao(i).set(n,t),i}};function Df(e,t){switch(e[0]){case"Q":{let r=t??z;return[z.prefix,r.decode(`${z.prefix}${e}`)]}case z.prefix:{let r=t??z;return[z.prefix,r.decode(e)]}case ie.prefix:{let r=t??ie;return[ie.prefix,r.decode(e)]}case Ut.prefix:{let r=t??Ut;return[Ut.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 Uf(e,t,r){let{prefix:n}=r;if(n!==z.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 Rf(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 mr=112,Nf=18;function ls(e,t,r){let n=$e(e),o=n+$e(t),i=new Uint8Array(o+r.byteLength);return qe(e,i,0),qe(t,i,n),i.set(r,o),i}var Lf=Symbol.for("@ipld/js-cid/CID");var vo={};yt(vo,{identity:()=>Nt});var ds=0,Pf="identity",hs=Gt;function kf(e){return Rt(ds,hs(e))}var Nt={code:ds,name:Pf,encode:hs,digest:kf};function J(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 It(e=0){return new Uint8Array(e)}function wt(e=0){return new Uint8Array(e)}function ce(e,t){t==null&&(t=e.reduce((o,i)=>o+i.length,0));let r=wt(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var ms=Symbol.for("@achingbrain/uint8arraylist");function ps(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 rn(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(rn(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(rn(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=ps(this.bufs,t);return r.buf[r.index]}set(t,r){let n=ps(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(rn(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 ce(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:ce(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,u=a+s.byteLength;if(o=u,t>=u)continue;let d=t>=a&&t<u,c=r>a&&r<=u;if(d&&c){if(t===a&&r===u){n.push(s);break}let l=t-a;n.push(s.subarray(l,l+(r-t)));break}if(d){if(t===0){n.push(s);continue}n.push(s.subarray(t-a));continue}if(c){if(r===u){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(!rn(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,u=this.byteLength-n.byteLength,d=n.byteLength-1,c;for(let l=r;l<=u;l+=c){c=0;for(let y=d;y>=0;y--){let b=this.get(l+y);if(n[y]!==b){c=Math.max(1,y-a[b]);break}}if(c===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=wt(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=It(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=It(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=It(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=wt(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=It(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=It(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=It(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=It(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=It(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(!J(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 To={};yt(To,{base10:()=>Kf});var Kf=oe({prefix:"9",name:"base10",alphabet:"0123456789"});var Bo={};yt(Bo,{base16:()=>Ff,base16upper:()=>Of});var Ff=X({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Of=X({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Io={};yt(Io,{base2:()=>Mf});var Mf=X({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Co={};yt(Co,{base256emoji:()=>zf});var ys=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}"),Vf=ys.reduce((e,t,r)=>(e[r]=t,e),[]),Hf=ys.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+=Vf[r],t),"")}function $f(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Hf[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var zf=He({prefix:"\u{1F680}",name:"base256emoji",encode:qf,decode:$f});var _o={};yt(_o,{base8:()=>Gf});var Gf=X({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Do={};yt(Do,{identity:()=>Zf});var Zf=He({prefix:"\0",name:"identity",encode:e=>Qi(e),decode:e=>Ji(e)});var _p=new TextEncoder,Dp=new TextDecoder;var No={};yt(No,{sha256:()=>yr,sha512:()=>Wf});function Ro({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?Rt(this.code,r):r.then(n=>Rt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function xs(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var yr=Ro({name:"sha2-256",code:18,encode:xs("SHA-256")}),Wf=Ro({name:"sha2-512",code:19,encode:xs("SHA-512")});var Lo={...Do,...Io,..._o,...To,...Bo,...yo,...Eo,...go,...wo,...Co},Hp={...No,...vo};function bs(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var ws=bs("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Po=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=wt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Xf={utf8:ws,"utf-8":ws,hex:Lo.base16,latin1:Po,ascii:Po,binary:Po,...Lo},nn=Xf;function M(e,t="utf8"){let r=nn[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function V(e,t="utf8"){let r=nn[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var Jf=parseInt("11111",2),ko=parseInt("10000000",2),Qf=parseInt("01111111",2),Es={0:gr,1:gr,2:tl,3:nl,4:ol,5:rl,6:el,16:gr,22:gr,48:gr};function jt(e,t={offset:0}){let r=e[t.offset]&Jf;if(t.offset++,Es[r]!=null)return Es[r](e,t);throw new Error("No decoder for tag "+r)}function xr(e,t){let r=0;if((e[t.offset]&ko)===ko){let n=e[t.offset]&Qf,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 gr(e,t){xr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=jt(e,t);if(n===null)break;r.push(n)}return r}function tl(e,t){let r=xr(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 el(e,t){let r=xr(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}`,u=[];for(;t.offset<n;){let d=e[t.offset];if(t.offset++,u.push(d&127),d<128){u.reverse();let c=0;for(let l=0;l<u.length;l++)c+=u[l]<<l*7;a+=`.${c}`,u=[]}}return a}function rl(e,t){return t.offset++,null}function nl(e,t){let r=xr(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 ol(e,t){let r=xr(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 Ko(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=il(e.byteLength);return new bt(Uint8Array.from([t.byteLength|ko]),t)}function xt(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]),Ko(t),t)}function on(e){let t=Uint8Array.from([0]),r=new bt(t,e);return new bt(Uint8Array.from([3]),Ko(r),r)}function ue(e,t=48){let r=new bt;for(let n of e)r.append(n);return new bt(Uint8Array.from([t]),Ko(r),r)}async function Ss(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 sl=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),al=Uint8Array.from([6,5,43,129,4,0,34]),cl=Uint8Array.from([6,5,43,129,4,0,35]),ul={ext:!0,kty:"EC",crv:"P-256"},fl={ext:!0,kty:"EC",crv:"P-384"},ll={ext:!0,kty:"EC",crv:"P-521"},Fo=32,Oo=48,Mo=66;function Vo(e){let t=jt(e);return As(t)}function As(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Fo*2+1)return n=V(t.subarray(r,r+Fo),"base64url"),o=V(t.subarray(r+Fo),"base64url"),new Ge({...ul,key_ops:["verify"],x:n,y:o});if(t.byteLength===Oo*2+1)return n=V(t.subarray(r,r+Oo),"base64url"),o=V(t.subarray(r+Oo),"base64url"),new Ge({...fl,key_ops:["verify"],x:n,y:o});if(t.byteLength===Mo*2+1)return n=V(t.subarray(r,r+Mo),"base64url"),o=V(t.subarray(r+Mo),"base64url"),new Ge({...ll,key_ops:["verify"],x:n,y:o});throw new et(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function vs(e){return ue([xt(Uint8Array.from([1])),ue([dl(e.crv)],160),ue([on(new bt(Uint8Array.from([4]),M(e.x??"","base64url"),M(e.y??"","base64url")))],161)]).subarray()}function dl(e){if(e==="P-256")return sl;if(e==="P-384")return al;if(e==="P-521")return cl;throw new et(`Invalid curve ${e}`)}var Ge=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=vs(this.jwk)),this._raw}toMultihash(){return Nt.digest(fe(this))}toCID(){return G.createV1(114,this.toMultihash())}toString(){return z.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:J(this.raw,t.raw)}async verify(t,r,n){return Ss(this.jwk,r,t,n)}};var ve=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function je(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function wr(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function ut(e,...t){if(!je(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 Bs(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");wr(e.outputLen),wr(e.blockLen)}function Ye(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 Is(e,t){ut(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function Wt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function sn(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Lt(e,t){return e<<32-t|e>>>t}var Cs=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",hl=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Mt(e){if(ut(e),Cs)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=hl[e[r]];return t}var Yt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Ts(e){if(e>=Yt._0&&e<=Yt._9)return e-Yt._0;if(e>=Yt.A&&e<=Yt.F)return e-(Yt.A-10);if(e>=Yt.a&&e<=Yt.f)return e-(Yt.a-10)}function We(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(Cs)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=Ts(e.charCodeAt(i)),a=Ts(e.charCodeAt(i+1));if(s===void 0||a===void 0){let u=e[i]+e[i+1];throw new Error('hex string expected, got non-hex character "'+u+'" at index '+i)}n[o]=s*16+a}return n}function _s(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function br(e){return typeof e=="string"&&(e=_s(e)),ut(e),e}function Et(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];ut(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 Ze=class{};function Ho(e){let t=n=>e().update(br(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function Er(e=32){if(ve&&typeof ve.getRandomValues=="function")return ve.getRandomValues(new Uint8Array(e));if(ve&&typeof ve.randomBytes=="function")return Uint8Array.from(ve.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),u=n?4:0,d=n?0:4;e.setUint32(t+u,s,n),e.setUint32(t+d,a,n)}function Ds(e,t,r){return e&t^~e&r}function Us(e,t,r){return e&t^e&r^t&r}var Sr=class extends Ze{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=sn(this.buffer)}update(t){Ye(this),t=br(t),ut(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 u=sn(t);for(;o<=i-s;s+=o)this.process(u,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){Ye(this),Is(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;r[s++]=128,Wt(this.buffer.subarray(s)),this.padOffset>o-s&&(this.process(n,0),s=0);for(let l=s;l<o;l++)r[l]=0;pl(n,o-8,BigInt(this.length*8),i),this.process(n,0);let a=sn(t),u=this.outputLen;if(u%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let d=u/4,c=this.get();if(d>c.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<d;l++)a.setUint32(4*l,c[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()}},Xt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var it=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var an=BigInt(4294967295),Rs=BigInt(32);function ml(e,t=!1){return t?{h:Number(e&an),l:Number(e>>Rs&an)}:{h:Number(e>>Rs&an)|0,l:Number(e&an)|0}}function Ns(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}=ml(e[i],t);[n[i],o[i]]=[s,a]}return[n,o]}var qo=(e,t,r)=>e>>>r,$o=(e,t,r)=>e<<32-r|t>>>r,Te=(e,t,r)=>e>>>r|t<<32-r,Be=(e,t,r)=>e<<32-r|t>>>r,Ar=(e,t,r)=>e<<64-r|t>>>r-32,vr=(e,t,r)=>e>>>r-32|t<<64-r;function Vt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var Ls=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Ps=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,ks=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),Ks=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,Fs=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Os=(e,t,r,n,o,i)=>t+r+n+o+i+(e/2**32|0)|0;var gl=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]),le=new Uint32Array(64),cn=class extends Sr{constructor(t=32){super(64,t,8,!1),this.A=Xt[0]|0,this.B=Xt[1]|0,this.C=Xt[2]|0,this.D=Xt[3]|0,this.E=Xt[4]|0,this.F=Xt[5]|0,this.G=Xt[6]|0,this.H=Xt[7]|0}get(){let{A:t,B:r,C:n,D:o,E:i,F:s,G:a,H:u}=this;return[t,r,n,o,i,s,a,u]}set(t,r,n,o,i,s,a,u){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=u|0}process(t,r){for(let l=0;l<16;l++,r+=4)le[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let y=le[l-15],b=le[l-2],T=Lt(y,7)^Lt(y,18)^y>>>3,A=Lt(b,17)^Lt(b,19)^b>>>10;le[l]=A+le[l-7]+T+le[l-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:u,G:d,H:c}=this;for(let l=0;l<64;l++){let y=Lt(a,6)^Lt(a,11)^Lt(a,25),b=c+y+Ds(a,u,d)+gl[l]+le[l]|0,A=(Lt(n,2)^Lt(n,13)^Lt(n,22))+Us(n,o,i)|0;c=d,d=u,u=a,a=s+b|0,s=i,i=o,o=n,n=b+A|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,u=u+this.F|0,d=d+this.G|0,c=c+this.H|0,this.set(n,o,i,s,a,u,d,c)}roundClean(){Wt(le)}destroy(){this.set(0,0,0,0,0,0,0,0),Wt(this.buffer)}};var Ms=Ns(["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))),xl=Ms[0],wl=Ms[1],de=new Uint32Array(80),he=new Uint32Array(80),zo=class extends Sr{constructor(t=64){super(128,t,16,!1),this.Ah=it[0]|0,this.Al=it[1]|0,this.Bh=it[2]|0,this.Bl=it[3]|0,this.Ch=it[4]|0,this.Cl=it[5]|0,this.Dh=it[6]|0,this.Dl=it[7]|0,this.Eh=it[8]|0,this.El=it[9]|0,this.Fh=it[10]|0,this.Fl=it[11]|0,this.Gh=it[12]|0,this.Gl=it[13]|0,this.Hh=it[14]|0,this.Hl=it[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:i,Cl:s,Dh:a,Dl:u,Eh:d,El:c,Fh:l,Fl:y,Gh:b,Gl:T,Hh:A,Hl:w}=this;return[t,r,n,o,i,s,a,u,d,c,l,y,b,T,A,w]}set(t,r,n,o,i,s,a,u,d,c,l,y,b,T,A,w){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=u|0,this.Eh=d|0,this.El=c|0,this.Fh=l|0,this.Fl=y|0,this.Gh=b|0,this.Gl=T|0,this.Hh=A|0,this.Hl=w|0}process(t,r){for(let D=0;D<16;D++,r+=4)de[D]=t.getUint32(r),he[D]=t.getUint32(r+=4);for(let D=16;D<80;D++){let K=de[D-15]|0,E=he[D-15]|0,R=Te(K,E,1)^Te(K,E,8)^qo(K,E,7),N=Be(K,E,1)^Be(K,E,8)^$o(K,E,7),g=de[D-2]|0,f=he[D-2]|0,x=Te(g,f,19)^Ar(g,f,61)^qo(g,f,6),h=Be(g,f,19)^vr(g,f,61)^$o(g,f,6),p=ks(N,h,he[D-7],he[D-16]),S=Ks(p,R,x,de[D-7],de[D-16]);de[D]=S|0,he[D]=p|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:u,Dh:d,Dl:c,Eh:l,El:y,Fh:b,Fl:T,Gh:A,Gl:w,Hh:C,Hl:U}=this;for(let D=0;D<80;D++){let K=Te(l,y,14)^Te(l,y,18)^Ar(l,y,41),E=Be(l,y,14)^Be(l,y,18)^vr(l,y,41),R=l&b^~l&A,N=y&T^~y&w,g=Fs(U,E,N,wl[D],he[D]),f=Os(g,C,K,R,xl[D],de[D]),x=g|0,h=Te(n,o,28)^Ar(n,o,34)^Ar(n,o,39),p=Be(n,o,28)^vr(n,o,34)^vr(n,o,39),S=n&i^n&a^i&a,B=o&s^o&u^s&u;C=A|0,U=w|0,A=b|0,w=T|0,b=l|0,T=y|0,{h:l,l:y}=Vt(d|0,c|0,f|0,x|0),d=a|0,c=u|0,a=i|0,u=s|0,i=n|0,s=o|0;let v=Ls(x,p,B);n=Ps(v,f,h,S),o=v|0}({h:n,l:o}=Vt(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=Vt(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:u}=Vt(this.Ch|0,this.Cl|0,a|0,u|0),{h:d,l:c}=Vt(this.Dh|0,this.Dl|0,d|0,c|0),{h:l,l:y}=Vt(this.Eh|0,this.El|0,l|0,y|0),{h:b,l:T}=Vt(this.Fh|0,this.Fl|0,b|0,T|0),{h:A,l:w}=Vt(this.Gh|0,this.Gl|0,A|0,w|0),{h:C,l:U}=Vt(this.Hh|0,this.Hl|0,C|0,U|0),this.set(n,o,i,s,a,u,d,c,l,y,b,T,A,w,C,U)}roundClean(){Wt(de,he)}destroy(){Wt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var un=Ho(()=>new cn);var Vs=Ho(()=>new zo);var jo=BigInt(0),Zo=BigInt(1);function Jt(e,t){if(typeof t!="boolean")throw new Error(e+" boolean expected, got "+t)}function Tr(e){let t=e.toString(16);return t.length&1?"0"+t:t}function Hs(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?jo:BigInt("0x"+e)}function Xe(e){return Hs(Mt(e))}function Ie(e){return ut(e),Hs(Mt(Uint8Array.from(e).reverse()))}function fn(e,t){return We(e.toString(16).padStart(t*2,"0"))}function Je(e,t){return fn(e,t).reverse()}function j(e,t,r){let n;if(typeof t=="string")try{n=We(t)}catch(i){throw new Error(e+" must be hex string or Uint8Array, cause: "+i)}else if(je(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}var Go=e=>typeof e=="bigint"&&jo<=e;function qs(e,t,r){return Go(e)&&Go(t)&&Go(r)&&t<=e&&e<r}function pe(e,t,r,n){if(!qs(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function $s(e){let t;for(t=0;e>jo;e>>=Zo,t+=1);return t}var Ce=e=>(Zo<<BigInt(e))-Zo;function zs(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=b=>new Uint8Array(b),o=b=>Uint8Array.of(b),i=n(e),s=n(e),a=0,u=()=>{i.fill(1),s.fill(0),a=0},d=(...b)=>r(s,i,...b),c=(b=n(0))=>{s=d(o(0),b),i=d(),b.length!==0&&(s=d(o(1),b),i=d())},l=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let b=0,T=[];for(;b<t;){i=d();let A=i.slice();T.push(A),b+=i.length}return Et(...T)};return(b,T)=>{u(),c(b);let A;for(;!(A=T(l()));)c();return u(),A}}function me(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 u=typeof a;if(u!==i||a===null)throw new Error(`param "${o}" is invalid: expected ${i}, got ${u}`)}Object.entries(t).forEach(([o,i])=>n(o,i,!1)),Object.entries(r).forEach(([o,i])=>n(o,i,!0))}function Qe(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 ht=BigInt(0),nt=BigInt(1),_e=BigInt(2),bl=BigInt(3),js=BigInt(4),Ys=BigInt(5),Ws=BigInt(8);function W(e,t){let r=e%t;return r>=ht?r:t+r}function Y(e,t,r){let n=e;for(;t-- >ht;)n*=n,n%=r;return n}function Gs(e,t){if(e===ht)throw new Error("invert: expected non-zero number");if(t<=ht)throw new Error("invert: expected positive modulus, got "+t);let r=W(e,t),n=t,o=ht,i=nt,s=nt,a=ht;for(;r!==ht;){let d=n/r,c=n%r,l=o-s*d,y=i-a*d;n=r,r=c,o=s,i=a,s=l,a=y}if(n!==nt)throw new Error("invert: does not exist");return W(o,t)}function Xs(e,t){let r=(e.ORDER+nt)/js,n=e.pow(t,r);if(!e.eql(e.sqr(n),t))throw new Error("Cannot find square root");return n}function El(e,t){let r=(e.ORDER-Ys)/Ws,n=e.mul(t,_e),o=e.pow(n,r),i=e.mul(t,o),s=e.mul(e.mul(i,_e),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 Sl(e){if(e<BigInt(3))throw new Error("sqrt is not defined for small field");let t=e-nt,r=0;for(;t%_e===ht;)t/=_e,r++;let n=_e,o=Pt(e);for(;Zs(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Xs;let i=o.pow(n,t),s=(t+nt)/_e;return function(u,d){if(u.is0(d))return d;if(Zs(u,d)!==1)throw new Error("Cannot find square root");let c=r,l=u.mul(u.ONE,i),y=u.pow(d,t),b=u.pow(d,s);for(;!u.eql(y,u.ONE);){if(u.is0(y))return u.ZERO;let T=1,A=u.sqr(y);for(;!u.eql(A,u.ONE);)if(T++,A=u.sqr(A),T===c)throw new Error("Cannot find square root");let w=nt<<BigInt(c-T-1),C=u.pow(l,w);c=T,l=u.sqr(C),y=u.mul(y,l),b=u.mul(b,C)}return b}}function Al(e){return e%js===bl?Xs:e%Ws===Ys?El:Sl(e)}var Js=(e,t)=>(W(e,t)&nt)===nt,vl=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Yo(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=vl.reduce((n,o)=>(n[o]="function",n),t);return me(e,r),e}function Tl(e,t,r){if(r<ht)throw new Error("invalid exponent, negatives unsupported");if(r===ht)return e.ONE;if(r===nt)return t;let n=e.ONE,o=t;for(;r>ht;)r&nt&&(n=e.mul(n,o)),o=e.sqr(o),r>>=nt;return n}function Br(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((s,a,u)=>e.is0(a)?s:(n[u]=s,e.mul(s,a)),e.ONE),i=e.inv(o);return t.reduceRight((s,a,u)=>e.is0(a)?s:(n[u]=e.mul(s,n[u]),e.mul(s,a)),i),n}function Zs(e,t){let r=(e.ORDER-nt)/_e,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 Qs(e,t){t!==void 0&&wr(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function Pt(e,t,r=!1,n={}){if(e<=ht)throw new Error("invalid field: expected ORDER > 0, got "+e);let o,i;if(typeof t=="object"&&t!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let c=t;c.BITS&&(o=c.BITS),c.sqrt&&(i=c.sqrt),typeof c.isLE=="boolean"&&(r=c.isLE)}else typeof t=="number"&&(o=t),n.sqrt&&(i=n.sqrt);let{nBitLength:s,nByteLength:a}=Qs(e,o);if(a>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let u,d=Object.freeze({ORDER:e,isLE:r,BITS:s,BYTES:a,MASK:Ce(s),ZERO:ht,ONE:nt,create:c=>W(c,e),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return ht<=c&&c<e},is0:c=>c===ht,isValidNot0:c=>!d.is0(c)&&d.isValid(c),isOdd:c=>(c&nt)===nt,neg:c=>W(-c,e),eql:(c,l)=>c===l,sqr:c=>W(c*c,e),add:(c,l)=>W(c+l,e),sub:(c,l)=>W(c-l,e),mul:(c,l)=>W(c*l,e),pow:(c,l)=>Tl(d,c,l),div:(c,l)=>W(c*Gs(l,e),e),sqrN:c=>c*c,addN:(c,l)=>c+l,subN:(c,l)=>c-l,mulN:(c,l)=>c*l,inv:c=>Gs(c,e),sqrt:i||(c=>(u||(u=Al(e)),u(d,c))),toBytes:c=>r?Je(c,a):fn(c,a),fromBytes:c=>{if(c.length!==a)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+c.length);return r?Ie(c):Xe(c)},invertBatch:c=>Br(d,c),cmov:(c,l,y)=>y?l:c});return Object.freeze(d)}function ta(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 Wo(e){let t=ta(e);return t+Math.ceil(t/2)}function ea(e,t,r=!1){let n=e.length,o=ta(t),i=Wo(t);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=r?Ie(e):Xe(e),a=W(s,t-nt)+nt;return r?Je(a,o):fn(a,o)}var er=BigInt(0),De=BigInt(1);function tr(e,t){let r=t.negate();return e?r:t}function ln(e,t,r){let n=t==="pz"?s=>s.pz:s=>s.ez,o=Br(e.Fp,r.map(n));return r.map((s,a)=>s.toAffine(o[a])).map(e.fromAffine)}function ia(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Xo(e,t){ia(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,i=Ce(e),s=BigInt(e);return{windows:r,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function ra(e,t,r){let{windowSize:n,mask:o,maxNumber:i,shiftBy:s}=r,a=Number(e&o),u=e>>s;a>n&&(a-=i,u+=De);let d=t*n,c=d+Math.abs(a)-1,l=a===0,y=a<0,b=t%2!==0;return{nextN:u,offset:c,isZero:l,isNeg:y,isNegF:b,offsetF:d}}function Bl(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 Il(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 Jo=new WeakMap,sa=new WeakMap;function Qo(e){return sa.get(e)||1}function na(e){if(e!==er)throw new Error("invalid wNAF")}function dn(e,t){return{constTimeNegate:tr,hasPrecomputes(r){return Qo(r)!==1},unsafeLadder(r,n,o=e.ZERO){let i=r;for(;n>er;)n&De&&(o=o.add(i)),i=i.double(),n>>=De;return o},precomputeWindow(r,n){let{windows:o,windowSize:i}=Xo(n,t),s=[],a=r,u=a;for(let d=0;d<o;d++){u=a,s.push(u);for(let c=1;c<i;c++)u=u.add(a),s.push(u);a=u.double()}return s},wNAF(r,n,o){let i=e.ZERO,s=e.BASE,a=Xo(r,t);for(let u=0;u<a.windows;u++){let{nextN:d,offset:c,isZero:l,isNeg:y,isNegF:b,offsetF:T}=ra(o,u,a);o=d,l?s=s.add(tr(b,n[T])):i=i.add(tr(y,n[c]))}return na(o),{p:i,f:s}},wNAFUnsafe(r,n,o,i=e.ZERO){let s=Xo(r,t);for(let a=0;a<s.windows&&o!==er;a++){let{nextN:u,offset:d,isZero:c,isNeg:l}=ra(o,a,s);if(o=u,!c){let y=n[d];i=i.add(l?y.negate():y)}}return na(o),i},getPrecomputes(r,n,o){let i=Jo.get(n);return i||(i=this.precomputeWindow(n,r),r!==1&&(typeof o=="function"&&(i=o(i)),Jo.set(n,i))),i},wNAFCached(r,n,o){let i=Qo(r);return this.wNAF(i,this.getPrecomputes(i,r,o),n)},wNAFCachedUnsafe(r,n,o,i){let s=Qo(r);return s===1?this.unsafeLadder(r,n,i):this.wNAFUnsafe(s,this.getPrecomputes(s,r,o),n,i)},setWindowSize(r,n){ia(n,t),sa.set(r,n),Jo.delete(r)}}}function aa(e,t,r,n){let o=t,i=e.ZERO,s=e.ZERO;for(;r>er||n>er;)r&De&&(i=i.add(o)),n&De&&(s=s.add(o)),o=o.double(),r>>=De,n>>=De;return{p1:i,p2:s}}function hn(e,t,r,n){Bl(r,e),Il(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=$s(BigInt(o)),u=1;a>12?u=a-3:a>4?u=a-2:a>0&&(u=2);let d=Ce(u),c=new Array(Number(d)+1).fill(s),l=Math.floor((t.BITS-1)/u)*u,y=s;for(let b=l;b>=0;b-=u){c.fill(s);for(let A=0;A<i;A++){let w=n[A],C=Number(w>>BigInt(b)&d);c[C]=c[C].add(r[A])}let T=s;for(let A=c.length-1,w=s;A>0;A--)w=w.add(c[A]),T=T.add(w);if(y=y.add(T),b!==0)for(let A=0;A<u;A++)y=y.double()}return y}function oa(e,t){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Yo(t),t}else return Pt(e)}function pn(e,t,r={}){if(!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let a of["p","n","h"]){let u=t[a];if(!(typeof u=="bigint"&&u>er))throw new Error(`CURVE.${a} must be positive bigint`)}let n=oa(t.p,r.Fp),o=oa(t.n,r.Fn),s=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let a of s)if(!n.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return{Fp:n,Fn:o}}var Ht=BigInt(0),pt=BigInt(1),ti=BigInt(2),Cl=BigInt(8),_l={zip215:!0};function Dl(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 Ul(e,t={}){let{Fp:r,Fn:n}=pn("edwards",e,t),{h:o,n:i}=e;me(t,{},{uvRatio:"function"});let s=ti<<BigInt(n.BYTES*8)-pt,a=A=>r.create(A),u=t.uvRatio||((A,w)=>{try{return{isValid:!0,value:r.sqrt(r.div(A,w))}}catch{return{isValid:!1,value:Ht}}});if(!Dl(r,e,e.Gx,e.Gy))throw new Error("bad curve params: generator point");function d(A,w,C=!1){let U=C?pt:Ht;return pe("coordinate "+A,w,U,s),w}function c(A){if(!(A instanceof b))throw new Error("ExtendedPoint expected")}let l=Qe((A,w)=>{let{ex:C,ey:U,ez:D}=A,K=A.is0();w==null&&(w=K?Cl:r.inv(D));let E=a(C*w),R=a(U*w),N=a(D*w);if(K)return{x:Ht,y:pt};if(N!==pt)throw new Error("invZ was invalid");return{x:E,y:R}}),y=Qe(A=>{let{a:w,d:C}=e;if(A.is0())throw new Error("bad point: ZERO");let{ex:U,ey:D,ez:K,et:E}=A,R=a(U*U),N=a(D*D),g=a(K*K),f=a(g*g),x=a(R*w),h=a(g*a(x+N)),p=a(f+a(C*a(R*N)));if(h!==p)throw new Error("bad point: equation left != right (1)");let S=a(U*D),B=a(K*E);if(S!==B)throw new Error("bad point: equation left != right (2)");return!0});class b{constructor(w,C,U,D){this.ex=d("x",w),this.ey=d("y",C),this.ez=d("z",U,!0),this.et=d("t",D),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(w){if(w instanceof b)throw new Error("extended point not allowed");let{x:C,y:U}=w||{};return d("x",C),d("y",U),new b(C,U,pt,a(C*U))}static normalizeZ(w){return ln(b,"ez",w)}static msm(w,C){return hn(b,n,w,C)}_setWindowSize(w){this.precompute(w)}precompute(w=8,C=!0){return T.setWindowSize(this,w),C||this.multiply(ti),this}assertValidity(){y(this)}equals(w){c(w);let{ex:C,ey:U,ez:D}=this,{ex:K,ey:E,ez:R}=w,N=a(C*R),g=a(K*D),f=a(U*R),x=a(E*D);return N===g&&f===x}is0(){return this.equals(b.ZERO)}negate(){return new b(a(-this.ex),this.ey,this.ez,a(-this.et))}double(){let{a:w}=e,{ex:C,ey:U,ez:D}=this,K=a(C*C),E=a(U*U),R=a(ti*a(D*D)),N=a(w*K),g=C+U,f=a(a(g*g)-K-E),x=N+E,h=x-R,p=N-E,S=a(f*h),B=a(x*p),v=a(f*p),I=a(h*x);return new b(S,B,I,v)}add(w){c(w);let{a:C,d:U}=e,{ex:D,ey:K,ez:E,et:R}=this,{ex:N,ey:g,ez:f,et:x}=w,h=a(D*N),p=a(K*g),S=a(R*U*x),B=a(E*f),v=a((D+K)*(N+g)-h-p),I=B-S,k=B+S,P=a(p-C*h),$=a(v*I),q=a(k*P),O=a(v*P),tt=a(I*k);return new b($,q,tt,O)}subtract(w){return this.add(w.negate())}multiply(w){let C=w;pe("scalar",C,pt,i);let{p:U,f:D}=T.wNAFCached(this,C,b.normalizeZ);return b.normalizeZ([U,D])[0]}multiplyUnsafe(w,C=b.ZERO){let U=w;return pe("scalar",U,Ht,i),U===Ht?b.ZERO:this.is0()||U===pt?this:T.wNAFCachedUnsafe(this,U,b.normalizeZ,C)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}isTorsionFree(){return T.wNAFCachedUnsafe(this,i).is0()}toAffine(w){return l(this,w)}clearCofactor(){return o===pt?this:this.multiplyUnsafe(o)}static fromBytes(w,C=!1){return ut(w),this.fromHex(w,C)}static fromHex(w,C=!1){let{d:U,a:D}=e,K=r.BYTES;w=j("pointHex",w,K),Jt("zip215",C);let E=w.slice(),R=w[K-1];E[K-1]=R&-129;let N=Ie(E),g=C?s:r.ORDER;pe("pointHex.y",N,Ht,g);let f=a(N*N),x=a(f-pt),h=a(U*f-D),{isValid:p,value:S}=u(x,h);if(!p)throw new Error("Point.fromHex: invalid y coordinate");let B=(S&pt)===pt,v=(R&128)!==0;if(!C&&S===Ht&&v)throw new Error("Point.fromHex: x=0 and x_0=1");return v!==B&&(S=a(-S)),b.fromAffine({x:S,y:N})}static fromPrivateScalar(w){return b.BASE.multiply(w)}toBytes(){let{x:w,y:C}=this.toAffine(),U=Je(C,r.BYTES);return U[U.length-1]|=w&pt?128:0,U}toRawBytes(){return this.toBytes()}toHex(){return Mt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}b.BASE=new b(e.Gx,e.Gy,pt,a(e.Gx*e.Gy)),b.ZERO=new b(Ht,pt,pt,Ht),b.Fp=r,b.Fn=n;let T=dn(b,n.BYTES*8);return b}function Rl(e,t){me(t,{hash:"function"},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:r,hash:n}=t,{BASE:o,Fp:i,Fn:s}=e,a=s.ORDER,u=t.randomBytes||Er,d=t.adjustScalarBytes||(E=>E),c=t.domain||((E,R,N)=>{if(Jt("phflag",N),R.length||N)throw new Error("Contexts/pre-hash are not supported");return E});function l(E){return s.create(E)}function y(E){return l(Ie(E))}function b(E){let R=i.BYTES;E=j("private key",E,R);let N=j("hashed private key",n(E),2*R),g=d(N.slice(0,R)),f=N.slice(R,2*R),x=y(g);return{head:g,prefix:f,scalar:x}}function T(E){let{head:R,prefix:N,scalar:g}=b(E),f=o.multiply(g),x=f.toBytes();return{head:R,prefix:N,scalar:g,point:f,pointBytes:x}}function A(E){return T(E).pointBytes}function w(E=Uint8Array.of(),...R){let N=Et(...R);return y(n(c(N,j("context",E),!!r)))}function C(E,R,N={}){E=j("message",E),r&&(E=r(E));let{prefix:g,scalar:f,pointBytes:x}=T(R),h=w(N.context,g,E),p=o.multiply(h).toBytes(),S=w(N.context,p,x,E),B=l(h+S*f);pe("signature.s",B,Ht,a);let v=i.BYTES,I=Et(p,Je(B,v));return j("result",I,v*2)}let U=_l;function D(E,R,N,g=U){let{context:f,zip215:x}=g,h=i.BYTES;E=j("signature",E,2*h),R=j("message",R),N=j("publicKey",N,h),x!==void 0&&Jt("zip215",x),r&&(R=r(R));let p=Ie(E.slice(h,2*h)),S,B,v;try{S=e.fromHex(N,x),B=e.fromHex(E.slice(0,h),x),v=o.multiplyUnsafe(p)}catch{return!1}if(!x&&S.isSmallOrder())return!1;let I=w(f,B.toBytes(),S.toBytes(),R);return B.add(S.multiplyUnsafe(I)).subtract(v).clearCofactor().is0()}return o.precompute(8),{getPublicKey:A,sign:C,verify:D,utils:{getExtendedPublicKey:T,randomPrivateKey:()=>u(i.BYTES),precompute(E=8,R=e.BASE){return R.precompute(E,!1)}},Point:e}}function Nl(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=Pt(t.n,e.nBitLength,!0),o={Fp:r,Fn:n,uvRatio:e.uvRatio},i={hash:e.hash,randomBytes:e.randomBytes,adjustScalarBytes:e.adjustScalarBytes,domain:e.domain,prehash:e.prehash,mapToCurve:e.mapToCurve};return{CURVE:t,curveOpts:o,eddsaOpts:i}}function Ll(e,t){return Object.assign({},t,{ExtendedPoint:t.Point,CURVE:e})}function ca(e){let{CURVE:t,curveOpts:r,eddsaOpts:n}=Nl(e),o=Ul(t,r),i=Rl(o,n);return Ll(e,i)}var Z0=BigInt(0),Pl=BigInt(1),ua=BigInt(2),j0=BigInt(3),kl=BigInt(5),Kl=BigInt(8),mn={p:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Kl,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Fl(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),i=mn.p,a=e*e%i*e%i,u=Y(a,ua,i)*a%i,d=Y(u,Pl,i)*e%i,c=Y(d,kl,i)*d%i,l=Y(c,t,i)*c%i,y=Y(l,r,i)*l%i,b=Y(y,n,i)*y%i,T=Y(b,o,i)*b%i,A=Y(T,o,i)*b%i,w=Y(A,t,i)*c%i;return{pow_p_5_8:Y(w,ua,i)*e%i,b2:a}}function Ol(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var fa=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Ml(e,t){let r=mn.p,n=W(t*t*t,r),o=W(n*n*t,r),i=Fl(e*o).pow_p_5_8,s=W(e*n*i,r),a=W(t*s*s,r),u=s,d=W(s*fa,r),c=a===e,l=a===W(-e,r),y=a===W(-e*fa,r);return c&&(s=u),(l||y)&&(s=d),Js(s,r)&&(s=W(-s,r)),{isValid:c||l,value:s}}var Vl=Pt(mn.p,void 0,!0),Hl={...mn,Fp:Vl,hash:Vs,adjustScalarBytes:Ol,uvRatio:Ml},la=ca(Hl);var Ir=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},yn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var da={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new yn("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 Ct=da;var gn=32;var ei,ql=(async()=>{try{return await Ct.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function $l(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await Ct.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await Ct.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 zl(e,t,r){return la.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function ha(e,t,r){return ei==null&&(ei=await ql),ei?$l(e,t,r):zl(e,t,r)}function xn(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var wn=class{type="Ed25519";raw;constructor(t){this.raw=ri(t,gn)}toMultihash(){return Nt.digest(fe(this))}toCID(){return G.createV1(114,this.toMultihash())}toString(){return z.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:J(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=ha(this.raw,r,t);return xn(o)?o.then(i=>(n?.signal?.throwIfAborted(),i)):o}};function ni(e){return e=ri(e,gn),new wn(e)}function ri(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new et(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var Zl=Math.pow(2,7),jl=Math.pow(2,14),Yl=Math.pow(2,21),ma=Math.pow(2,28),ya=Math.pow(2,35),ga=Math.pow(2,42),xa=Math.pow(2,49),mt=128,ye=127;function Cr(e){if(e<Zl)return 1;if(e<jl)return 2;if(e<Yl)return 3;if(e<ma)return 4;if(e<ya)return 5;if(e<ga)return 6;if(e<xa)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function wa(e,t,r=0){switch(Cr(e)){case 8:t[r++]=e&255|mt,e/=128;case 7:t[r++]=e&255|mt,e/=128;case 6:t[r++]=e&255|mt,e/=128;case 5:t[r++]=e&255|mt,e/=128;case 4:t[r++]=e&255|mt,e>>>=7;case 3:t[r++]=e&255|mt,e>>>=7;case 2:t[r++]=e&255|mt,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function ba(e,t){let r=e[t],n=0;if(n+=r&ye,r<mt||(r=e[t+1],n+=(r&ye)<<7,r<mt)||(r=e[t+2],n+=(r&ye)<<14,r<mt)||(r=e[t+3],n+=(r&ye)<<21,r<mt)||(r=e[t+4],n+=(r&ye)*ma,r<mt)||(r=e[t+5],n+=(r&ye)*ya,r<mt)||(r=e[t+6],n+=(r&ye)*ga,r<mt)||(r=e[t+7],n+=(r&ye)*xa,r<mt))return n;throw new RangeError("Could not decode varint")}var oi=new Float32Array([-0]),ge=new Uint8Array(oi.buffer);function Ea(e,t,r){oi[0]=e,t[r]=ge[0],t[r+1]=ge[1],t[r+2]=ge[2],t[r+3]=ge[3]}function Sa(e,t){return ge[0]=e[t],ge[1]=e[t+1],ge[2]=e[t+2],ge[3]=e[t+3],oi[0]}var ii=new Float64Array([-0]),ft=new Uint8Array(ii.buffer);function Aa(e,t,r){ii[0]=e,t[r]=ft[0],t[r+1]=ft[1],t[r+2]=ft[2],t[r+3]=ft[3],t[r+4]=ft[4],t[r+5]=ft[5],t[r+6]=ft[6],t[r+7]=ft[7]}function va(e,t){return ft[0]=e[t],ft[1]=e[t+1],ft[2]=e[t+2],ft[3]=e[t+3],ft[4]=e[t+4],ft[5]=e[t+5],ft[6]=e[t+6],ft[7]=e[t+7],ii[0]}var Wl=BigInt(Number.MAX_SAFE_INTEGER),Xl=BigInt(Number.MIN_SAFE_INTEGER),St=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 Ue;if(t<Wl&&t>Xl)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>Ta&&(o=0n,++n>Ta&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return Ue;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):Ue}},Ue=new St(0,0);Ue.toBigInt=function(){return 0n};Ue.zzEncode=Ue.zzDecode=function(){return this};Ue.length=function(){return 1};var Ta=4294967296n;function Ba(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 Ia(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 si(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 kt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function bn(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var ai=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,kt(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 kt(this,4);return bn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw kt(this,4);return bn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw kt(this,4);let t=Sa(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw kt(this,4);let t=va(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 kt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return Ia(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw kt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw kt(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 St(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 kt(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 kt(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 kt(this,8);let t=bn(this.buf,this.pos+=4),r=bn(this.buf,this.pos+=4);return new St(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=ba(this.buf,this.pos);return this.pos+=Cr(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 ci(e){return new ai(e instanceof Uint8Array?e:e.subarray())}function xe(e,t,r){let n=ci(e);return t.decode(n,void 0,r)}function ui(e){let t=e??8192,r=t>>>1,n,o=t;return function(s){if(s<1||s>r)return wt(s);o+s>t&&(n=wt(t),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var Re=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function fi(){}var di=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Jl=ui();function Ql(e){return globalThis.Buffer!=null?wt(e):Jl(e)}var Dr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Re(fi,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new Re(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new hi((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(En,10,St.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=St.fromBigInt(t);return this._push(En,r.length(),r)}uint64Number(t){return this._push(wa,Cr(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=St.fromBigInt(t).zzEncode();return this._push(En,r.length(),r)}sint64Number(t){let r=St.fromNumber(t).zzEncode();return this._push(En,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(li,1,t?1:0)}fixed32(t){return this._push(_r,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=St.fromBigInt(t);return this._push(_r,4,r.lo)._push(_r,4,r.hi)}fixed64Number(t){let r=St.fromNumber(t);return this._push(_r,4,r.lo)._push(_r,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(Ea,4,t)}double(t){return this._push(Aa,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(li,1,0):this.uint32(r)._push(ed,r,t)}string(t){let r=Ba(t);return r!==0?this.uint32(r)._push(si,r,t):this._push(li,1,0)}fork(){return this.states=new di(this),this.head=this.tail=new Re(fi,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 Re(fi,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=Ql(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function li(e,t,r){t[r]=e&255}function td(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var hi=class extends Re{next;constructor(t,r){super(td,t,r),this.next=void 0}};function En(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 _r(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 ed(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(Dr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(rd,t,e),this},Dr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(nd,t,e),this});function rd(e,t,r){t.set(e,r)}function nd(e,t,r){e.length<40?si(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(M(e),r)}function pi(){return new Dr}function we(e,t){let r=pi();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var rr;(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"})(rr||(rr={}));function Sn(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function Ur(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 Sn("enum",rr.VARINT,r,n)}function be(e,t){return Sn("message",rr.LENGTH_DELIMITED,e,t)}var Q;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(Q||(Q={}));var mi;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(mi||(mi={}));(function(e){e.codec=()=>Ur(mi)})(Q||(Q={}));var qt;(function(e){let t;e.codec=()=>(t==null&&(t=be((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),Q.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=Q.codec().decode(r);break}case 2:{i.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return i})),t),e.encode=r=>we(r,e.codec()),e.decode=(r,n)=>xe(r,e.codec(),n)})(qt||(qt={}));var yi;(function(e){let t;e.codec=()=>(t==null&&(t=be((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),Q.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=Q.codec().decode(r);break}case 2:{i.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return i})),t),e.encode=r=>we(r,e.codec()),e.decode=(r,n)=>xe(r,e.codec(),n)})(yi||(yi={}));var Nr={};yt(Nr,{MAX_RSA_KEY_SIZE:()=>gi,generateRSAKeyPair:()=>Na,jwkToJWKKeyPair:()=>La,jwkToPkcs1:()=>ad,jwkToPkix:()=>Ei,jwkToRSAPrivateKey:()=>Ti,pkcs1MessageToJwk:()=>wi,pkcs1MessageToRSAPrivateKey:()=>Si,pkcs1ToJwk:()=>sd,pkcs1ToRSAPrivateKey:()=>Ra,pkixMessageToJwk:()=>bi,pkixMessageToRSAPublicKey:()=>vi,pkixToJwk:()=>cd,pkixToRSAPublicKey:()=>Ai});var An=un;var nr=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Nr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return G.createV1(114,this._multihash)}toString(){return z.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:J(this.raw,t.raw)}verify(t,r,n){return Ua(this.jwk,r,t,n)}},Rr=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Nr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:J(this.raw,t.raw)}sign(t,r){return Da(this.jwk,t,r)}};var gi=8192,xi=18,od=1062,id=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function sd(e){let t=jt(e);return wi(t)}function wi(e){return{n:V(e[1],"base64url"),e:V(e[2],"base64url"),d:V(e[3],"base64url"),p:V(e[4],"base64url"),q:V(e[5],"base64url"),dp:V(e[6],"base64url"),dq:V(e[7],"base64url"),qi:V(e[8],"base64url"),kty:"RSA"}}function ad(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 et("JWK was missing components");return ue([xt(Uint8Array.from([0])),xt(M(e.n,"base64url")),xt(M(e.e,"base64url")),xt(M(e.d,"base64url")),xt(M(e.p,"base64url")),xt(M(e.q,"base64url")),xt(M(e.dp,"base64url")),xt(M(e.dq,"base64url")),xt(M(e.qi,"base64url"))]).subarray()}function cd(e){let t=jt(e,{offset:0});return bi(t)}function bi(e){let t=jt(e[1],{offset:0});return{kty:"RSA",n:V(t[0],"base64url"),e:V(t[1],"base64url")}}function Ei(e){if(e.n==null||e.e==null)throw new et("JWK was missing components");return ue([id,on(ue([xt(M(e.n,"base64url")),xt(M(e.e,"base64url"))]))]).subarray()}function Ra(e){let t=jt(e);return Si(t)}function Si(e){let t=wi(e);return Ti(t)}function Ai(e,t){if(e.byteLength>=od)throw new Oe("Key size is too large");let r=jt(e,{offset:0});return vi(r,e,t)}function vi(e,t,r){let n=bi(e);if(r==null){let o=An(qt.encode({Type:Q.RSA,Data:t}));r=Rt(xi,o)}return new nr(n,r)}function Ti(e){if(ka(e)>gi)throw new et("Key size is too large");let t=La(e),r=An(qt.encode({Type:Q.RSA,Data:Ei(t.publicKey)})),n=Rt(xi,r);return new Rr(t.privateKey,new nr(t.publicKey,n))}async function Na(e){if(e>gi)throw new et("Key size is too large");let t=await Pa(e),r=An(qt.encode({Type:Q.RSA,Data:Ei(t.publicKey)})),n=Rt(xi,r);return new Rr(t.privateKey,new nr(t.publicKey,n))}function La(e){if(e==null)throw new et("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function Pa(e,t){let r=await Ct.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 ud(r,t);return{privateKey:n[0],publicKey:n[1]}}async function Da(e,t,r){let n=await Ct.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Ct.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 Ua(e,t,r,n){let o=await Ct.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let i=await Ct.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),i}async function ud(e,t){if(e.privateKey==null||e.publicKey==null)throw new et("Private and public key are required");let r=await Promise.all([Ct.get().subtle.exportKey("jwk",e.privateKey),Ct.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function ka(e){if(e.kty!=="RSA")throw new et("invalid key type");if(e.n==null)throw new et("invalid key modulus");return M(e.n,"base64url").length*8}var vn=class extends Ze{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,Bs(t);let n=br(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),Wt(i)}update(t){return Ye(this),this.iHash.update(t),this}digestInto(t){Ye(this),ut(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()}},Bi=(e,t,r)=>new vn(e,t).update(r).digest();Bi.create=(e,t)=>new vn(e,t);function Ka(e){e.lowS!==void 0&&Jt("lowS",e.lowS),e.prehash!==void 0&&Jt("prehash",e.prehash)}var Ii=class extends Error{constructor(t=""){super(t)}},Qt={Err:Ii,_tlv:{encode:(e,t)=>{let{Err:r}=Qt;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=Tr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let i=n>127?Tr(o.length/2|128):"";return Tr(e)+i+o+t},decode(e,t){let{Err:r}=Qt,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 u=o&127;if(!u)throw new r("tlv.decode(long): indefinite length not supported");if(u>4)throw new r("tlv.decode(long): byte length is too big");let d=t.subarray(n,n+u);if(d.length!==u)throw new r("tlv.decode: length bytes not complete");if(d[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let c of d)s=s<<8|c;if(n+=u,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}=Qt;if(e<Lr)throw new t("integer: negative integers are not allowed");let r=Tr(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}=Qt;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 Xe(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Qt,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:u}=n.decode(2,i),{v:d,l:c}=n.decode(2,u);if(c.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(d)}},hexFromSig(e){let{_tlv:t,_int:r}=Qt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),i=n+o;return t.encode(48,i)}},Lr=BigInt(0),Pr=BigInt(1),fd=BigInt(2),Tn=BigInt(3),ld=BigInt(4);function dd(e,t,r){function n(o){let i=e.sqr(o),s=e.mul(i,o);return e.add(e.add(s,e.mul(o,t)),r)}return n}function Fa(e,t,r){let{BYTES:n}=e;function o(i){let s;if(typeof i=="bigint")s=i;else{let a=j("private key",i);if(t){if(!t.includes(a.length*2))throw new Error("invalid private key");let u=new Uint8Array(n);u.set(a,u.length-a.length),a=u}try{s=e.fromBytes(a)}catch{throw new Error(`invalid private key: expected ui8a of size ${n}, got ${typeof i}`)}}if(r&&(s=e.create(s)),!e.isValidNot0(s))throw new Error("invalid private key: out of range [1..N-1]");return s}return o}function hd(e,t={}){let{Fp:r,Fn:n}=pn("weierstrass",e,t),{h:o,n:i}=e;me(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:s}=t;if(s&&(!r.is0(e.a)||typeof s.beta!="bigint"||typeof s.splitScalar!="function"))throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function');function a(){if(!r.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function u(g,f,x){let{x:h,y:p}=f.toAffine(),S=r.toBytes(h);if(Jt("isCompressed",x),x){a();let B=!r.isOdd(p);return Et(Oa(B),S)}else return Et(Uint8Array.of(4),S,r.toBytes(p))}function d(g){ut(g);let f=r.BYTES,x=f+1,h=2*f+1,p=g.length,S=g[0],B=g.subarray(1);if(p===x&&(S===2||S===3)){let v=r.fromBytes(B);if(!r.isValid(v))throw new Error("bad point: is not on curve, wrong x");let I=y(v),k;try{k=r.sqrt(I)}catch(q){let O=q instanceof Error?": "+q.message:"";throw new Error("bad point: is not on curve, sqrt error"+O)}a();let P=r.isOdd(k);return(S&1)===1!==P&&(k=r.neg(k)),{x:v,y:k}}else if(p===h&&S===4){let v=r.fromBytes(B.subarray(f*0,f*1)),I=r.fromBytes(B.subarray(f*1,f*2));if(!b(v,I))throw new Error("bad point: is not on curve");return{x:v,y:I}}else throw new Error(`bad point: got length ${p}, expected compressed=${x} or uncompressed=${h}`)}let c=t.toBytes||u,l=t.fromBytes||d,y=dd(r,e.a,e.b);function b(g,f){let x=r.sqr(f),h=y(g);return r.eql(x,h)}if(!b(e.Gx,e.Gy))throw new Error("bad curve params: generator point");let T=r.mul(r.pow(e.a,Tn),ld),A=r.mul(r.sqr(e.b),BigInt(27));if(r.is0(r.add(T,A)))throw new Error("bad curve params: a or b");function w(g,f,x=!1){if(!r.isValid(f)||x&&r.is0(f))throw new Error(`bad point coordinate ${g}`);return f}function C(g){if(!(g instanceof E))throw new Error("ProjectivePoint expected")}let U=Qe((g,f)=>{let{px:x,py:h,pz:p}=g;if(r.eql(p,r.ONE))return{x,y:h};let S=g.is0();f==null&&(f=S?r.ONE:r.inv(p));let B=r.mul(x,f),v=r.mul(h,f),I=r.mul(p,f);if(S)return{x:r.ZERO,y:r.ZERO};if(!r.eql(I,r.ONE))throw new Error("invZ was invalid");return{x:B,y:v}}),D=Qe(g=>{if(g.is0()){if(t.allowInfinityPoint&&!r.is0(g.py))return;throw new Error("bad point: ZERO")}let{x:f,y:x}=g.toAffine();if(!r.isValid(f)||!r.isValid(x))throw new Error("bad point: x or y not field elements");if(!b(f,x))throw new Error("bad point: equation left != right");if(!g.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function K(g,f,x,h,p){return x=new E(r.mul(x.px,g),x.py,x.pz),f=tr(h,f),x=tr(p,x),f.add(x)}class E{constructor(f,x,h){this.px=w("x",f),this.py=w("y",x,!0),this.pz=w("z",h),Object.freeze(this)}static fromAffine(f){let{x,y:h}=f||{};if(!f||!r.isValid(x)||!r.isValid(h))throw new Error("invalid affine point");if(f instanceof E)throw new Error("projective point not allowed");return r.is0(x)&&r.is0(h)?E.ZERO:new E(x,h,r.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(f){return ln(E,"pz",f)}static fromBytes(f){return ut(f),E.fromHex(f)}static fromHex(f){let x=E.fromAffine(l(j("pointHex",f)));return x.assertValidity(),x}static fromPrivateKey(f){let x=Fa(n,t.allowedPrivateKeyLengths,t.wrapPrivateKey);return E.BASE.multiply(x(f))}static msm(f,x){return hn(E,n,f,x)}precompute(f=8,x=!0){return N.setWindowSize(this,f),x||this.multiply(Tn),this}_setWindowSize(f){this.precompute(f)}assertValidity(){D(this)}hasEvenY(){let{y:f}=this.toAffine();if(!r.isOdd)throw new Error("Field doesn't support isOdd");return!r.isOdd(f)}equals(f){C(f);let{px:x,py:h,pz:p}=this,{px:S,py:B,pz:v}=f,I=r.eql(r.mul(x,v),r.mul(S,p)),k=r.eql(r.mul(h,v),r.mul(B,p));return I&&k}negate(){return new E(this.px,r.neg(this.py),this.pz)}double(){let{a:f,b:x}=e,h=r.mul(x,Tn),{px:p,py:S,pz:B}=this,v=r.ZERO,I=r.ZERO,k=r.ZERO,P=r.mul(p,p),$=r.mul(S,S),q=r.mul(B,B),O=r.mul(p,S);return O=r.add(O,O),k=r.mul(p,B),k=r.add(k,k),v=r.mul(f,k),I=r.mul(h,q),I=r.add(v,I),v=r.sub($,I),I=r.add($,I),I=r.mul(v,I),v=r.mul(O,v),k=r.mul(h,k),q=r.mul(f,q),O=r.sub(P,q),O=r.mul(f,O),O=r.add(O,k),k=r.add(P,P),P=r.add(k,P),P=r.add(P,q),P=r.mul(P,O),I=r.add(I,P),q=r.mul(S,B),q=r.add(q,q),P=r.mul(q,O),v=r.sub(v,P),k=r.mul(q,$),k=r.add(k,k),k=r.add(k,k),new E(v,I,k)}add(f){C(f);let{px:x,py:h,pz:p}=this,{px:S,py:B,pz:v}=f,I=r.ZERO,k=r.ZERO,P=r.ZERO,$=e.a,q=r.mul(e.b,Tn),O=r.mul(x,S),tt=r.mul(h,B),rt=r.mul(p,v),ct=r.add(x,h),Z=r.add(S,B);ct=r.mul(ct,Z),Z=r.add(O,tt),ct=r.sub(ct,Z),Z=r.add(x,p);let dt=r.add(S,v);return Z=r.mul(Z,dt),dt=r.add(O,rt),Z=r.sub(Z,dt),dt=r.add(h,p),I=r.add(B,v),dt=r.mul(dt,I),I=r.add(tt,rt),dt=r.sub(dt,I),P=r.mul($,Z),I=r.mul(q,rt),P=r.add(I,P),I=r.sub(tt,P),P=r.add(tt,P),k=r.mul(I,P),tt=r.add(O,O),tt=r.add(tt,O),rt=r.mul($,rt),Z=r.mul(q,Z),tt=r.add(tt,rt),rt=r.sub(O,rt),rt=r.mul($,rt),Z=r.add(Z,rt),O=r.mul(tt,Z),k=r.add(k,O),O=r.mul(dt,Z),I=r.mul(ct,I),I=r.sub(I,O),O=r.mul(ct,tt),P=r.mul(dt,P),P=r.add(P,O),new E(I,k,P)}subtract(f){return this.add(f.negate())}is0(){return this.equals(E.ZERO)}multiply(f){let{endo:x}=t;if(!n.isValidNot0(f))throw new Error("invalid scalar: out of range");let h,p,S=B=>N.wNAFCached(this,B,E.normalizeZ);if(x){let{k1neg:B,k1:v,k2neg:I,k2:k}=x.splitScalar(f),{p:P,f:$}=S(v),{p:q,f:O}=S(k);p=$.add(O),h=K(x.beta,P,q,B,I)}else{let{p:B,f:v}=S(f);h=B,p=v}return E.normalizeZ([h,p])[0]}multiplyUnsafe(f){let{endo:x}=t,h=this;if(!n.isValid(f))throw new Error("invalid scalar: out of range");if(f===Lr||h.is0())return E.ZERO;if(f===Pr)return h;if(N.hasPrecomputes(this))return this.multiply(f);if(x){let{k1neg:p,k1:S,k2neg:B,k2:v}=x.splitScalar(f),{p1:I,p2:k}=aa(E,h,S,v);return K(x.beta,I,k,p,B)}else return N.wNAFCachedUnsafe(h,f)}multiplyAndAddUnsafe(f,x,h){let p=this.multiplyUnsafe(x).add(f.multiplyUnsafe(h));return p.is0()?void 0:p}toAffine(f){return U(this,f)}isTorsionFree(){let{isTorsionFree:f}=t;return o===Pr?!0:f?f(E,this):N.wNAFCachedUnsafe(this,i).is0()}clearCofactor(){let{clearCofactor:f}=t;return o===Pr?this:f?f(E,this):this.multiplyUnsafe(o)}toBytes(f=!0){return Jt("isCompressed",f),this.assertValidity(),c(E,this,f)}toRawBytes(f=!0){return this.toBytes(f)}toHex(f=!0){return Mt(this.toBytes(f))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}E.BASE=new E(e.Gx,e.Gy,r.ONE),E.ZERO=new E(r.ZERO,r.ONE,r.ZERO),E.Fp=r,E.Fn=n;let R=n.BITS,N=dn(E,t.endo?Math.ceil(R/2):R);return E}function Oa(e){return Uint8Array.of(e?2:3)}function pd(e,t,r={}){me(t,{hash:"function"},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=t.randomBytes||Er,o=t.hmac||((h,...p)=>Bi(t.hash,h,Et(...p))),{Fp:i,Fn:s}=e,{ORDER:a,BITS:u}=s;function d(h){let p=a>>Pr;return h>p}function c(h){return d(h)?s.neg(h):h}function l(h,p){if(!s.isValidNot0(p))throw new Error(`invalid signature ${h}: out of range 1..CURVE.n`)}class y{constructor(p,S,B){l("r",p),l("s",S),this.r=p,this.s=S,B!=null&&(this.recovery=B),Object.freeze(this)}static fromCompact(p){let S=s.BYTES,B=j("compactSignature",p,S*2);return new y(s.fromBytes(B.subarray(0,S)),s.fromBytes(B.subarray(S,S*2)))}static fromDER(p){let{r:S,s:B}=Qt.toSig(j("DER",p));return new y(S,B)}assertValidity(){}addRecoveryBit(p){return new y(this.r,this.s,p)}recoverPublicKey(p){let S=i.ORDER,{r:B,s:v,recovery:I}=this;if(I==null||![0,1,2,3].includes(I))throw new Error("recovery id invalid");if(a*fd<S&&I>1)throw new Error("recovery id is ambiguous for h>1 curve");let P=I===2||I===3?B+a:B;if(!i.isValid(P))throw new Error("recovery id 2 or 3 invalid");let $=i.toBytes(P),q=e.fromHex(Et(Oa((I&1)===0),$)),O=s.inv(P),tt=D(j("msgHash",p)),rt=s.create(-tt*O),ct=s.create(v*O),Z=e.BASE.multiplyUnsafe(rt).add(q.multiplyUnsafe(ct));if(Z.is0())throw new Error("point at infinify");return Z.assertValidity(),Z}hasHighS(){return d(this.s)}normalizeS(){return this.hasHighS()?new y(this.r,s.neg(this.s),this.recovery):this}toBytes(p){if(p==="compact")return Et(s.toBytes(this.r),s.toBytes(this.s));if(p==="der")return We(Qt.hexFromSig(this));throw new Error("invalid format")}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return Mt(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return Mt(this.toBytes("compact"))}}let b=Fa(s,r.allowedPrivateKeyLengths,r.wrapPrivateKey),T={isValidPrivateKey(h){try{return b(h),!0}catch{return!1}},normPrivateKeyToScalar:b,randomPrivateKey:()=>{let h=a;return ea(n(Wo(h)),h)},precompute(h=8,p=e.BASE){return p.precompute(h,!1)}};function A(h,p=!0){return e.fromPrivateKey(h).toBytes(p)}function w(h){if(typeof h=="bigint")return!1;if(h instanceof e)return!0;let S=j("key",h).length,B=i.BYTES,v=B+1,I=2*B+1;if(!(r.allowedPrivateKeyLengths||s.BYTES===v))return S===v||S===I}function C(h,p,S=!0){if(w(h)===!0)throw new Error("first arg must be private key");if(w(p)===!1)throw new Error("second arg must be public key");return e.fromHex(p).multiply(b(h)).toBytes(S)}let U=t.bits2int||function(h){if(h.length>8192)throw new Error("input is too large");let p=Xe(h),S=h.length*8-u;return S>0?p>>BigInt(S):p},D=t.bits2int_modN||function(h){return s.create(U(h))},K=Ce(u);function E(h){return pe("num < 2^"+u,h,Lr,K),s.toBytes(h)}function R(h,p,S=N){if(["recovered","canonical"].some(ct=>ct in S))throw new Error("sign() legacy options not supported");let{hash:B}=t,{lowS:v,prehash:I,extraEntropy:k}=S;v==null&&(v=!0),h=j("msgHash",h),Ka(S),I&&(h=j("prehashed msgHash",B(h)));let P=D(h),$=b(p),q=[E($),E(P)];if(k!=null&&k!==!1){let ct=k===!0?n(i.BYTES):k;q.push(j("extraEntropy",ct))}let O=Et(...q),tt=P;function rt(ct){let Z=U(ct);if(!s.isValidNot0(Z))return;let dt=s.inv(Z),lr=e.BASE.multiply(Z).toAffine(),Ke=s.create(lr.x);if(Ke===Lr)return;let Ae=s.create(dt*s.create(tt+Ke*$));if(Ae===Lr)return;let uo=(lr.x===Ke?0:2)|Number(lr.y&Pr),Fe=Ae;return v&&d(Ae)&&(Fe=c(Ae),uo^=1),new y(Ke,Fe,uo)}return{seed:O,k2sig:rt}}let N={lowS:t.lowS,prehash:!1},g={lowS:t.lowS,prehash:!1};function f(h,p,S=N){let{seed:B,k2sig:v}=R(h,p,S);return zs(t.hash.outputLen,s.BYTES,o)(B,v)}e.BASE.precompute(8);function x(h,p,S,B=g){let v=h;p=j("msgHash",p),S=j("publicKey",S),Ka(B);let{lowS:I,prehash:k,format:P}=B;if("strict"in B)throw new Error("options.strict was renamed to lowS");if(P!==void 0&&!["compact","der","js"].includes(P))throw new Error('format must be "compact", "der" or "js"');let $=typeof v=="string"||je(v),q=!$&&!P&&typeof v=="object"&&v!==null&&typeof v.r=="bigint"&&typeof v.s=="bigint";if(!$&&!q)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let O,tt;try{if(q)if(P===void 0||P==="js")O=new y(v.r,v.s);else throw new Error("invalid format");if($){try{P!=="compact"&&(O=y.fromDER(v))}catch(Fe){if(!(Fe instanceof Qt.Err))throw Fe}!O&&P!=="der"&&(O=y.fromCompact(v))}tt=e.fromHex(S)}catch{return!1}if(!O||I&&O.hasHighS())return!1;k&&(p=t.hash(p));let{r:rt,s:ct}=O,Z=D(p),dt=s.inv(ct),lr=s.create(Z*dt),Ke=s.create(rt*dt),Ae=e.BASE.multiplyUnsafe(lr).add(tt.multiplyUnsafe(Ke));return Ae.is0()?!1:s.create(Ae.x)===rt}return Object.freeze({getPublicKey:A,getSharedSecret:C,sign:f,verify:x,utils:T,Point:e,Signature:y})}function md(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=Pt(t.n,e.nBitLength),o={Fp:r,Fn:n,allowedPrivateKeyLengths:e.allowedPrivateKeyLengths,allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,wrapPrivateKey:e.wrapPrivateKey,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes};return{CURVE:t,curveOpts:o}}function yd(e){let{CURVE:t,curveOpts:r}=md(e),n={hash:e.hash,hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:r,ecdsaOpts:n}}function gd(e,t){return Object.assign({},t,{ProjectivePoint:t.Point,CURVE:e})}function Ma(e){let{CURVE:t,curveOpts:r,ecdsaOpts:n}=yd(e),o=hd(t,r),i=pd(o,n,r);return gd(e,i)}function Va(e,t){let r=n=>Ma({...e,hash:n});return{...r(t),create:r}}var Bn={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Py=BigInt(0),xd=BigInt(1),Ci=BigInt(2),Ha=(e,t)=>(e+t/Ci)/t;function wd(e){let t=Bn.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),u=BigInt(88),d=e*e*e%t,c=d*d*e%t,l=Y(c,r,t)*c%t,y=Y(l,r,t)*c%t,b=Y(y,Ci,t)*d%t,T=Y(b,o,t)*b%t,A=Y(T,i,t)*T%t,w=Y(A,a,t)*A%t,C=Y(w,u,t)*w%t,U=Y(C,a,t)*A%t,D=Y(U,r,t)*c%t,K=Y(D,s,t)*T%t,E=Y(K,n,t)*d%t,R=Y(E,Ci,t);if(!_i.eql(_i.sqr(R),e))throw new Error("Cannot find square root");return R}var _i=Pt(Bn.p,void 0,void 0,{sqrt:wd}),or=Va({...Bn,Fp:_i,lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{let t=Bn.n,r=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-xd*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=r,s=BigInt("0x100000000000000000000000000000000"),a=Ha(i*e,t),u=Ha(-n*e,t),d=W(e-a*r-u*o,t),c=W(-a*n-u*i,t),l=d>s,y=c>s;if(l&&(d=t-d),y&&(c=t-c),d>s||c>s)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:l,k1:d,k2neg:y,k2:c}}}},un);function qa(e,t,r,n){let o=yr.digest(r instanceof Uint8Array?r:r.subarray());if(xn(o))return o.then(({digest:i})=>(n?.signal?.throwIfAborted(),or.verify(t,i,e))).catch(i=>{throw i.name==="AbortError"?i:new Ir(String(i))});try{return n?.signal?.throwIfAborted(),or.verify(t,o.digest,e)}catch(i){throw new Ir(String(i))}}var In=class{type="secp256k1";raw;_key;constructor(t){this._key=za(t),this.raw=$a(this._key)}toMultihash(){return Nt.digest(fe(this))}toCID(){return G.createV1(114,this.toMultihash())}toString(){return z.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:J(this.raw,t.raw)}verify(t,r,n){return qa(this._key,r,t,n)}};function Di(e){return new In(e)}function $a(e){return or.ProjectivePoint.fromHex(e).toRawBytes(!0)}function za(e){try{return or.ProjectivePoint.fromHex(e),e}catch(t){throw new Oe(String(t))}}function Ga(e,t){let{Type:r,Data:n}=qt.decode(e),o=n??new Uint8Array;switch(r){case Q.RSA:return Ai(o,t);case Q.Ed25519:return ni(o);case Q.secp256k1:return Di(o);case Q.ECDSA:return Vo(o);default:throw new Ve}}function Cn(e){let{Type:t,Data:r}=qt.decode(e.digest),n=r??new Uint8Array;switch(t){case Q.Ed25519:return ni(n);case Q.secp256k1:return Di(n);case Q.ECDSA:return Vo(n);default:throw new Ve}}function fe(e){return qt.encode({Type:Q[e.type],Data:e.raw})}var Za=Symbol.for("nodejs.util.inspect.custom"),bd=114,kr=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()})`}[fo]=!0;toString(){return this.string==null&&(this.string=z.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return G.createV1(bd,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return J(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return J(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Za](){return`PeerId(${this.toString()})`}},_n=class extends kr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Dn=class extends kr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Un=class extends kr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Ed=2336,Kr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Nt.digest(M(this.url))}[Za](){return`PeerId(${this.url})`}[fo]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return G.createV1(Ed,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=V(t)),t.toString()===this.toString())}};var Sd=114,ja=2336;function Rn(e,t){let r;if(e.charAt(0)==="1"||e.charAt(0)==="Q")r=Zt(z.decode(`z${e}`));else{if(e.startsWith("k51qzi5uqu5")||e.startsWith("kzwfwjn5ji4")||e.startsWith("k2k4r8")||e.startsWith("bafz"))return Ui(G.parse(e));if(t==null)throw new et('Please pass a multibase decoder for strings that do not start with "1" or "Q"');r=Zt(t.decode(e))}return Ya(r)}function Ya(e){if(vd(e))return new _n({multihash:e});if(Ad(e))try{let t=Cn(e);if(t.type==="Ed25519")return new Dn({multihash:e,publicKey:t});if(t.type==="secp256k1")return new Un({multihash:e,publicKey:t})}catch{let r=V(e.digest);return new Kr(new URL(r))}throw new Me("Supplied PeerID Multihash is invalid")}function Ui(e){if(e?.multihash==null||e.version==null||e.version===1&&e.code!==Sd&&e.code!==ja)throw new Xr("Supplied PeerID CID is invalid");if(e.code===ja){let t=V(e.multihash.digest);return new Kr(new URL(t))}return Ya(e.multihash)}function Ad(e){return e.code===Nt.code}function vd(e){return e.code===yr.code}var te="/",Wa=new TextEncoder().encode(te),Nn=Wa[0],Fr=class e{_buf;constructor(t,r){if(typeof t=="string")this._buf=M(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 V(this._buf,t)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(t){return new e(t.join(te))}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=Wa),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(te).slice(1)}type(){return Td(this.baseNamespace())}name(){return Bd(this.baseNamespace())}instance(t){return new e(this.toString()+":"+t)}path(){let t=this.parent().toString();return t.endsWith(te)||(t+=te),t+=this.type(),new e(t)}parent(){let t=this.list();return t.length===1?new e(te):new e(t.slice(0,-1).join(te))}child(t){return this.toString()===te?t:t.toString()===te?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(),...Id(t.map(r=>r.namespaces()))])}};function Td(e){let t=e.split(":");return t.length<2?"":t.slice(0,-1).join(":")}function Bd(e){let t=e.split(":");return t[t.length-1]}function Id(e){return[].concat(...e)}var cu=Wr(Ln(),1);var Pn=class extends Error{static name="SignatureCreationError";constructor(t="Record signature creation failed"){super(t),this.name="SignatureCreationError"}},Kt=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"}},Ne=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"}},Or=class extends Error{static name="InvalidValueError";constructor(t="Value must be a valid content path starting with /"){super(t),this.name="InvalidValueError"}},Fn=class extends Error{static name="InvalidRecordDataError";constructor(t="Invalid record data"){super(t),this.name="InvalidRecordDataError"}},Mr=class extends Error{static name="InvalidEmbeddedPublicKeyError";constructor(t="Invalid embedded public key"){super(t),this.name="InvalidEmbeddedPublicKeyError"}};var st;(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=()=>Ur(r)}(t=e.ValidityType||(e.ValidityType={}));let n;e.codec=()=>(n==null&&(n=be((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={},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let d=o.uint32();switch(d>>>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(d&7);break}}}return a})),n),e.encode=o=>we(o,e.codec()),e.decode=(o,i)=>xe(o,e.codec(),i)})(st||(st={}));var Cd=["string","number","bigint","symbol"],_d=["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 Xa(e){if(e===null)return"null";if(e===void 0)return"undefined";if(e===!0||e===!1)return"boolean";let t=typeof e;if(Cd.includes(t))return t;if(t==="function")return"Function";if(Array.isArray(e))return"Array";if(Dd(e))return"Buffer";let r=Ud(e);return r||"Object"}function Dd(e){return e&&e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer.call(null,e)}function Ud(e){let t=Object.prototype.toString.call(e).slice(8,-1);if(_d.includes(t))return t}var m=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}};m.uint=new m(0,"uint",!0);m.negint=new m(1,"negint",!0);m.bytes=new m(2,"bytes",!0);m.string=new m(3,"string",!0);m.array=new m(4,"array",!1);m.map=new m(5,"map",!1);m.tag=new m(6,"tag",!1);m.float=new m(7,"float",!0);m.false=new m(7,"false",!0);m.true=new m(7,"true",!0);m.null=new m(7,"null",!0);m.undefined=new m(7,"undefined",!0);m.break=new m(7,"break",!0);var L=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 ir=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Rd=new TextDecoder,Nd=new TextEncoder;function On(e){return ir&&globalThis.Buffer.isBuffer(e)}function Ni(e){return e instanceof Uint8Array?On(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e:Uint8Array.from(e)}var ec=ir?(e,t,r)=>r-t>64?globalThis.Buffer.from(e.subarray(t,r)).toString("utf8"):Qa(e,t,r):(e,t,r)=>r-t>64?Rd.decode(e.subarray(t,r)):Qa(e,t,r),rc=ir?e=>e.length>64?globalThis.Buffer.from(e):Ja(e):e=>e.length>64?Nd.encode(e):Ja(e),$t=e=>Uint8Array.from(e),sr=ir?(e,t,r)=>On(e)?new Uint8Array(e.subarray(t,r)):e.slice(t,r):(e,t,r)=>e.slice(t,r),nc=ir?(e,t)=>(e=e.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),Ni(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},oc=ir?e=>globalThis.Buffer.allocUnsafe(e):e=>new Uint8Array(e);function ic(e,t){if(On(e)&&On(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 Ja(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 Qa(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,u,d,c;switch(s){case 1:o<128&&(i=o);break;case 2:a=e[t+1],(a&192)===128&&(c=(o&31)<<6|a&63,c>127&&(i=c));break;case 3:a=e[t+1],u=e[t+2],(a&192)===128&&(u&192)===128&&(c=(o&15)<<12|(a&63)<<6|u&63,c>2047&&(c<55296||c>57343)&&(i=c));break;case 4:a=e[t+1],u=e[t+2],d=e[t+3],(a&192)===128&&(u&192)===128&&(d&192)===128&&(c=(o&15)<<18|(a&63)<<12|(u&63)<<6|d&63,c>65535&&c<1114112&&(i=c))}}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 Ld(n)}var tc=4096;function Ld(e){let t=e.length;if(t<=tc)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=tc));return r}var Pd=256,Vr=class{constructor(t=Pd){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=oc(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=sr(n,0,this.cursor)}else r=nc(this.chunks,this.cursor);return t&&this.reset(),r}};var F="CBOR decode error:",Li="CBOR encode error:",Hr=[];Hr[23]=1;Hr[24]=2;Hr[25]=3;Hr[26]=5;Hr[27]=9;function ee(e,t,r){if(e.length-t<r)throw new Error(`${F} not enough data for type`)}var ot=[24,256,65536,4294967296,BigInt("18446744073709551616")];function At(e,t,r){ee(e,t,1);let n=e[t];if(r.strict===!0&&n<ot[0])throw new Error(`${F} integer encoded in more bytes than necessary (strict decode)`);return n}function vt(e,t,r){ee(e,t,2);let n=e[t]<<8|e[t+1];if(r.strict===!0&&n<ot[1])throw new Error(`${F} integer encoded in more bytes than necessary (strict decode)`);return n}function Tt(e,t,r){ee(e,t,4);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];if(r.strict===!0&&n<ot[2])throw new Error(`${F} integer encoded in more bytes than necessary (strict decode)`);return n}function Bt(e,t,r){ee(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<ot[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 sc(e,t,r,n){return new L(m.uint,At(e,t+1,n),2)}function ac(e,t,r,n){return new L(m.uint,vt(e,t+1,n),3)}function cc(e,t,r,n){return new L(m.uint,Tt(e,t+1,n),5)}function uc(e,t,r,n){return new L(m.uint,Bt(e,t+1,n),9)}function _t(e,t){return at(e,0,t.value)}function at(e,t,r){if(r<ot[0]){let n=Number(r);e.push([t|n])}else if(r<ot[1]){let n=Number(r);e.push([t|24,n])}else if(r<ot[2]){let n=Number(r);e.push([t|25,n>>>8,n&255])}else if(r<ot[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<ot[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`)}}_t.encodedSize=function(t){return at.encodedSize(t.value)};at.encodedSize=function(t){return t<ot[0]?1:t<ot[1]?2:t<ot[2]?3:t<ot[3]?5:9};_t.compareTokens=function(t,r){return t.value<r.value?-1:t.value>r.value?1:0};function fc(e,t,r,n){return new L(m.negint,-1-At(e,t+1,n),2)}function lc(e,t,r,n){return new L(m.negint,-1-vt(e,t+1,n),3)}function dc(e,t,r,n){return new L(m.negint,-1-Tt(e,t+1,n),5)}var Pi=BigInt(-1),hc=BigInt(1);function pc(e,t,r,n){let o=Bt(e,t+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new L(m.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${F} integers outside of the safe integer range are not supported`);return new L(m.negint,Pi-BigInt(o),9)}function Mn(e,t){let r=t.value,n=typeof r=="bigint"?r*Pi-hc:r*-1-1;at(e,t.type.majorEncoded,n)}Mn.encodedSize=function(t){let r=t.value,n=typeof r=="bigint"?r*Pi-hc:r*-1-1;return n<ot[0]?1:n<ot[1]?2:n<ot[2]?3:n<ot[3]?5:9};Mn.compareTokens=function(t,r){return t.value<r.value?1:t.value>r.value?-1:0};function qr(e,t,r,n){ee(e,t,r+n);let o=sr(e,t+r,t+r+n);return new L(m.bytes,o,r+n)}function mc(e,t,r,n){return qr(e,t,1,r)}function yc(e,t,r,n){return qr(e,t,2,At(e,t+1,n))}function gc(e,t,r,n){return qr(e,t,3,vt(e,t+1,n))}function xc(e,t,r,n){return qr(e,t,5,Tt(e,t+1,n))}function wc(e,t,r,n){let o=Bt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${F} 64-bit integer bytes lengths not supported`);return qr(e,t,9,o)}function Vn(e){return e.encodedBytes===void 0&&(e.encodedBytes=e.type===m.string?rc(e.value):e.value),e.encodedBytes}function ar(e,t){let r=Vn(t);at(e,t.type.majorEncoded,r.length),e.push(r)}ar.encodedSize=function(t){let r=Vn(t);return at.encodedSize(r.length)+r.length};ar.compareTokens=function(t,r){return Kd(Vn(t),Vn(r))};function Kd(e,t){return e.length<t.length?-1:e.length>t.length?1:ic(e,t)}function $r(e,t,r,n,o){let i=r+n;ee(e,t,i);let s=new L(m.string,ec(e,t+r,t+i),i);return o.retainStringBytes===!0&&(s.byteValue=sr(e,t+r,t+i)),s}function bc(e,t,r,n){return $r(e,t,1,r,n)}function Ec(e,t,r,n){return $r(e,t,2,At(e,t+1,n),n)}function Sc(e,t,r,n){return $r(e,t,3,vt(e,t+1,n),n)}function Ac(e,t,r,n){return $r(e,t,5,Tt(e,t+1,n),n)}function vc(e,t,r,n){let o=Bt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${F} 64-bit integer string lengths not supported`);return $r(e,t,9,o,n)}var Tc=ar;function cr(e,t,r,n){return new L(m.array,n,r)}function Bc(e,t,r,n){return cr(e,t,1,r)}function Ic(e,t,r,n){return cr(e,t,2,At(e,t+1,n))}function Cc(e,t,r,n){return cr(e,t,3,vt(e,t+1,n))}function _c(e,t,r,n){return cr(e,t,5,Tt(e,t+1,n))}function Dc(e,t,r,n){let o=Bt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${F} 64-bit integer array lengths not supported`);return cr(e,t,9,o)}function Uc(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${F} indefinite length items not allowed`);return cr(e,t,1,1/0)}function Hn(e,t){at(e,m.array.majorEncoded,t.value)}Hn.compareTokens=_t.compareTokens;Hn.encodedSize=function(t){return at.encodedSize(t.value)};function ur(e,t,r,n){return new L(m.map,n,r)}function Rc(e,t,r,n){return ur(e,t,1,r)}function Nc(e,t,r,n){return ur(e,t,2,At(e,t+1,n))}function Lc(e,t,r,n){return ur(e,t,3,vt(e,t+1,n))}function Pc(e,t,r,n){return ur(e,t,5,Tt(e,t+1,n))}function kc(e,t,r,n){let o=Bt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${F} 64-bit integer map lengths not supported`);return ur(e,t,9,o)}function Kc(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${F} indefinite length items not allowed`);return ur(e,t,1,1/0)}function qn(e,t){at(e,m.map.majorEncoded,t.value)}qn.compareTokens=_t.compareTokens;qn.encodedSize=function(t){return at.encodedSize(t.value)};function Fc(e,t,r,n){return new L(m.tag,r,1)}function Oc(e,t,r,n){return new L(m.tag,At(e,t+1,n),2)}function Mc(e,t,r,n){return new L(m.tag,vt(e,t+1,n),3)}function Vc(e,t,r,n){return new L(m.tag,Tt(e,t+1,n),5)}function Hc(e,t,r,n){return new L(m.tag,Bt(e,t+1,n),9)}function $n(e,t){at(e,m.tag.majorEncoded,t.value)}$n.compareTokens=_t.compareTokens;$n.encodedSize=function(t){return at.encodedSize(t.value)};var qd=20,$d=21,zd=22,Gd=23;function qc(e,t,r,n){if(n.allowUndefined===!1)throw new Error(`${F} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new L(m.null,null,1):new L(m.undefined,void 0,1)}function $c(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${F} indefinite length items not allowed`);return new L(m.break,void 0,1)}function ki(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 L(m.float,e,t)}function zc(e,t,r,n){return ki(Ki(e,t+1),3,n)}function Gc(e,t,r,n){return ki(Fi(e,t+1),5,n)}function Zc(e,t,r,n){return ki(Xc(e,t+1),9,n)}function zn(e,t,r){let n=t.value;if(n===!1)e.push([m.float.majorEncoded|qd]);else if(n===!0)e.push([m.float.majorEncoded|$d]);else if(n===null)e.push([m.float.majorEncoded|zd]);else if(n===void 0)e.push([m.float.majorEncoded|Gd]);else{let o,i=!1;(!r||r.float64!==!0)&&(Yc(n),o=Ki(Ft,1),n===o||Number.isNaN(n)?(Ft[0]=249,e.push(Ft.slice(0,3)),i=!0):(Wc(n),o=Fi(Ft,1),n===o&&(Ft[0]=250,e.push(Ft.slice(0,5)),i=!0))),i||(Zd(n),o=Xc(Ft,1),Ft[0]=251,e.push(Ft.slice(0,9)))}}zn.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){Yc(n);let o=Ki(Ft,1);if(n===o||Number.isNaN(n))return 3;if(Wc(n),o=Fi(Ft,1),n===o)return 5}return 9};var jc=new ArrayBuffer(9),Dt=new DataView(jc,1),Ft=new Uint8Array(jc,0);function Yc(e){if(e===1/0)Dt.setUint16(0,31744,!1);else if(e===-1/0)Dt.setUint16(0,64512,!1);else if(Number.isNaN(e))Dt.setUint16(0,32256,!1);else{Dt.setFloat32(0,e);let t=Dt.getUint32(0),r=(t&2139095040)>>23,n=t&8388607;if(r===255)Dt.setUint16(0,31744,!1);else if(r===0)Dt.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?Dt.setUint16(0,0):o<-14?Dt.setUint16(0,(t&2147483648)>>16|1<<24+o,!1):Dt.setUint16(0,(t&2147483648)>>16|o+15<<10|n>>13,!1)}}}function Ki(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 Wc(e){Dt.setFloat32(0,e,!1)}function Fi(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 Zd(e){Dt.setFloat64(0,e,!1)}function Xc(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)}zn.compareTokens=_t.compareTokens;function H(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]=H;_[24]=sc;_[25]=ac;_[26]=cc;_[27]=uc;_[28]=H;_[29]=H;_[30]=H;_[31]=H;for(let e=32;e<=55;e++)_[e]=H;_[56]=fc;_[57]=lc;_[58]=dc;_[59]=pc;_[60]=H;_[61]=H;_[62]=H;_[63]=H;for(let e=64;e<=87;e++)_[e]=mc;_[88]=yc;_[89]=gc;_[90]=xc;_[91]=wc;_[92]=H;_[93]=H;_[94]=H;_[95]=Gn("indefinite length bytes/strings are not supported");for(let e=96;e<=119;e++)_[e]=bc;_[120]=Ec;_[121]=Sc;_[122]=Ac;_[123]=vc;_[124]=H;_[125]=H;_[126]=H;_[127]=Gn("indefinite length bytes/strings are not supported");for(let e=128;e<=151;e++)_[e]=Bc;_[152]=Ic;_[153]=Cc;_[154]=_c;_[155]=Dc;_[156]=H;_[157]=H;_[158]=H;_[159]=Uc;for(let e=160;e<=183;e++)_[e]=Rc;_[184]=Nc;_[185]=Lc;_[186]=Pc;_[187]=kc;_[188]=H;_[189]=H;_[190]=H;_[191]=Kc;for(let e=192;e<=215;e++)_[e]=Fc;_[216]=Oc;_[217]=Mc;_[218]=Vc;_[219]=Hc;_[220]=H;_[221]=H;_[222]=H;_[223]=H;for(let e=224;e<=243;e++)_[e]=Gn("simple values are not supported");_[244]=H;_[245]=H;_[246]=H;_[247]=qc;_[248]=Gn("simple values are not supported");_[249]=zc;_[250]=Gc;_[251]=Zc;_[252]=H;_[253]=H;_[254]=H;_[255]=$c;var Ot=[];for(let e=0;e<24;e++)Ot[e]=new L(m.uint,e,1);for(let e=-1;e>=-24;e--)Ot[31-e]=new L(m.negint,e,1);Ot[64]=new L(m.bytes,new Uint8Array(0),1);Ot[96]=new L(m.string,"",1);Ot[128]=new L(m.array,0,1);Ot[160]=new L(m.map,0,1);Ot[244]=new L(m.false,!1,1);Ot[245]=new L(m.true,!0,1);Ot[246]=new L(m.null,null,1);function Jc(e){switch(e.type){case m.false:return $t([244]);case m.true:return $t([245]);case m.null:return $t([246]);case m.bytes:return e.value.length?void 0:$t([64]);case m.string:return e.value===""?$t([96]):void 0;case m.array:return e.value===0?$t([128]):void 0;case m.map:return e.value===0?$t([160]):void 0;case m.uint:return e.value<24?$t([Number(e.value)]):void 0;case m.negint:if(e.value>=-24)return $t([31-Number(e.value)])}}var Yd={float64:!1,mapSorter:Jd,quickEncodeToken:Jc};function Wd(){let e=[];return e[m.uint.major]=_t,e[m.negint.major]=Mn,e[m.bytes.major]=ar,e[m.string.major]=Tc,e[m.array.major]=Hn,e[m.map.major]=qn,e[m.tag.major]=$n,e[m.float.major]=zn,e}var Qc=Wd(),Oi=new Vr,jn=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(`${Li} object contains circular references`);return new e(r,t)}},Ee={null:new L(m.null,null),undefined:new L(m.undefined,void 0),true:new L(m.true,!0),false:new L(m.false,!1),emptyArray:new L(m.array,0),emptyMap:new L(m.map,0)},Se={number(e,t,r,n){return!Number.isInteger(e)||!Number.isSafeInteger(e)?new L(m.float,e):e>=0?new L(m.uint,e):new L(m.negint,e)},bigint(e,t,r,n){return e>=BigInt(0)?new L(m.uint,e):new L(m.negint,e)},Uint8Array(e,t,r,n){return new L(m.bytes,e)},string(e,t,r,n){return new L(m.string,e)},boolean(e,t,r,n){return e?Ee.true:Ee.false},null(e,t,r,n){return Ee.null},undefined(e,t,r,n){return Ee.undefined},ArrayBuffer(e,t,r,n){return new L(m.bytes,new Uint8Array(e))},DataView(e,t,r,n){return new L(m.bytes,new Uint8Array(e.buffer,e.byteOffset,e.byteLength))},Array(e,t,r,n){if(!e.length)return r.addBreakTokens===!0?[Ee.emptyArray,new L(m.break)]:Ee.emptyArray;n=jn.createCheck(n,e);let o=[],i=0;for(let s of e)o[i++]=Zn(s,r,n);return r.addBreakTokens?[new L(m.array,e.length),o,new L(m.break)]:[new L(m.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?[Ee.emptyMap,new L(m.break)]:Ee.emptyMap;n=jn.createCheck(n,e);let a=[],u=0;for(let d of i)a[u++]=[Zn(d,r,n),Zn(o?e.get(d):e[d],r,n)];return Xd(a,r),r.addBreakTokens?[new L(m.map,s),a,new L(m.break)]:[new L(m.map,s),a]}};Se.Map=Se.Object;Se.Buffer=Se.Uint8Array;for(let e of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))Se[`${e}Array`]=Se.DataView;function Zn(e,t={},r){let n=Xa(e),o=t&&t.typeEncoders&&t.typeEncoders[n]||Se[n];if(typeof o=="function"){let s=o(e,n,t,r);if(s!=null)return s}let i=Se[n];if(!i)throw new Error(`${Li} unsupported type: ${n}`);return i(e,n,t,r)}function Xd(e,t){t.mapSorter&&e.sort(t.mapSorter)}function Jd(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=Qc[o].compareTokens(r,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function tu(e,t,r,n){if(Array.isArray(t))for(let o of t)tu(e,o,r,n);else r[t.type.major](e,t,n)}function Qd(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 Vr(s);if(i(a,n,r),a.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return Ni(a.chunks[0])}}return Oi.reset(),tu(Oi,n,t,r),Oi.toBytes(!0)}function Mi(e,t){return t=Object.assign({},Yd,t),Qd(e,Qc,t)}var th={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},Yn=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=Ot[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}},zr=Symbol.for("DONE"),Wn=Symbol.for("BREAK");function eh(e,t,r){let n=[];for(let o=0;o<e.value;o++){let i=fr(t,r);if(i===Wn){if(e.value===1/0)break;throw new Error(`${F} got unexpected break to lengthed array`)}if(i===zr)throw new Error(`${F} found array but not enough entries (got ${o}, expected ${e.value})`);n[o]=i}return n}function rh(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=fr(t,r);if(a===Wn){if(e.value===1/0)break;throw new Error(`${F} got unexpected break to lengthed map`)}if(a===zr)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 u=fr(t,r);if(u===zr)throw new Error(`${F} found map but not enough entries (got ${s} [no value], expected ${e.value})`);n?i.set(a,u):o[a]=u}return n?i:o}function fr(e,t){if(e.done())return zr;let r=e.next();if(r.type===m.break)return Wn;if(r.type.terminal)return r.value;if(r.type===m.array)return eh(r,e,t);if(r.type===m.map)return rh(r,e,t);if(r.type===m.tag){if(t.tags&&typeof t.tags[r.value]=="function"){let n=fr(e,t);return t.tags[r.value](n)}throw new Error(`${F} tag not supported (${r.value})`)}throw new Error("unsupported")}function eu(e,t){if(!(e instanceof Uint8Array))throw new Error(`${F} data to decode must be a Uint8Array`);t=Object.assign({},th,t);let r=t.tokenizer||new Yn(e,t),n=fr(r,t);if(n===zr)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 Vi(e,t){let[r,n]=eu(e,t);if(n.length>0)throw new Error(`${F} too many terminals, data makes no sense`);return r}var oh=se("ipns:utils"),ru=M("/ipns/"),ih=114,sh=0,ah=18;function Gr(e){let t;if(e.pubKey!=null)try{t=Ga(e.pubKey)}catch(r){throw oh.error(r),r}if(t!=null)return t}function nu(e,t,r){let n=M(t);return ce([e,r,n])}function Jn(e){let t=M("ipns-signature:");return ce([t,e])}function Qn(e){return"signatureV1"in e?st.encode({value:M(e.value),signatureV1:e.signatureV1,validityType:e.validityType,validity:M(e.validity),sequence:e.sequence,ttl:e.ttl,pubKey:e.pubKey,signatureV2:e.signatureV2,data:e.data}):st.encode({pubKey:e.pubKey,signatureV2:e.signatureV2,data:e.data})}function zt(e){let t=st.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 Kt("Missing data or signatureV2");let r=su(t.data),n=ch(r.Value),o=V(r.Validity);if(t.value!=null&&t.signatureV1!=null)return uh(t),{value:n,validityType:st.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:st.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 Pe(e){return ce([ru,e.bytes])}function ou(e){let t=Zt(e.slice(ru.length));if(!Xn(t,sh)&&!Xn(t,ah))throw new Me("Multihash in IPNS key was not identity or sha2-256");return t}function iu(e,t,r,n,o){let i;if(t===st.ValidityType.EOL)i=0;else throw new Ne("The validity type is unsupported");return Mi({Value:e,Validity:r,ValidityType:i,Sequence:n,TTL:o})}function su(e){let t=Vi(e);if(t.ValidityType===0)t.ValidityType=st.ValidityType.EOL;else throw new Ne("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 ch(e){let t=V(e).trim();if(t.startsWith("/"))return t;try{return`/ipfs/${G.decode(e).toV1().toString()}`}catch{}try{return`/ipfs/${G.parse(t).toV1().toString()}`}catch{}throw new Or("Value must be a valid content path starting with /")}function au(e){if(e!=null){let t=dh(e);if(t!=null)return t.code===ih?`/ipns/${t.toString(Ut)}`:`/ipfs/${t.toV1().toString()}`;if(fh(e))return`/ipns/${Ut.encode(e.bytes)}`;let r=e.toString().trim();if(r.startsWith("/")&&r.length>1)return r}throw new Or("Value must be a valid content path starting with /")}function uh(e){if(e.data==null)throw new Fn("Record data is missing");let t=su(e.data);if(!J(t.Value,e.value??new Uint8Array(0)))throw new Kt('Field "value" did not match between protobuf and CBOR');if(!J(t.Validity,e.validity??new Uint8Array(0)))throw new Kt('Field "validity" did not match between protobuf and CBOR');if(t.ValidityType!==e.validityType)throw new Kt('Field "validityType" did not match between protobuf and CBOR');if(t.Sequence!==e.sequence)throw new Kt('Field "sequence" did not match between protobuf and CBOR');if(t.TTL!==e.ttl)throw new Kt('Field "ttl" did not match between protobuf and CBOR')}function fh(e){return e.bytes instanceof Uint8Array}function lh(e){return typeof e?.toCID=="function"}function dh(e){if(lh(e))return e.toCID();try{return G.parse(e)}catch{}return G.asCID(e)}function Xn(e,t){return e.code===t}var hh=se("ipns"),uu=5*60*1e9,ph="/ipns/",aw=ph.length,fu={v1Compatible:!0,ttlNs:uu};async function lu(e,t,r,n,o=fu){let i=new cu.default(Date.now()+Number(n)),s=st.ValidityType.EOL,a=BigInt(o.ttlNs??uu);return mh(e,t,r,s,i.toString(),a,o)}var mh=async(e,t,r,n,o,i,s=fu)=>{r=BigInt(r);let a=M(o),u=au(t),d=M(u),c=iu(d,n,a,r,i),l=Jn(c),y=await e.sign(l),b;if(e.type==="RSA"&&(b=fe(e.publicKey)),s.v1Compatible===!0){let T=await yh(e,d,n,a),A={value:u,signatureV1:T,validity:o,validityType:n,sequence:r,ttl:i,signatureV2:y,data:c};return b!=null&&(A.pubKey=b),A}else{let T={value:u,validity:o,validityType:n,sequence:r,ttl:i,signatureV2:y,data:c};return b!=null&&(T.pubKey=b),T}},yh=async(e,t,r,n)=>{try{let o=nu(t,r,n);return await e.sign(o)}catch(o){throw hh.error("record signature creation failed",o),new Pn("Record signature creation failed")}};var Hi=Wr(Ln(),1);function to(e,t){let r=t.map((n,o)=>({record:zt(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===st.ValidityType.EOL&&o.record.validityType===st.ValidityType.EOL){let a=Hi.default.fromString(n.record.validity).toDate(),u=Hi.default.fromString(o.record.validity).toDate();if(a.getTime()>u.getTime())return-1;if(a.getTime()<u.getTime())return 1}return 0}),r[0].index}var du=Wr(Ln(),1);var eo=se("ipns:validator"),gh=1024*10,xh=async(e,t)=>{let r=zt(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 Kt("Record signature verification failed");if(r.validityType===st.ValidityType.EOL){if(du.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 Ne("The validity type is unsupported");eo("ipns record for %s is valid",r.value)};async function Zr(e,t){if(t.byteLength>gh)throw new Kn("The record is too large");let r=ou(e),n;Xn(r,0)&&(n=Cn(r));let o=zt(t),i=Gr(o)??n;if(i==null)throw new Mr("Could not extract public key from IPNS record or routing key");let s=Pe(i.toMultihash());if(!J(s,e))throw new Mr("Embedded public key did not match routing key");await xh(i,t)}var lt=class extends Event{type;detail;constructor(t,r){super(t),this.type=t,this.detail=r}};var Eh=Wr(pu(),1);var re;(function(e){e[e.A=1]="A",e[e.CNAME=5]="CNAME",e[e.TXT=16]="TXT",e[e.AAAA=28]="AAAA"})(re||(re={}));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 Sh=32;async function mu(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:[re.TXT]}))?.Answer??[]).sort((d,c)=>d.data.localeCompare(c.data));n("found %d TXT records for %s",s.length,e);for(let d of s)try{let c=d.data;if(c.startsWith('"')&&c.endsWith('"')&&(c=c.substring(1,c.length-1)),!c.startsWith("dnslink="))continue;n("%s TXT %s",d.name,c),c=c.replace("dnslink=","");let[,l,y,...b]=c.split("/");if(l==="ipfs")try{return{value:`/ipfs/${G.parse(y)}${b.length>0?`/${b.join("/")}`:""}`,answer:d}}catch{}else if(l==="ipns"){try{let T;return y.charAt(0)==="1"||y.charAt(0)==="Q"?T=Rn(y):T=Ui(G.parse(y)),{value:`/ipns/${T}${b.length>0?`/${b.join("/")}`:""}`,answer:d}}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(c){n.error("could not parse DNS link record for domain %s, %s",e,d.data,c)}n("no DNSLink records found for %s, falling back to CNAME",e);let u=((await r.query(e,{...o,types:[re.CNAME]}))?.Answer??[]).sort((d,c)=>d.data.localeCompare(c.data));n("found %d CNAME records for %s",u.length,e);for(let d of u)try{return await ao(d.data,t-1,r,n,o)}catch(c){n.error("domain %s cname %s had no DNSLink records",e,d.data,c)}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 mu(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}`,mu(e,t,r,n,o)}}async function yu(e,t,r,n={}){return ao(e,n.maxRecursiveDepth??Sh,t,r,n)}var qi=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 lt("ipns:routing:helia:error",o)),o}}async get(t,r={}){try{return await this.routing.get(t,r)}catch(n){throw r.onProgress?.(new lt("ipns:routing:helia:error",n)),n}}};function gu(e){return new qi(e)}var jr;(function(e){let t;e.codec=()=>(t==null&&(t=be((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:It(0),value:It(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=>we(r,e.codec()),e.decode=(r,n)=>xe(r,e.codec(),n)})(jr||(jr={}));function xu(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(),u=String(a*1e3*1e3).padStart(9,"0");return`${t}-${r}-${n}T${o}:${i}:${s}.${u}Z`}function wu(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),u=parseInt(r[6],10),d=parseInt(r[7].slice(0,-6),10);return new Date(Date.UTC(n,o,i,s,a,u,d))}var ke=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 jr.encode(this.prepareSerialize())}prepareSerialize(){return{key:this.key,value:this.value,timeReceived:xu(this.timeReceived)}}static deserialize(t){let r=jr.decode(t);return new e(r.key,r.value,new Date(r.timeReceived))}static fromDeserialized(t){let r=wu(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 bu;(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"})(bu||(bu={}));function co(e){return new Fr("/dht/record/"+V(e,"base32"),!1)}function Eu(e){return{async put(t,r,n={}){try{let o=co(t);try{let s=await e.get(o),a=ke.deserialize(s);if(J(a.value,r))return}catch(s){if(s.name!=="NotFoundError")throw s}let i=new ke(t,r,new Date);n.onProgress?.(new lt("ipns:routing:datastore:put")),await e.put(o,i.serialize(),n)}catch(o){throw n.onProgress?.(new lt("ipns:routing:datastore:error",o)),o}},async get(t,r={}){try{let n=co(t);r.onProgress?.(new lt("ipns:routing:datastore:get"));let o=await e.get(n,r),i=ke.deserialize(o);return{record:i.value,created:i.timeReceived}}catch(n){throw r.onProgress?.(new lt("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 $i="/ipns/";function zi(e,t){return e.code===t}var ne=se("helia:ipns"),vu=60*1e3,Tu=60*vu,Bh=48*Tu,Gi=23*Tu,Su=BigInt(vu)*5000000n,Au={[Ut.prefix]:Ut,[z.prefix]:z},Zi=class{routers;localStore;timeout;dns;log;constructor(t,r=[]){this.routers=[gu(t.routing),...r],this.localStore=Eu(t.datastore),this.dns=t.dns,this.log=t.logger.forComponent("helia:ipns")}async publish(t,r,n={}){try{let o=1n,i=Pe(t.publicKey.toMultihash());if(await this.localStore.has(i,n)){let{record:d}=await this.localStore.get(i,n);o=zt(d).sequence+1n}let s=n.ttl!=null?BigInt(n.ttl)*1000000n:Su,a=await lu(t,r,o,n.lifetime??Bh,{...n,ttlNs:s}),u=Qn(a);return await this.localStore.put(i,u,n),n.offline!==!0&&await Promise.all(this.routers.map(async d=>{await d.put(i,u,n)})),a}catch(o){throw n.onProgress?.(new lt("ipns:publish:error",o)),o}}async resolve(t,r={}){let n=Wi(t)?t.toMultihash():t,o=Pe(n),i=await this.#e(o,r);return{...await this.#t(i.value,r),record:i}}async resolveDNSLink(t,r={}){let n=await yu(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 lt("ipns:republish:start"));let i=Date.now()-n,s=Gi-i;s<0&&(s=t.interval??Gi),setTimeout(()=>{r().catch(a=>{ne.error("error republishing",a)})},s)}this.timeout=setTimeout(()=>{r().catch(n=>{ne.error("error republishing",n)})},t.interval??Gi)}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=z.decode(`z${i}`);else if(Au[s]!=null)a=Au[s].decode(i);else throw new oo(`Unsupported multibase prefix "${s}"`);let u;try{u=Zt(a)}catch{u=G.decode(a).multihash}if(!zi(u,0)&&!zi(u,18))throw new io(`Unsupported multihash codec "${u.code}"`);let{cid:d}=await this.resolve(u,r),c=n.slice(3).join("/");return{cid:d,path:c}}else if(o==="ipfs"){let i=G.parse(n[2]),s=n.slice(3).join("/");return{cid:i,path:s}}}catch(o){ne.error("error parsing ipfs path",o)}throw ne.error("invalid ipfs path %s",t),new so("Invalid value")}async#e(t,r={}){let n=[];if(await this.localStore.has(t,r))if(ne("record is present in the cache"),r.nocache!==!0)try{let{record:a,created:u}=await this.localStore.get(t,r);this.log("record retrieved from cache"),await Zr(t,a),this.log("record was valid");let d=zt(a),c=Number((d.ttl??Su)/1000000n);if(u.getTime()+c>Date.now())return this.log("record TTL was valid"),d;if(r.offline===!0)return this.log("record TTL has been reached but we are resolving offline-only, returning record"),d;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 ne("ignoring local cache due to nocache=true option");if(r.offline===!0)throw new dr("Record was not present in the cache or has expired");ne("did not have record locally");let i=0;if(await Promise.all(this.routers.map(async a=>{let u;try{u=await a.get(t,{...r,validate:!1})}catch(d){ne.error("error finding IPNS record",d);return}try{await Zr(t,u),n.push(u)}catch(d){i++,ne.error("error finding IPNS record",d)}})),n.length===0)throw i>0?new no(`${i>1?`${i} records`:"Record"} found for routing key ${i>1?"were":"was"} invalid`):new dr("Could not find record for routing key");let s=n[to(t,n)];return await this.localStore.put(t,s,r),zt(s)}async republishRecord(t,r,n={}){let o;try{if(o=Gr(r)?.toMultihash(),o==null)if(typeof t=="string"){t.startsWith($i)&&(t=t.slice($i.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=Pe(o),s=Qn(r);await Zr(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 lt("ipns:republish:error",{key:o,record:r,err:i})),i}}};function Ih(e,{routers:t=[]}={}){return new Zi(e,t)}return Uu(Ch);})();
2
+ "use strict";var HeliaIpns=(()=>{var Pu=Object.create;var Xr=Object.defineProperty;var Ou=Object.getOwnPropertyDescriptor;var Mu=Object.getOwnPropertyNames;var Fu=Object.getPrototypeOf,Vu=Object.prototype.hasOwnProperty;var ns=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),bt=(e,t)=>{for(var r in t)Xr(e,r,{get:t[r],enumerable:!0})},os=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Mu(t))!Vu.call(e,o)&&o!==r&&Xr(e,o,{get:()=>t[o],enumerable:!(n=Ou(t,o))||n.enumerable});return e};var jr=(e,t,r)=>(r=e!=null?Pu(Fu(e)):{},os(t||!e||!e.__esModule?Xr(r,"default",{value:e,enumerable:!0}):r,e)),qu=e=>os(Xr({},"__esModule",{value:!0}),e);var _n=ns((Og,Mi)=>{var Pg=(function(){typeof Mi<"u"&&(Mi.exports=I);var e=86400,t=3200,r=146097*t/400,n=e*r,o=1e3*n,i=864e13,s=4294967296,a=1e6,c="000000000",f=Math.trunc||function(h){var p=h-h%1;return p==0&&(h<0||h===0&&1/h!=1/0)?-0:p},u=I.prototype,l=(I.fromDate=function(h){return new I(+h)},I.fromInt64BE=R(0,1,2,3,0,4),I.fromInt64LE=R(3,2,1,0,4,0),I.fromString=function(D){var p,_=new I,D=(D+="").replace(/^\s*[+\-]?\d+/,function(m){var m=+m,y=1970+(m-1970)%400;return _.year=m-y,y}).replace(/(?:Z|([+\-]\d{2}):?(\d{2}))$/,function(A,m,y){return m<0&&(y*=-1),p=6e4*(60*+m+ +y),""}).replace(/\.\d+$/,function(A){return _.nano=+(A+c).substr(1,9),""}).split(/\D+/);if(1<D.length?D[1]--:D[1]=0,_.time=p=Date.UTC.apply(Date,D)-(p||0),isNaN(p))throw new TypeError("Invalid Date");return T(_)},I.fromTimeT=function(h){return C(h,0)},u.year=0,u.time=0,u.nano=0,u.addNano=function(h){return this.nano+=+h||0,this},u.getNano=function(){var h=T(this);return(h.time%1e3*a+ +h.nano+1e9)%1e9},u.getTimeT=function(){var p=T(this),h=Math.floor(p.time/1e3),p=p.year;return p&&(h+=p*r*e/t),h},u.getYear=function(){return this.toDate().getUTCFullYear()+this.year},u.toDate=function(){return w(T(this).time)},u.toJSON=function(){return this.toString().replace(/0{1,6}Z$/,"Z")},u.toString=function(h){var p=this,_=p.toDate(),D={H:function(){return M(_.getUTCHours())},L:function(){return V(_.getUTCMilliseconds(),3)},M:function(){return M(_.getUTCMinutes())},N:function(){return V(p.getNano(),9)},S:function(){return M(_.getUTCSeconds())},Y:function(){var A=p.getYear();return 999999<A?"+"+A:9999<A?"+"+V(A,6):0<=A?V(A,4):-999999<=A?"-"+V(-A,6):A},a:function(){return v[_.getUTCDay()]},b:function(){return b[_.getUTCMonth()]},d:function(){return M(_.getUTCDate())},e:function(){return(function(A){return(9<A?"":" ")+(0|A)})(_.getUTCDate())},m:function(){return M(_.getUTCMonth()+1)}};return(function A(m){return m.replace(/%./g,function(y){var E=y[1],d=x[E],E=D[E];return d?A(d):E?E():y})})(h||l)},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"),b=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],v=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],x={"%":"%",F:"%Y-%m-%d",n:`
3
+ `,R:"%H:%M",T:"%H:%M:%S",t:" ",X:"%T",Z:"GMT",z:"+0000"};return I;function I(h,p,_){var D=this;if(!(D instanceof I))return new I(h,p,_);D.time=+h||0,D.nano=+p||0,D.year=+_||0,T(D)}function T(h){var p,_,D,A=h.year,m=h.time,y=h.nano,d=((y<0||a<=y)&&(y-=(_=Math.floor(y/a))*a,m+=_,_=1),A%t);return(m<-i||i<m||d)&&((p=f(m/o))&&(A+=p*t,m-=p*o),(D=w(m)).setUTCFullYear(d+D.getUTCFullYear()),D=(m=+D)+(p=f((A-=d)/t))*o,p&&-i<=D&&D<=i&&(A-=p*t,m=D),_=1),_&&(h.year=A,h.time=m,h.nano=y),h}function w(h){var p=new Date(0);return p.setTime(h),p}function C(A,D){A=+A||0;var _=f((D=(D|0)*s)/n)+f(A/n),D=D%n+A%n,A=f(D/n);return A&&(_+=A,D-=A*n),new I(1e3*D,0,_*t)}function S(h,p,_,D,A,m){return function(d,E){var L=T(this);d=d||new Array(8),P(d,E|=0);var k=Math.floor(L.time/1e3),L=L.year*(r*e/t),U=f(L/s)+f(k/s),L=L%s+k%s,k=Math.floor(L/s);return k&&(U+=k,L-=k*s),y(d,E+A,U),y(d,E+m,L),d};function y(d,E,U){d[E+h]=U>>24&255,d[E+p]=U>>16&255,d[E+_]=U>>8&255,d[E+D]=255&U}}function R(h,p,_,D,A,m){return function(d,E){P(d,E|=0);var U=y(d,E+A);return C(y(d,E+m),U)};function y(d,E){return 16777216*d[E+h]+(d[E+p]<<16|d[E+_]<<8|d[E+D])}}function P(h,p){if(h=h&&h.length,h==null)throw new TypeError("Invalid Buffer");if(h<p+8)throw new RangeError("Out of range")}function M(h){return(9<h?"":"0")+(0|h)}function V(h,p){return(c+(0|h)).substr(-p)}})()});var vu=ns((Nb,Au)=>{Au.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 Lh={};bt(Lh,{ipns:()=>Rh,ipnsSelector:()=>jn,ipnsValidator:()=>zr});var st=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Ve=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var dr=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}};var Wr=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},Jr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var qe=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};function is(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 so=Symbol.for("@libp2p/peer-id");var lo={};bt(lo,{base32:()=>Vt,base32hex:()=>Ju,base32hexpad:()=>tf,base32hexpadupper:()=>ef,base32hexupper:()=>Qu,base32pad:()=>ju,base32padupper:()=>Wu,base32upper:()=>Xu,base32z:()=>rf});var Oh=new Uint8Array(0);function ss(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 Gt(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 as(e){return new TextEncoder().encode(e)}function cs(e){return new TextDecoder().decode(e)}function $u(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(x){if(x instanceof Uint8Array||(ArrayBuffer.isView(x)?x=new Uint8Array(x.buffer,x.byteOffset,x.byteLength):Array.isArray(x)&&(x=Uint8Array.from(x))),!(x instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(x.length===0)return"";for(var I=0,T=0,w=0,C=x.length;w!==C&&x[w]===0;)w++,I++;for(var S=(C-w)*u+1>>>0,R=new Uint8Array(S);w!==C;){for(var P=x[w],M=0,V=S-1;(P!==0||M<T)&&V!==-1;V--,M++)P+=256*R[V]>>>0,R[V]=P%a>>>0,P=P/a>>>0;if(P!==0)throw new Error("Non-zero carry");T=M,w++}for(var h=S-T;h!==S&&R[h]===0;)h++;for(var p=c.repeat(I);h<S;++h)p+=e.charAt(R[h]);return p}function b(x){if(typeof x!="string")throw new TypeError("Expected String");if(x.length===0)return new Uint8Array;var I=0;if(x[I]!==" "){for(var T=0,w=0;x[I]===c;)T++,I++;for(var C=(x.length-I)*f+1>>>0,S=new Uint8Array(C);x[I];){var R=r[x.charCodeAt(I)];if(R===255)return;for(var P=0,M=C-1;(R!==0||P<w)&&M!==-1;M--,P++)R+=a*S[M]>>>0,S[M]=R%256>>>0,R=R/256>>>0;if(R!==0)throw new Error("Non-zero carry");w=P,I++}if(x[I]!==" "){for(var V=C-w;V!==C&&S[V]===0;)V++;for(var h=new Uint8Array(T+(C-V)),p=T;V!==C;)h[p++]=S[V++];return h}}}function v(x){var I=b(x);if(I)return I;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:b,decode:v}}var Hu=$u,zu=Hu,fs=zu;var ao=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")}},co=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 ls(this,t)}},uo=class{decoders;constructor(t){this.decoders=t}or(t){return ls(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 ls(e,t){return new uo({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var fo=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 ao(t,r,n),this.decoder=new co(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function $e({name:e,prefix:t,encode:r,decode:n}){return new fo(e,t,r,n)}function ce({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=fs(r,e);return $e({prefix:t,name:e,encode:n,decode:i=>Gt(o(i))})}function Zu(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 Yu(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 Gu(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=Gu(n);return $e({prefix:t,name:e,encode(i){return Yu(i,n,r)},decode(i){return Zu(i,o,r,e)}})}var Vt=rt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Xu=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}),Ju=rt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Qu=rt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),tf=rt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ef=rt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),rf=rt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ho={};bt(ho,{base58btc:()=>G,base58flickr:()=>nf});var G=ce({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),nf=ce({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var po={};bt(po,{base64:()=>hr,base64pad:()=>of,base64url:()=>sf,base64urlpad:()=>af});var hr=rt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),of=rt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),sf=rt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),af=rt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});function cf(e,t){if(typeof e=="string")return uf(e);if(typeof e=="number")return df(e,t);throw Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(e)}`)}var Qr=cf;function uf(e){if(typeof e!="string"||e.length===0||e.length>100)throw Error(`Value provided to ms.parse() must be a string with length between 1 and 99. value=${JSON.stringify(e)}`);let t=/^(?<value>-?\d*\.?\d+) *(?<unit>milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.exec(e);if(!t?.groups)return NaN;let{value:r,unit:n="ms"}=t.groups,o=parseFloat(r),i=n.toLowerCase();switch(i){case"years":case"year":case"yrs":case"yr":case"y":return o*315576e5;case"months":case"month":case"mo":return o*26298e5;case"weeks":case"week":case"w":return o*6048e5;case"days":case"day":case"d":return o*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return o*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return o*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return o*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return o;default:throw Error(`Unknown unit "${i}" provided to ms.parse(). value=${JSON.stringify(e)}`)}}function ff(e){let t=Math.abs(e);return t>=315576e5?`${Math.round(e/315576e5)}y`:t>=26298e5?`${Math.round(e/26298e5)}mo`:t>=6048e5?`${Math.round(e/6048e5)}w`: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 lf(e){let t=Math.abs(e);return t>=315576e5?Te(e,t,315576e5,"year"):t>=26298e5?Te(e,t,26298e5,"month"):t>=6048e5?Te(e,t,6048e5,"week"):t>=864e5?Te(e,t,864e5,"day"):t>=36e5?Te(e,t,36e5,"hour"):t>=6e4?Te(e,t,6e4,"minute"):t>=1e3?Te(e,t,1e3,"second"):`${e} ms`}function df(e,t){if(typeof e!="number"||!Number.isFinite(e))throw Error("Value provided to ms.format() must be of type number.");return t?.long?lf(e):ff(e)}function Te(e,t,r,n){let o=t>=r*1.5;return`${Math.round(e/r)} ${n}${o?"s":""}`}function mo(e){r.debug=r,r.default=r,r.coerce=c,r.disable=i,r.enable=o,r.enabled=s,r.humanize=Qr,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 b=0;b<u.length;b++)l=(l<<5)-l+u.charCodeAt(b),l|=0;return r.colors[Math.abs(l)%r.colors.length]}r.selectColor=t;function r(u){let l,b=null,v,x;function I(...T){if(!I.enabled)return;let w=I,C=Number(new Date),S=C-(l||C);w.diff=S,w.prev=l,w.curr=C,l=C,T[0]=r.coerce(T[0]),typeof T[0]!="string"&&T.unshift("%O");let R=0;T[0]=T[0].replace(/%([a-zA-Z%])/g,(M,V)=>{if(M==="%%")return"%";R++;let h=r.formatters[V];if(typeof h=="function"){let p=T[R];M=h.call(w,p),T.splice(R,1),R--}return M}),r.formatArgs.call(w,T),(w.log||r.log).apply(w,T)}return I.namespace=u,I.useColors=r.useColors(),I.color=r.selectColor(u),I.extend=n,I.destroy=r.destroy,Object.defineProperty(I,"enabled",{enumerable:!0,configurable:!1,get:()=>b!==null?b:(v!==r.namespaces&&(v=r.namespaces,x=r.enabled(u)),x),set:T=>{b=T}}),typeof r.init=="function"&&r.init(I),I}function n(u,l){let b=r(this.namespace+(typeof l>"u"?":":l)+u);return b.log=this.log,b}function o(u){r.save(u),r.namespaces=u,r.names=[],r.skips=[];let l,b=(typeof u=="string"?u:"").split(/[\s,]+/),v=b.length;for(l=0;l<v;l++)b[l]&&(u=b[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,b;for(l=0,b=r.skips.length;l<b;l++)if(r.skips[l].test(u))return!1;for(l=0,b=r.names.length;l<b;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 tn=bf(),hf=["#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 pf(){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 mf(e){if(e[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+e[0]+(this.useColors?"%c ":" ")+"+"+Qr(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 yf=console.debug??console.log??(()=>{});function gf(e){try{e?tn?.setItem("debug",e):tn?.removeItem("debug")}catch{}}function xf(){let e;try{e=tn?.getItem("debug")}catch{}return!e&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(e=globalThis.process.env.DEBUG),e}function bf(){try{return localStorage}catch{}}function wf(e){e.j=function(t){try{return JSON.stringify(t)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var ds=mo({formatArgs:mf,save:gf,load:xf,useColors:pf,setupFormatters:wf,colors:hf,storage:tn,log:yf});var X=ds;X.formatters.b=e=>e==null?"undefined":G.baseEncode(e);X.formatters.t=e=>e==null?"undefined":Vt.baseEncode(e);X.formatters.m=e=>e==null?"undefined":hr.baseEncode(e);X.formatters.p=e=>e==null?"undefined":e.toString();X.formatters.c=e=>e==null?"undefined":e.toString();X.formatters.k=e=>e==null?"undefined":e.toString();X.formatters.a=e=>e==null?"undefined":e.toString();X.formatters.e=e=>{if(e==null)return"undefined";let t=hs(e.message),r=hs(e.stack);return t!=null&&r!=null?r.includes(t)?r:`${t}
4
+ ${r}`:r??t??e.toString()};function Ef(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 yo(e){let t=Ef(`${e}:trace`);return X.enabled(`${e}:trace`)&&X.names.map(r=>r.toString()).find(r=>r.includes(":trace"))!=null&&(t=X(`${e}:trace`)),Object.assign(X(e),{error:X(`${e}:error`),trace:t,newScope:r=>yo(`${e}:${r}`)})}function hs(e){if(e!=null&&(e=e.trim(),e.length!==0))return e}var go={};bt(go,{base36:()=>Lt,base36upper:()=>Sf});var Lt=ce({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Sf=ce({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Af=ys,ps=128,vf=127,If=~vf,Tf=Math.pow(2,31);function ys(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Tf;)t[r++]=e&255|ps,e/=128;for(;e&If;)t[r++]=e&255|ps,e>>>=7;return t[r]=e|0,ys.bytes=r-n+1,t}var Bf=xo,Cf=128,ms=127;function xo(e,n){var r=0,n=n||0,o=0,i=n,s,a=e.length;do{if(i>=a)throw xo.bytes=0,new RangeError("Could not decode varint");s=e[i++],r+=o<28?(s&ms)<<o:(s&ms)*Math.pow(2,o),o+=7}while(s>=Cf);return xo.bytes=i-n,r}var _f=Math.pow(2,7),Df=Math.pow(2,14),Uf=Math.pow(2,21),Rf=Math.pow(2,28),Lf=Math.pow(2,35),Nf=Math.pow(2,42),kf=Math.pow(2,49),Kf=Math.pow(2,56),Pf=Math.pow(2,63),Of=function(e){return e<_f?1:e<Df?2:e<Uf?3:e<Rf?4:e<Lf?5:e<Nf?6:e<kf?7:e<Kf?8:e<Pf?9:10},Mf={encode:Af,decode:Bf,encodingLength:Of},Ff=Mf,pr=Ff;function mr(e,t=0){return[pr.decode(e,t),pr.decode.bytes]}function He(e,t,r=0){return pr.encode(e,t,r),t}function ze(e){return pr.encodingLength(e)}function qt(e,t){let r=t.byteLength,n=ze(e),o=n+ze(r),i=new Uint8Array(o+r);return He(e,i,0),He(r,i,n),i.set(t,o),new Ze(e,r,t,i)}function Xt(e){let t=Gt(e),[r,n]=mr(t),[o,i]=mr(t.subarray(n)),s=t.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Ze(r,o,s,t)}function gs(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&ss(e.bytes,r.bytes)}}var Ze=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function xs(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return qf(r,bo(e),t??G.encoder);default:return $f(r,bo(e),t??Vt.encoder)}}var bs=new WeakMap;function bo(e){let t=bs.get(e);if(t==null){let r=new Map;return bs.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!==yr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Hf)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=qt(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&&gs(t.multihash,n.multihash)}toString(t){return xs(this,t)}toJSON(){return{"/":xs(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??ws(n,o,i.bytes))}else if(r[zf]===!0){let{version:n,multihash:o,code:i}=r,s=Xt(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!==yr)throw new Error(`Version 0 CID must use dag-pb (code: ${yr}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=ws(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,yr,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=Gt(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 Ze(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,b]=mr(t.subarray(r));return r+=b,l},o=n(),i=yr;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]=Vf(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 bo(i).set(n,t),i}};function Vf(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 Vt.prefix:{let r=t??Vt;return[Vt.prefix,r.decode(e)]}case Lt.prefix:{let r=t??Lt;return[Lt.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 qf(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 $f(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 yr=112,Hf=18;function ws(e,t,r){let n=ze(e),o=n+ze(t),i=new Uint8Array(o+r.byteLength);return He(e,i,0),He(t,i,n),i.set(r,o),i}var zf=Symbol.for("@ipld/js-cid/CID");var wo={};bt(wo,{identity:()=>Nt});var Es=0,Zf="identity",Ss=Gt;function Yf(e,t){if(t?.truncate!=null&&t.truncate!==e.byteLength){if(t.truncate<0||t.truncate>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,t.truncate)}return qt(Es,Ss(e))}var Nt={code:Es,name:Zf,encode:Ss,digest:Yf};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 _t(e=0){return new Uint8Array(e)}function St(e=0){return new Uint8Array(e)}function fe(e,t){t==null&&(t=e.reduce((o,i)=>o+i.length,0));let r=St(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var vs=Symbol.for("@achingbrain/uint8arraylist");function As(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 rn(e){return!!e?.[vs]}var At=class e{bufs;length;[vs]=!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(rn(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(rn(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=As(this.bufs,t);return r.buf[r.index]}set(t,r){let n=As(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(rn(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 fe(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:fe(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(!rn(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 b=f;b>=0;b--){let v=this.get(l+b);if(n[b]!==v){u=Math.max(1,b-a[v]);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=St(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=_t(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=_t(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=_t(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=St(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=_t(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=_t(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=_t(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=_t(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=_t(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 Eo={};bt(Eo,{base10:()=>Gf});var Gf=ce({prefix:"9",name:"base10",alphabet:"0123456789"});var So={};bt(So,{base16:()=>Xf,base16upper:()=>jf});var Xf=rt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),jf=rt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Ao={};bt(Ao,{base2:()=>Wf});var Wf=rt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var vo={};bt(vo,{base256emoji:()=>rl});var Is=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}"),Jf=Is.reduce((e,t,r)=>(e[r]=t,e),[]),Qf=Is.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function tl(e){return e.reduce((t,r)=>(t+=Jf[r],t),"")}function el(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Qf[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var rl=$e({prefix:"\u{1F680}",name:"base256emoji",encode:tl,decode:el});var Io={};bt(Io,{base8:()=>nl});var nl=rt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var To={};bt(To,{identity:()=>ol});var ol=$e({prefix:"\0",name:"identity",encode:e=>cs(e),decode:e=>as(e)});var N0=new TextEncoder,k0=new TextDecoder;var _o={};bt(_o,{sha256:()=>gr,sha512:()=>cl});var al=20;function Co({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new Bo(e,t,r,n,o)}var Bo=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,i){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??al,this.maxDigestLength=i}digest(t,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?Ts(n,this.code,r?.truncate):n.then(o=>Ts(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Ts(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return qt(t,e)}function Cs(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var gr=Co({name:"sha2-256",code:18,encode:Cs("SHA-256")}),cl=Co({name:"sha2-512",code:19,encode:Cs("SHA-512")});var Do={...To,...Ao,...Io,...Eo,...So,...lo,...go,...ho,...po,...vo},Y0={..._o,...wo};function Ds(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var _s=Ds("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Uo=Ds("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=St(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),ul={utf8:_s,"utf-8":_s,hex:Do.base16,latin1:Uo,ascii:Uo,binary:Uo,...Do},nn=ul;function z(e,t="utf8"){let r=nn[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function Z(e,t="utf8"){let r=nn[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var fl=parseInt("11111",2),Ro=parseInt("10000000",2),ll=parseInt("01111111",2),Us={0:xr,1:xr,2:dl,3:ml,4:yl,5:pl,6:hl,16:xr,22:xr,48:xr};function jt(e,t={offset:0}){let r=e[t.offset]&fl;if(t.offset++,Us[r]!=null)return Us[r](e,t);throw new Error("No decoder for tag "+r)}function br(e,t){let r=0;if((e[t.offset]&Ro)===Ro){let n=e[t.offset]&ll,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 xr(e,t){br(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=jt(e,t);if(n===null)break;r.push(n)}return r}function dl(e,t){let r=br(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 hl(e,t){let r=br(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 pl(e,t){return t.offset++,null}function ml(e,t){let r=br(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 yl(e,t){let r=br(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function gl(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new At;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function Lo(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=gl(e.byteLength);return new At(Uint8Array.from([t.byteLength|Ro]),t)}function wt(e){let t=new At,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new At(Uint8Array.from([2]),Lo(t),t)}function on(e){let t=Uint8Array.from([0]),r=new At(t,e);return new At(Uint8Array.from([3]),Lo(r),r)}function le(e,t=48){let r=new At;for(let n of e)r.append(n);return new At(Uint8Array.from([t]),Lo(r),r)}async function Rs(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 xl=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),bl=Uint8Array.from([6,5,43,129,4,0,34]),wl=Uint8Array.from([6,5,43,129,4,0,35]),El={ext:!0,kty:"EC",crv:"P-256"},Sl={ext:!0,kty:"EC",crv:"P-384"},Al={ext:!0,kty:"EC",crv:"P-521"},No=32,ko=48,Ko=66;function Po(e){let t=jt(e);return Ls(t)}function Ls(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===No*2+1)return n=Z(t.subarray(r,r+No),"base64url"),o=Z(t.subarray(r+No),"base64url"),new Ye({...El,key_ops:["verify"],x:n,y:o});if(t.byteLength===ko*2+1)return n=Z(t.subarray(r,r+ko),"base64url"),o=Z(t.subarray(r+ko),"base64url"),new Ye({...Sl,key_ops:["verify"],x:n,y:o});if(t.byteLength===Ko*2+1)return n=Z(t.subarray(r,r+Ko),"base64url"),o=Z(t.subarray(r+Ko),"base64url"),new Ye({...Al,key_ops:["verify"],x:n,y:o});throw new st(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Ns(e){return le([wt(Uint8Array.from([1])),le([vl(e.crv)],160),le([on(new At(Uint8Array.from([4]),z(e.x??"","base64url"),z(e.y??"","base64url")))],161)]).subarray()}function vl(e){if(e==="P-256")return xl;if(e==="P-384")return bl;if(e==="P-521")return wl;throw new st(`Invalid curve ${e}`)}var Ye=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Ns(this.jwk)),this._raw}toMultihash(){return Nt.digest(de(this))}toCID(){return j.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 Rs(this.jwk,r,t,n)}};function Be(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function $t(e,t=""){if(!Number.isSafeInteger(e)||e<0){let r=t&&`"${t}" `;throw new Error(`${r}expected integer >= 0, got ${e}`)}}function $(e,t,r=""){let n=Be(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 sn(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash must wrapped by utils.createHasher");$t(e.outputLen),$t(e.blockLen)}function Ge(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 Ks(e,t){$(e,void 0,"digestInto() output");let r=t.outputLen;if(e.length<r)throw new Error('"digestInto() output" expected to be of length >='+r)}function Jt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function an(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function kt(e,t){return e<<32-t|e>>>t}var Ps=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Il=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Qt(e){if($(e),Ps)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Il[e[r]];return t}var Wt={_0:48,_9:57,A:65,F:70,a:97,f:102};function ks(e){if(e>=Wt._0&&e<=Wt._9)return e-Wt._0;if(e>=Wt.A&&e<=Wt.F)return e-(Wt.A-10);if(e>=Wt.a&&e<=Wt.f)return e-(Wt.a-10)}function te(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(Ps)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=ks(e.charCodeAt(i)),a=ks(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 Et(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];$(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}function Oo(e,t={}){let r=(o,i)=>e(i).update(o).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.create=o=>e(o),Object.assign(r,t),Object.freeze(r)}function Xe(e=32){let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return t.getRandomValues(new Uint8Array(e))}var Mo=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function Os(e,t,r){return e&t^~e&r}function Ms(e,t,r){return e&t^e&r^t&r}var wr=class{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,r,n,o){this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=an(this.buffer)}update(t){Ge(this),$(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=an(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){Ge(this),Ks(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;r[s++]=128,Jt(this.buffer.subarray(s)),this.padOffset>o-s&&(this.process(n,0),s=0);for(let l=s;l<o;l++)r[l]=0;n.setBigUint64(o-8,BigInt(this.length*8),i),this.process(n,0);let a=an(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must 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||=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()}},ee=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var lt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var cn=BigInt(4294967295),Fs=BigInt(32);function Tl(e,t=!1){return t?{h:Number(e&cn),l:Number(e>>Fs&cn)}:{h:Number(e>>Fs&cn)|0,l:Number(e&cn)|0}}function Vs(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 Fo=(e,t,r)=>e>>>r,Vo=(e,t,r)=>e<<32-r|t>>>r,Ce=(e,t,r)=>e>>>r|t<<32-r,_e=(e,t,r)=>e<<32-r|t>>>r,Er=(e,t,r)=>e<<64-r|t>>>r-32,Sr=(e,t,r)=>e>>>r-32|t<<64-r;function Ht(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var qs=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),$s=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,Hs=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),zs=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,Zs=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Ys=(e,t,r,n,o,i)=>t+r+n+o+i+(e/2**32|0)|0;var Cl=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]),he=new Uint32Array(64),qo=class extends wr{constructor(t){super(64,t,8,!1)}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)he[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let b=he[l-15],v=he[l-2],x=kt(b,7)^kt(b,18)^b>>>3,I=kt(v,17)^kt(v,19)^v>>>10;he[l]=I+he[l-7]+x+he[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 b=kt(a,6)^kt(a,11)^kt(a,25),v=u+b+Os(a,c,f)+Cl[l]+he[l]|0,I=(kt(n,2)^kt(n,13)^kt(n,22))+Ms(n,o,i)|0;u=f,f=c,c=a,a=s+v|0,s=i,i=o,o=n,n=v+I|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(){Jt(he)}destroy(){this.set(0,0,0,0,0,0,0,0),Jt(this.buffer)}},$o=class extends qo{A=ee[0]|0;B=ee[1]|0;C=ee[2]|0;D=ee[3]|0;E=ee[4]|0;F=ee[5]|0;G=ee[6]|0;H=ee[7]|0;constructor(){super(32)}};var Gs=Vs(["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))),_l=Gs[0],Dl=Gs[1],pe=new Uint32Array(80),me=new Uint32Array(80),Ho=class extends wr{constructor(t){super(128,t,16,!1)}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:b,Gh:v,Gl:x,Hh:I,Hl:T}=this;return[t,r,n,o,i,s,a,c,f,u,l,b,v,x,I,T]}set(t,r,n,o,i,s,a,c,f,u,l,b,v,x,I,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=f|0,this.El=u|0,this.Fh=l|0,this.Fl=b|0,this.Gh=v|0,this.Gl=x|0,this.Hh=I|0,this.Hl=T|0}process(t,r){for(let S=0;S<16;S++,r+=4)pe[S]=t.getUint32(r),me[S]=t.getUint32(r+=4);for(let S=16;S<80;S++){let R=pe[S-15]|0,P=me[S-15]|0,M=Ce(R,P,1)^Ce(R,P,8)^Fo(R,P,7),V=_e(R,P,1)^_e(R,P,8)^Vo(R,P,7),h=pe[S-2]|0,p=me[S-2]|0,_=Ce(h,p,19)^Er(h,p,61)^Fo(h,p,6),D=_e(h,p,19)^Sr(h,p,61)^Vo(h,p,6),A=Hs(V,D,me[S-7],me[S-16]),m=zs(A,M,_,pe[S-7],pe[S-16]);pe[S]=m|0,me[S]=A|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:c,Dh:f,Dl:u,Eh:l,El:b,Fh:v,Fl:x,Gh:I,Gl:T,Hh:w,Hl:C}=this;for(let S=0;S<80;S++){let R=Ce(l,b,14)^Ce(l,b,18)^Er(l,b,41),P=_e(l,b,14)^_e(l,b,18)^Sr(l,b,41),M=l&v^~l&I,V=b&x^~b&T,h=Zs(C,P,V,Dl[S],me[S]),p=Ys(h,w,R,M,_l[S],pe[S]),_=h|0,D=Ce(n,o,28)^Er(n,o,34)^Er(n,o,39),A=_e(n,o,28)^Sr(n,o,34)^Sr(n,o,39),m=n&i^n&a^i&a,y=o&s^o&c^s&c;w=I|0,C=T|0,I=v|0,T=x|0,v=l|0,x=b|0,{h:l,l:b}=Ht(f|0,u|0,p|0,_|0),f=a|0,u=c|0,a=i|0,c=s|0,i=n|0,s=o|0;let d=qs(_,A,y);n=$s(d,p,D,m),o=d|0}({h:n,l:o}=Ht(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=Ht(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:c}=Ht(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=Ht(this.Dh|0,this.Dl|0,f|0,u|0),{h:l,l:b}=Ht(this.Eh|0,this.El|0,l|0,b|0),{h:v,l:x}=Ht(this.Fh|0,this.Fl|0,v|0,x|0),{h:I,l:T}=Ht(this.Gh|0,this.Gl|0,I|0,T|0),{h:w,l:C}=Ht(this.Hh|0,this.Hl|0,w|0,C|0),this.set(n,o,i,s,a,c,f,u,l,b,v,x,I,T,w,C)}roundClean(){Jt(pe,me)}destroy(){Jt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},zo=class extends Ho{Ah=lt[0]|0;Al=lt[1]|0;Bh=lt[2]|0;Bl=lt[3]|0;Ch=lt[4]|0;Cl=lt[5]|0;Dh=lt[6]|0;Dl=lt[7]|0;Eh=lt[8]|0;El=lt[9]|0;Fh=lt[10]|0;Fl=lt[11]|0;Gh=lt[12]|0;Gl=lt[13]|0;Hh=lt[14]|0;Hl=lt[15]|0;constructor(){super(64)}};var je=Oo(()=>new $o,Mo(1));var Xs=Oo(()=>new zo,Mo(3));var Yo=BigInt(0),Zo=BigInt(1);function re(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}" `;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function js(e){if(typeof e=="bigint"){if(!un(e))throw new Error("positive bigint expected, got "+e)}else $t(e);return e}function Ar(e){let t=js(e).toString(16);return t.length&1?"0"+t:t}function Ws(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?Yo:BigInt("0x"+e)}function We(e){return Ws(Qt(e))}function De(e){return Ws(Qt(ln($(e)).reverse()))}function fn(e,t){$t(t),e=js(e);let r=te(e.toString(16).padStart(t*2,"0"));if(r.length!==t)throw new Error("number too large");return r}function Go(e,t){return fn(e,t).reverse()}function ln(e){return Uint8Array.from(e)}var un=e=>typeof e=="bigint"&&Yo<=e;function Ul(e,t,r){return un(e)&&un(t)&&un(r)&&t<=e&&e<r}function vr(e,t,r,n){if(!Ul(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Xo(e){let t;for(t=0;e>Yo;e>>=Zo,t+=1);return t}var Ir=e=>(Zo<<BigInt(e))-Zo;function Js(e,t,r){if($t(e,"hashLen"),$t(t,"qByteLen"),typeof r!="function")throw new Error("hmacFn must be a function");let n=T=>new Uint8Array(T),o=Uint8Array.of(),i=Uint8Array.of(0),s=Uint8Array.of(1),a=1e3,c=n(e),f=n(e),u=0,l=()=>{c.fill(1),f.fill(0),u=0},b=(...T)=>r(f,Et(c,...T)),v=(T=o)=>{f=b(i,T),c=b(),T.length!==0&&(f=b(s,T),c=b())},x=()=>{if(u++>=a)throw new Error("drbg: tried max amount of iterations");let T=0,w=[];for(;T<t;){c=b();let C=c.slice();w.push(C),T+=c.length}return Et(...w)};return(T,w)=>{l(),v(T);let C;for(;!(C=w(x()));)v();return l(),C}}function ye(e,t={},r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(i,s,a){let c=e[i];if(a&&c===void 0)return;let f=typeof c;if(f!==s||c===null)throw new Error(`param "${i}" is invalid: expected ${s}, got ${f}`)}let o=(i,s)=>Object.entries(i).forEach(([a,c])=>n(a,c,s));o(t,!1),o(r,!0)}function Je(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),Ue=BigInt(2),ea=BigInt(3),ra=BigInt(4),na=BigInt(5),Rl=BigInt(7),oa=BigInt(8),Ll=BigInt(9),ia=BigInt(16);function ot(e,t){let r=e%t;return r>=gt?r:t+r}function J(e,t,r){let n=e;for(;t-- >gt;)n*=n,n%=r;return n}function Qs(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=ot(e,t),n=t,o=gt,i=at,s=at,a=gt;for(;r!==gt;){let f=n/r,u=n%r,l=o-s*f,b=i-a*f;n=r,r=u,o=s,i=a,s=l,a=b}if(n!==at)throw new Error("invert: does not exist");return ot(o,t)}function Wo(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function sa(e,t){let r=(e.ORDER+at)/ra,n=e.pow(t,r);return Wo(e,n,t),n}function Nl(e,t){let r=(e.ORDER-na)/oa,n=e.mul(t,Ue),o=e.pow(n,r),i=e.mul(t,o),s=e.mul(e.mul(i,Ue),o),a=e.mul(i,e.sub(s,e.ONE));return Wo(e,a,t),a}function kl(e){let t=Qe(e),r=aa(e),n=r(t,t.neg(t.ONE)),o=r(t,n),i=r(t,t.neg(n)),s=(e+Rl)/ia;return(a,c)=>{let f=a.pow(c,s),u=a.mul(f,n),l=a.mul(f,o),b=a.mul(f,i),v=a.eql(a.sqr(u),c),x=a.eql(a.sqr(l),c);f=a.cmov(f,u,v),u=a.cmov(b,l,x);let I=a.eql(a.sqr(u),c),T=a.cmov(f,u,I);return Wo(a,T,c),T}}function aa(e){if(e<ea)throw new Error("sqrt is not defined for small field");let t=e-at,r=0;for(;t%Ue===gt;)t/=Ue,r++;let n=Ue,o=Qe(e);for(;ta(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return sa;let i=o.pow(n,t),s=(t+at)/Ue;return function(c,f){if(c.is0(f))return f;if(ta(c,f)!==1)throw new Error("Cannot find square root");let u=r,l=c.mul(c.ONE,i),b=c.pow(f,t),v=c.pow(f,s);for(;!c.eql(b,c.ONE);){if(c.is0(b))return c.ZERO;let x=1,I=c.sqr(b);for(;!c.eql(I,c.ONE);)if(x++,I=c.sqr(I),x===u)throw new Error("Cannot find square root");let T=at<<BigInt(u-x-1),w=c.pow(l,T);u=x,l=c.sqr(w),b=c.mul(b,l),v=c.mul(v,w)}return v}}function Kl(e){return e%ra===ea?sa:e%oa===na?Nl:e%ia===Ll?kl(e):aa(e)}var ca=(e,t)=>(ot(e,t)&at)===at,Pl=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Jo(e){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},r=Pl.reduce((n,o)=>(n[o]="function",n),t);return ye(e,r),e}function Ol(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 Tr(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 ta(e,t){let r=(e.ORDER-at)/Ue,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 Ml(e,t){t!==void 0&&$t(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}var jo=class{ORDER;BITS;BYTES;isLE;ZERO=gt;ONE=at;_lengths;_sqrt;_mod;constructor(t,r={}){if(t<=gt)throw new Error("invalid field: expected ORDER > 0, got "+t);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&(this.sqrt=r.sqrt),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=r.allowedLengths?.slice()),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:i}=Ml(t,n);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=o,this.BYTES=i,this._sqrt=void 0,Object.preventExtensions(this)}create(t){return ot(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof t);return gt<=t&&t<this.ORDER}is0(t){return t===gt}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&at)===at}neg(t){return ot(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return ot(t*t,this.ORDER)}add(t,r){return ot(t+r,this.ORDER)}sub(t,r){return ot(t-r,this.ORDER)}mul(t,r){return ot(t*r,this.ORDER)}pow(t,r){return Ol(this,t,r)}div(t,r){return ot(t*Qs(r,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,r){return t+r}subN(t,r){return t-r}mulN(t,r){return t*r}inv(t){return Qs(t,this.ORDER)}sqrt(t){return this._sqrt||(this._sqrt=Kl(this.ORDER)),this._sqrt(this,t)}toBytes(t){return this.isLE?Go(t,this.BYTES):fn(t,this.BYTES)}fromBytes(t,r=!1){$(t);let{_lengths:n,BYTES:o,isLE:i,ORDER:s,_mod:a}=this;if(n){if(!n.includes(t.length)||t.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let f=new Uint8Array(o);f.set(t,i?0:f.length-t.length),t=f}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let c=i?De(t):We(t);if(a&&(c=ot(c,s)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return Tr(this,t)}cmov(t,r,n){return n?r:t}};function Qe(e,t={}){return new jo(e,t)}function ua(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=ua(e);return t+Math.ceil(t/2)}function ti(e,t,r=!1){$(e);let n=e.length,o=ua(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?De(e):We(e),a=ot(s,t-at)+at;return r?Go(a,o):fn(a,o)}var tr=BigInt(0),Re=BigInt(1);function Br(e,t){let r=t.negate();return e?r:t}function Le(e,t){let r=Tr(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function ha(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){ha(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,i=Ir(e),s=BigInt(e);return{windows:r,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function fa(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+=Re);let f=t*n,u=f+Math.abs(a)-1,l=a===0,b=a<0,v=t%2!==0;return{nextN:c,offset:u,isZero:l,isNeg:b,isNegF:v,offsetF:f}}var ri=new WeakMap,pa=new WeakMap;function ni(e){return pa.get(e)||1}function la(e){if(e!==tr)throw new Error("invalid wNAF")}var er=class{BASE;ZERO;Fn;bits;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>tr;)r&Re&&(n=n.add(o)),o=o.double(),r>>=Re;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=ei(r,this.bits),i=[],s=t,a=s;for(let c=0;c<n;c++){a=s,i.push(a);for(let f=1;f<o;f++)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=ei(t,this.bits);for(let a=0;a<s.windows;a++){let{nextN:c,offset:f,isZero:u,isNeg:l,isNegF:b,offsetF:v}=fa(n,a,s);n=c,u?i=i.add(Br(b,r[v])):o=o.add(Br(l,r[f]))}return la(n),{p:o,f:i}}wNAFUnsafe(t,r,n,o=this.ZERO){let i=ei(t,this.bits);for(let s=0;s<i.windows&&n!==tr;s++){let{nextN:a,offset:c,isZero:f,isNeg:u}=fa(n,s,i);if(n=a,!f){let l=r[c];o=o.add(u?l.negate():l)}}return la(n),o}getPrecomputes(t,r,n){let o=ri.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),ri.set(r,o))),o}cached(t,r,n){let o=ni(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let i=ni(t);return i===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(i,this.getPrecomputes(i,t,n),r,o)}createCache(t,r){ha(r,this.bits),pa.set(t,r),ri.delete(t)}hasCache(t){return ni(t)!==1}};function ma(e,t,r,n){let o=t,i=e.ZERO,s=e.ZERO;for(;r>tr||n>tr;)r&Re&&(i=i.add(o)),n&Re&&(s=s.add(o)),o=o.double(),r>>=Re,n>>=Re;return{p1:i,p2:s}}function da(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Jo(t),t}else return Qe(e,{isLE:r})}function dn(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 f=t[c];if(!(typeof f=="bigint"&&f>tr))throw new Error(`CURVE.${c} must be positive bigint`)}let o=da(t.p,r.Fp,n),i=da(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}}function hn(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var ge=BigInt(0),ct=BigInt(1),oi=BigInt(2),Fl=BigInt(8);function Vl(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 ya(e,t={}){let r=dn("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r,i=r.CURVE,{h:s}=i;ye(t,{},{uvRatio:"function"});let a=oi<<BigInt(o.BYTES*8)-ct,c=T=>n.create(T),f=t.uvRatio||((T,w)=>{try{return{isValid:!0,value:n.sqrt(n.div(T,w))}}catch{return{isValid:!1,value:ge}}});if(!Vl(n,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function u(T,w,C=!1){let S=C?ct:ge;return vr("coordinate "+T,w,S,a),w}function l(T){if(!(T instanceof x))throw new Error("EdwardsPoint expected")}let b=Je((T,w)=>{let{X:C,Y:S,Z:R}=T,P=T.is0();w==null&&(w=P?Fl:n.inv(R));let M=c(C*w),V=c(S*w),h=n.mul(R,w);if(P)return{x:ge,y:ct};if(h!==ct)throw new Error("invZ was invalid");return{x:M,y:V}}),v=Je(T=>{let{a:w,d:C}=i;if(T.is0())throw new Error("bad point: ZERO");let{X:S,Y:R,Z:P,T:M}=T,V=c(S*S),h=c(R*R),p=c(P*P),_=c(p*p),D=c(V*w),A=c(p*c(D+h)),m=c(_+c(C*c(V*h)));if(A!==m)throw new Error("bad point: equation left != right (1)");let y=c(S*R),d=c(P*M);if(y!==d)throw new Error("bad point: equation left != right (2)");return!0});class x{static BASE=new x(i.Gx,i.Gy,ct,c(i.Gx*i.Gy));static ZERO=new x(ge,ct,ct,ge);static Fp=n;static Fn=o;X;Y;Z;T;constructor(w,C,S,R){this.X=u("x",w),this.Y=u("y",C),this.Z=u("z",S,!0),this.T=u("t",R),Object.freeze(this)}static CURVE(){return i}static fromAffine(w){if(w instanceof x)throw new Error("extended point not allowed");let{x:C,y:S}=w||{};return u("x",C),u("y",S),new x(C,S,ct,c(C*S))}static fromBytes(w,C=!1){let S=n.BYTES,{a:R,d:P}=i;w=ln($(w,S,"point")),re(C,"zip215");let M=ln(w),V=w[S-1];M[S-1]=V&-129;let h=De(M),p=C?a:n.ORDER;vr("point.y",h,ge,p);let _=c(h*h),D=c(_-ct),A=c(P*_-R),{isValid:m,value:y}=f(D,A);if(!m)throw new Error("bad point: invalid y coordinate");let d=(y&ct)===ct,E=(V&128)!==0;if(!C&&y===ge&&E)throw new Error("bad point: x=0 and x_0=1");return E!==d&&(y=c(-y)),x.fromAffine({x:y,y:h})}static fromHex(w,C=!1){return x.fromBytes(te(w),C)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(w=8,C=!0){return I.createCache(this,w),C||this.multiply(oi),this}assertValidity(){v(this)}equals(w){l(w);let{X:C,Y:S,Z:R}=this,{X:P,Y:M,Z:V}=w,h=c(C*V),p=c(P*R),_=c(S*V),D=c(M*R);return h===p&&_===D}is0(){return this.equals(x.ZERO)}negate(){return new x(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:w}=i,{X:C,Y:S,Z:R}=this,P=c(C*C),M=c(S*S),V=c(oi*c(R*R)),h=c(w*P),p=C+S,_=c(c(p*p)-P-M),D=h+M,A=D-V,m=h-M,y=c(_*A),d=c(D*m),E=c(_*m),U=c(A*D);return new x(y,d,U,E)}add(w){l(w);let{a:C,d:S}=i,{X:R,Y:P,Z:M,T:V}=this,{X:h,Y:p,Z:_,T:D}=w,A=c(R*h),m=c(P*p),y=c(V*S*D),d=c(M*_),E=c((R+P)*(h+p)-A-m),U=d-y,L=d+y,k=c(m-C*A),K=c(E*U),O=c(L*k),q=c(E*k),Q=c(U*L);return new x(K,O,Q,q)}subtract(w){return this.add(w.negate())}multiply(w){if(!o.isValidNot0(w))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:C,f:S}=I.cached(this,w,R=>Le(x,R));return Le(x,[C,S])[0]}multiplyUnsafe(w,C=x.ZERO){if(!o.isValid(w))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return w===ge?x.ZERO:this.is0()||w===ct?this:I.unsafe(this,w,S=>Le(x,S),C)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}isTorsionFree(){return I.unsafe(this,i.n).is0()}toAffine(w){return b(this,w)}clearCofactor(){return s===ct?this:this.multiplyUnsafe(s)}toBytes(){let{x:w,y:C}=this.toAffine(),S=n.toBytes(C);return S[S.length-1]|=w&ct?128:0,S}toHex(){return Qt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let I=new er(x,o.BITS);return x.BASE.precompute(8),x}function ga(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');ye(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||Xe,c=r.adjustScalarBytes||(h=>h),f=r.domain||((h,p,_)=>{if(re(_,"phflag"),p.length||_)throw new Error("Contexts/pre-hash are not supported");return h});function u(h){return s.create(De(h))}function l(h){let p=S.secretKey;$(h,S.secretKey,"secretKey");let _=$(t(h),2*p,"hashedSecretKey"),D=c(_.slice(0,p)),A=_.slice(p,2*p),m=u(D);return{head:D,prefix:A,scalar:m}}function b(h){let{head:p,prefix:_,scalar:D}=l(h),A=o.multiply(D),m=A.toBytes();return{head:p,prefix:_,scalar:D,point:A,pointBytes:m}}function v(h){return b(h).pointBytes}function x(h=Uint8Array.of(),...p){let _=Et(...p);return u(t(f(_,$(h,void 0,"context"),!!n)))}function I(h,p,_={}){h=$(h,void 0,"message"),n&&(h=n(h));let{prefix:D,scalar:A,pointBytes:m}=b(p),y=x(_.context,D,h),d=o.multiply(y).toBytes(),E=x(_.context,d,m,h),U=s.create(y+E*A);if(!s.isValid(U))throw new Error("sign failed: invalid s");let L=Et(d,s.toBytes(U));return $(L,S.signature,"result")}let T={zip215:!0};function w(h,p,_,D=T){let{context:A,zip215:m}=D,y=S.signature;h=$(h,y,"signature"),p=$(p,void 0,"message"),_=$(_,S.publicKey,"publicKey"),m!==void 0&&re(m,"zip215"),n&&(p=n(p));let d=y/2,E=h.subarray(0,d),U=De(h.subarray(d,y)),L,k,K;try{L=e.fromBytes(_,m),k=e.fromBytes(E,m),K=o.multiplyUnsafe(U)}catch{return!1}if(!m&&L.isSmallOrder())return!1;let O=x(A,k.toBytes(),L.toBytes(),p);return k.add(L.multiplyUnsafe(O)).subtract(K).clearCofactor().is0()}let C=i.BYTES,S={secretKey:C,publicKey:C,signature:2*C,seed:C};function R(h=a(S.seed)){return $(h,S.seed,"seed")}function P(h){return Be(h)&&h.length===s.BYTES}function M(h,p){try{return!!e.fromBytes(h,p)}catch{return!1}}let V={getExtendedPublicKey:b,randomSecretKey:R,isValidSecretKey:P,isValidPublicKey:M,toMontgomery(h){let{y:p}=e.fromBytes(h),_=S.publicKey,D=_===32;if(!D&&_!==57)throw new Error("only defined for 25519 and 448");let A=D?i.div(ct+p,ct-p):i.div(p-ct,p+ct);return i.toBytes(A)},toMontgomerySecret(h){let p=S.secretKey;$(h,p);let _=t(h.subarray(0,p));return c(_).subarray(0,p)}};return Object.freeze({keygen:hn(R,v),getPublicKey:v,sign:I,verify:w,utils:V,Point:e,lengths:S})}var ql=BigInt(1),xa=BigInt(2);var $l=BigInt(5),Hl=BigInt(8),ii=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),zl={p:ii,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Hl,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Zl(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),i=ii,a=e*e%i*e%i,c=J(a,xa,i)*a%i,f=J(c,ql,i)*e%i,u=J(f,$l,i)*f%i,l=J(u,t,i)*u%i,b=J(l,r,i)*l%i,v=J(b,n,i)*b%i,x=J(v,o,i)*v%i,I=J(x,o,i)*v%i,T=J(I,t,i)*u%i;return{pow_p_5_8:J(T,xa,i)*e%i,b2:a}}function Yl(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var ba=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Gl(e,t){let r=ii,n=ot(t*t*t,r),o=ot(n*n*t,r),i=Zl(e*o).pow_p_5_8,s=ot(e*n*i,r),a=ot(t*s*s,r),c=s,f=ot(s*ba,r),u=a===e,l=a===ot(-e,r),b=a===ot(-e*ba,r);return u&&(s=c),(l||b)&&(s=f),ca(s,r)&&(s=ot(-s,r)),{isValid:u||l,value:s}}var Xl=ya(zl,{uvRatio:Gl});function jl(e){return ga(Xl,Xs,Object.assign({adjustScalarBytes:Yl},e))}var wa=jl({});var Cr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},pn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Ea={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new pn("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 Dt=Ea;var mn=32;var si,Wl=(async()=>{try{return await Dt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Jl(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await Dt.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await Dt.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 Ql(e,t,r){return wa.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function Sa(e,t,r){return si==null&&(si=await Wl),si?Jl(e,t,r):Ql(e,t,r)}function yn(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var gn=class{type="Ed25519";raw;constructor(t){this.raw=ai(t,mn)}toMultihash(){return Nt.digest(de(this))}toCID(){return j.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=Sa(this.raw,r,t);return yn(o)?o.then(i=>(n?.signal?.throwIfAborted(),i)):o}};function ci(e){return e=ai(e,mn),new gn(e)}function ai(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new st(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var ed=Math.pow(2,7),rd=Math.pow(2,14),nd=Math.pow(2,21),va=Math.pow(2,28),Ia=Math.pow(2,35),Ta=Math.pow(2,42),Ba=Math.pow(2,49),xt=128,xe=127;function _r(e){if(e<ed)return 1;if(e<rd)return 2;if(e<nd)return 3;if(e<va)return 4;if(e<Ia)return 5;if(e<Ta)return 6;if(e<Ba)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ca(e,t,r=0){switch(_r(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 _a(e,t){let r=e[t],n=0;if(n+=r&xe,r<xt||(r=e[t+1],n+=(r&xe)<<7,r<xt)||(r=e[t+2],n+=(r&xe)<<14,r<xt)||(r=e[t+3],n+=(r&xe)<<21,r<xt)||(r=e[t+4],n+=(r&xe)*va,r<xt)||(r=e[t+5],n+=(r&xe)*Ia,r<xt)||(r=e[t+6],n+=(r&xe)*Ta,r<xt)||(r=e[t+7],n+=(r&xe)*Ba,r<xt))return n;throw new RangeError("Could not decode varint")}var ui=new Float32Array([-0]),be=new Uint8Array(ui.buffer);function Da(e,t,r){ui[0]=e,t[r]=be[0],t[r+1]=be[1],t[r+2]=be[2],t[r+3]=be[3]}function Ua(e,t){return be[0]=e[t],be[1]=e[t+1],be[2]=e[t+2],be[3]=e[t+3],ui[0]}var fi=new Float64Array([-0]),mt=new Uint8Array(fi.buffer);function Ra(e,t,r){fi[0]=e,t[r]=mt[0],t[r+1]=mt[1],t[r+2]=mt[2],t[r+3]=mt[3],t[r+4]=mt[4],t[r+5]=mt[5],t[r+6]=mt[6],t[r+7]=mt[7]}function La(e,t){return mt[0]=e[t],mt[1]=e[t+1],mt[2]=e[t+2],mt[3]=e[t+3],mt[4]=e[t+4],mt[5]=e[t+5],mt[6]=e[t+6],mt[7]=e[t+7],fi[0]}var od=BigInt(Number.MAX_SAFE_INTEGER),id=BigInt(Number.MIN_SAFE_INTEGER),vt=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 Ne;if(t<od&&t>id)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>Na&&(o=0n,++n>Na&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return Ne;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):Ne}},Ne=new vt(0,0);Ne.toBigInt=function(){return 0n};Ne.zzEncode=Ne.zzDecode=function(){return this};Ne.length=function(){return 1};var Na=4294967296n;function ka(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 Ka(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 li(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 Kt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function xn(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var di=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,Kt(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 Kt(this,4);return xn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Kt(this,4);return xn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Kt(this,4);let t=Ua(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Kt(this,4);let t=La(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 Kt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return Ka(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Kt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Kt(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 vt(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 Kt(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 Kt(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 Kt(this,8);let t=xn(this.buf,this.pos+=4),r=xn(this.buf,this.pos+=4);return new vt(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=_a(this.buf,this.pos);return this.pos+=_r(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 hi(e){return new di(e instanceof Uint8Array?e:e.subarray())}function we(e,t,r){let n=hi(e);return t.decode(n,void 0,r)}function pi(e){let t=e??8192,r=t>>>1,n,o=t;return function(s){if(s<1||s>r)return St(s);o+s>t&&(n=St(t),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var ke=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function mi(){}var gi=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},sd=pi();function ad(e){return globalThis.Buffer!=null?St(e):sd(e)}var Ur=class{len;head;tail;states;constructor(){this.len=0,this.head=new ke(mi,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new ke(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new xi((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(bn,10,vt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=vt.fromBigInt(t);return this._push(bn,r.length(),r)}uint64Number(t){return this._push(Ca,_r(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=vt.fromBigInt(t).zzEncode();return this._push(bn,r.length(),r)}sint64Number(t){let r=vt.fromNumber(t).zzEncode();return this._push(bn,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(yi,1,t?1:0)}fixed32(t){return this._push(Dr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=vt.fromBigInt(t);return this._push(Dr,4,r.lo)._push(Dr,4,r.hi)}fixed64Number(t){let r=vt.fromNumber(t);return this._push(Dr,4,r.lo)._push(Dr,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(Da,4,t)}double(t){return this._push(Ra,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(yi,1,0):this.uint32(r)._push(ud,r,t)}string(t){let r=ka(t);return r!==0?this.uint32(r)._push(li,r,t):this._push(yi,1,0)}fork(){return this.states=new gi(this),this.head=this.tail=new ke(mi,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 ke(mi,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=ad(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function yi(e,t,r){t[r]=e&255}function cd(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var xi=class extends ke{next;constructor(t,r){super(cd,t,r),this.next=void 0}};function bn(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 Dr(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 ud(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(Ur.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(fd,t,e),this},Ur.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(ld,t,e),this});function fd(e,t,r){t.set(e,r)}function ld(e,t,r){e.length<40?li(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(z(e),r)}function bi(){return new Ur}function Ee(e,t){let r=bi();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var rr;(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"})(rr||(rr={}));function wn(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function Rr(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 wn("enum",rr.VARINT,r,n)}function Se(e,t){return wn("message",rr.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=()=>Rr(wi)})(it||(it={}));var zt;(function(e){let t;e.codec=()=>(t==null&&(t=Se((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=>Ee(r,e.codec()),e.decode=(r,n)=>we(r,e.codec(),n)})(zt||(zt={}));var Ei;(function(e){let t;e.codec=()=>(t==null&&(t=Se((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=>Ee(r,e.codec()),e.decode=(r,n)=>we(r,e.codec(),n)})(Ei||(Ei={}));var Nr={};bt(Nr,{MAX_RSA_KEY_SIZE:()=>Si,generateRSAKeyPair:()=>qa,jwkToJWKKeyPair:()=>$a,jwkToPkcs1:()=>md,jwkToPkix:()=>Ti,jwkToRSAPrivateKey:()=>Di,pkcs1MessageToJwk:()=>vi,pkcs1MessageToRSAPrivateKey:()=>Bi,pkcs1ToJwk:()=>pd,pkcs1ToRSAPrivateKey:()=>Va,pkixMessageToJwk:()=>Ii,pkixMessageToRSAPublicKey:()=>_i,pkixToJwk:()=>yd,pkixToRSAPublicKey:()=>Ci});var nr=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Nr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return j.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 Fa(this.jwk,r,t,n)}},Lr=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Nr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:nt(this.raw,t.raw)}sign(t,r){return Ma(this.jwk,t,r)}};var Si=8192,Ai=18,dd=1062,hd=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function pd(e){let t=jt(e);return vi(t)}function vi(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 md(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 st("JWK was missing components");return le([wt(Uint8Array.from([0])),wt(z(e.n,"base64url")),wt(z(e.e,"base64url")),wt(z(e.d,"base64url")),wt(z(e.p,"base64url")),wt(z(e.q,"base64url")),wt(z(e.dp,"base64url")),wt(z(e.dq,"base64url")),wt(z(e.qi,"base64url"))]).subarray()}function yd(e){let t=jt(e,{offset:0});return Ii(t)}function Ii(e){let t=jt(e[1],{offset:0});return{kty:"RSA",n:Z(t[0],"base64url"),e:Z(t[1],"base64url")}}function Ti(e){if(e.n==null||e.e==null)throw new st("JWK was missing components");return le([hd,on(le([wt(z(e.n,"base64url")),wt(z(e.e,"base64url"))]))]).subarray()}function Va(e){let t=jt(e);return Bi(t)}function Bi(e){let t=vi(e);return Di(t)}function Ci(e,t){if(e.byteLength>=dd)throw new Ve("Key size is too large");let r=jt(e,{offset:0});return _i(r,e,t)}function _i(e,t,r){let n=Ii(e);if(r==null){let o=je(zt.encode({Type:it.RSA,Data:t}));r=qt(Ai,o)}return new nr(n,r)}function Di(e){if(za(e)>Si)throw new st("Key size is too large");let t=$a(e),r=je(zt.encode({Type:it.RSA,Data:Ti(t.publicKey)})),n=qt(Ai,r);return new Lr(t.privateKey,new nr(t.publicKey,n))}async function qa(e){if(e>Si)throw new st("Key size is too large");let t=await Ha(e),r=je(zt.encode({Type:it.RSA,Data:Ti(t.publicKey)})),n=qt(Ai,r);return new Lr(t.privateKey,new nr(t.publicKey,n))}function $a(e){if(e==null)throw new st("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function Ha(e,t){let r=await Dt.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 gd(r,t);return{privateKey:n[0],publicKey:n[1]}}async function Ma(e,t,r){let n=await Dt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Dt.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 Fa(e,t,r,n){let o=await Dt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let i=await Dt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),i}async function gd(e,t){if(e.privateKey==null||e.publicKey==null)throw new st("Private and public key are required");let r=await Promise.all([Dt.get().subtle.exportKey("jwk",e.privateKey),Dt.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function za(e){if(e.kty!=="RSA")throw new st("invalid key type");if(e.n==null)throw new st("invalid key modulus");return z(e.n,"base64url").length*8}var En=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(t,r){if(sn(t),$(r,void 0,"key"),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 n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?t.create().update(r).digest():r);for(let i=0;i<o.length;i++)o[i]^=54;this.iHash.update(o),this.oHash=t.create();for(let i=0;i<o.length;i++)o[i]^=106;this.oHash.update(o),Jt(o)}update(t){return Ge(this),this.iHash.update(t),this}digestInto(t){Ge(this),$(t,this.outputLen,"output"),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||=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 En(e,t).update(r).digest();Ui.create=(e,t)=>new En(e,t);var Za=(e,t)=>(e+(e>=0?t:-t)/Ya)/t;function xd(e,t,r){let[[n,o],[i,s]]=t,a=Za(s*e,r),c=Za(-o*e,r),f=e-a*n-c*i,u=-a*o-c*s,l=f<ne,b=u<ne;l&&(f=-f),b&&(u=-u);let v=Ir(Math.ceil(Xo(r)/2))+or;if(f<ne||f>=v||u<ne||u>=v)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:l,k1:f,k2neg:b,k2:u}}function Li(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Ri(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return re(r.lowS,"lowS"),re(r.prehash,"prehash"),r.format!==void 0&&Li(r.format),r}var Ni=class extends Error{constructor(t=""){super(t)}},Ae={Err:Ni,_tlv:{encode:(e,t)=>{let{Err:r}=Ae;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=Ar(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let i=n>127?Ar(o.length/2|128):"";return Ar(e)+i+o+t},decode(e,t){let{Err:r}=Ae,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}=Ae;if(e<ne)throw new t("integer: negative integers are not allowed");let r=Ar(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}=Ae;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 We(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Ae,o=$(e,void 0,"signature"),{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}=Ae,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),i=n+o;return t.encode(48,i)}},ne=BigInt(0),or=BigInt(1),Ya=BigInt(2),Sn=BigInt(3),bd=BigInt(4);function Ga(e,t={}){let r=dn("weierstrass",e,t),{Fp:n,Fn:o}=r,i=r.CURVE,{h:s,n:a}=i;ye(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});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 f=ja(n,o);function u(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(A,m,y){let{x:d,y:E}=m.toAffine(),U=n.toBytes(d);if(re(y,"isCompressed"),y){u();let L=!n.isOdd(E);return Et(Xa(L),U)}else return Et(Uint8Array.of(4),U,n.toBytes(E))}function b(A){$(A,void 0,"Point");let{publicKey:m,publicKeyUncompressed:y}=f,d=A.length,E=A[0],U=A.subarray(1);if(d===m&&(E===2||E===3)){let L=n.fromBytes(U);if(!n.isValid(L))throw new Error("bad point: is not on curve, wrong x");let k=I(L),K;try{K=n.sqrt(k)}catch(Q){let W=Q instanceof Error?": "+Q.message:"";throw new Error("bad point: is not on curve, sqrt error"+W)}u();let O=n.isOdd(K);return(E&1)===1!==O&&(K=n.neg(K)),{x:L,y:K}}else if(d===y&&E===4){let L=n.BYTES,k=n.fromBytes(U.subarray(0,L)),K=n.fromBytes(U.subarray(L,L*2));if(!T(k,K))throw new Error("bad point: is not on curve");return{x:k,y:K}}else throw new Error(`bad point: got length ${d}, expected compressed=${m} or uncompressed=${y}`)}let v=t.toBytes||l,x=t.fromBytes||b;function I(A){let m=n.sqr(A),y=n.mul(m,A);return n.add(n.add(y,n.mul(A,i.a)),i.b)}function T(A,m){let y=n.sqr(m),d=I(A);return n.eql(y,d)}if(!T(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let w=n.mul(n.pow(i.a,Sn),bd),C=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(w,C)))throw new Error("bad curve params: a or b");function S(A,m,y=!1){if(!n.isValid(m)||y&&n.is0(m))throw new Error(`bad point coordinate ${A}`);return m}function R(A){if(!(A instanceof p))throw new Error("Weierstrass Point expected")}function P(A){if(!c||!c.basises)throw new Error("no endo");return xd(A,c.basises,o.ORDER)}let M=Je((A,m)=>{let{X:y,Y:d,Z:E}=A;if(n.eql(E,n.ONE))return{x:y,y:d};let U=A.is0();m==null&&(m=U?n.ONE:n.inv(E));let L=n.mul(y,m),k=n.mul(d,m),K=n.mul(E,m);if(U)return{x:n.ZERO,y:n.ZERO};if(!n.eql(K,n.ONE))throw new Error("invZ was invalid");return{x:L,y:k}}),V=Je(A=>{if(A.is0()){if(t.allowInfinityPoint&&!n.is0(A.Y))return;throw new Error("bad point: ZERO")}let{x:m,y}=A.toAffine();if(!n.isValid(m)||!n.isValid(y))throw new Error("bad point: x or y not field elements");if(!T(m,y))throw new Error("bad point: equation left != right");if(!A.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function h(A,m,y,d,E){return y=new p(n.mul(y.X,A),y.Y,y.Z),m=Br(d,m),y=Br(E,y),m.add(y)}class p{static BASE=new p(i.Gx,i.Gy,n.ONE);static ZERO=new p(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(m,y,d){this.X=S("x",m),this.Y=S("y",y,!0),this.Z=S("z",d),Object.freeze(this)}static CURVE(){return i}static fromAffine(m){let{x:y,y:d}=m||{};if(!m||!n.isValid(y)||!n.isValid(d))throw new Error("invalid affine point");if(m instanceof p)throw new Error("projective point not allowed");return n.is0(y)&&n.is0(d)?p.ZERO:new p(y,d,n.ONE)}static fromBytes(m){let y=p.fromAffine(x($(m,void 0,"point")));return y.assertValidity(),y}static fromHex(m){return p.fromBytes(te(m))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=8,y=!0){return D.createCache(this,m),y||this.multiply(Sn),this}assertValidity(){V(this)}hasEvenY(){let{y:m}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(m)}equals(m){R(m);let{X:y,Y:d,Z:E}=this,{X:U,Y:L,Z:k}=m,K=n.eql(n.mul(y,k),n.mul(U,E)),O=n.eql(n.mul(d,k),n.mul(L,E));return K&&O}negate(){return new p(this.X,n.neg(this.Y),this.Z)}double(){let{a:m,b:y}=i,d=n.mul(y,Sn),{X:E,Y:U,Z:L}=this,k=n.ZERO,K=n.ZERO,O=n.ZERO,q=n.mul(E,E),Q=n.mul(U,U),W=n.mul(L,L),H=n.mul(E,U);return H=n.add(H,H),O=n.mul(E,L),O=n.add(O,O),k=n.mul(m,O),K=n.mul(d,W),K=n.add(k,K),k=n.sub(Q,K),K=n.add(Q,K),K=n.mul(k,K),k=n.mul(H,k),O=n.mul(d,O),W=n.mul(m,W),H=n.sub(q,W),H=n.mul(m,H),H=n.add(H,O),O=n.add(q,q),q=n.add(O,q),q=n.add(q,W),q=n.mul(q,H),K=n.add(K,q),W=n.mul(U,L),W=n.add(W,W),q=n.mul(W,H),k=n.sub(k,q),O=n.mul(W,Q),O=n.add(O,O),O=n.add(O,O),new p(k,K,O)}add(m){R(m);let{X:y,Y:d,Z:E}=this,{X:U,Y:L,Z:k}=m,K=n.ZERO,O=n.ZERO,q=n.ZERO,Q=i.a,W=n.mul(i.b,Sn),H=n.mul(y,U),tt=n.mul(d,L),ft=n.mul(E,k),Ft=n.add(y,d),et=n.add(U,L);Ft=n.mul(Ft,et),et=n.add(H,tt),Ft=n.sub(Ft,et),et=n.add(y,E);let pt=n.add(U,k);return et=n.mul(et,pt),pt=n.add(H,ft),et=n.sub(et,pt),pt=n.add(d,E),K=n.add(L,k),pt=n.mul(pt,K),K=n.add(tt,ft),pt=n.sub(pt,K),q=n.mul(Q,et),K=n.mul(W,ft),q=n.add(K,q),K=n.sub(tt,q),q=n.add(tt,q),O=n.mul(K,q),tt=n.add(H,H),tt=n.add(tt,H),ft=n.mul(Q,ft),et=n.mul(W,et),tt=n.add(tt,ft),ft=n.sub(H,ft),ft=n.mul(Q,ft),et=n.add(et,ft),H=n.mul(tt,et),O=n.add(O,H),H=n.mul(pt,et),K=n.mul(Ft,K),K=n.sub(K,H),H=n.mul(Ft,tt),q=n.mul(pt,q),q=n.add(q,H),new p(K,O,q)}subtract(m){return this.add(m.negate())}is0(){return this.equals(p.ZERO)}multiply(m){let{endo:y}=t;if(!o.isValidNot0(m))throw new Error("invalid scalar: out of range");let d,E,U=L=>D.cached(this,L,k=>Le(p,k));if(y){let{k1neg:L,k1:k,k2neg:K,k2:O}=P(m),{p:q,f:Q}=U(k),{p:W,f:H}=U(O);E=Q.add(H),d=h(y.beta,q,W,L,K)}else{let{p:L,f:k}=U(m);d=L,E=k}return Le(p,[d,E])[0]}multiplyUnsafe(m){let{endo:y}=t,d=this;if(!o.isValid(m))throw new Error("invalid scalar: out of range");if(m===ne||d.is0())return p.ZERO;if(m===or)return d;if(D.hasCache(this))return this.multiply(m);if(y){let{k1neg:E,k1:U,k2neg:L,k2:k}=P(m),{p1:K,p2:O}=ma(p,d,U,k);return h(y.beta,K,O,E,L)}else return D.unsafe(d,m)}toAffine(m){return M(this,m)}isTorsionFree(){let{isTorsionFree:m}=t;return s===or?!0:m?m(p,this):D.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:m}=t;return s===or?this:m?m(p,this):this.multiplyUnsafe(s)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}toBytes(m=!0){return re(m,"isCompressed"),this.assertValidity(),v(p,this,m)}toHex(m=!0){return Qt(this.toBytes(m))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let _=o.BITS,D=new er(p,t.endo?Math.ceil(_/2):_);return p.BASE.precompute(8),p}function Xa(e){return Uint8Array.of(e?2:3)}function ja(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function wd(e,t={}){let{Fn:r}=e,n=t.randomBytes||Xe,o=Object.assign(ja(e.Fp,r),{seed:Qo(r.ORDER)});function i(v){try{let x=r.fromBytes(v);return r.isValidNot0(x)}catch{return!1}}function s(v,x){let{publicKey:I,publicKeyUncompressed:T}=o;try{let w=v.length;return x===!0&&w!==I||x===!1&&w!==T?!1:!!e.fromBytes(v)}catch{return!1}}function a(v=n(o.seed)){return ti($(v,o.seed,"seed"),r.ORDER)}function c(v,x=!0){return e.BASE.multiply(r.fromBytes(v)).toBytes(x)}function f(v){let{secretKey:x,publicKey:I,publicKeyUncompressed:T}=o;if(!Be(v)||"_lengths"in r&&r._lengths||x===I)return;let w=$(v,void 0,"key").length;return w===I||w===T}function u(v,x,I=!0){if(f(v)===!0)throw new Error("first arg must be private key");if(f(x)===!1)throw new Error("second arg must be public key");let T=r.fromBytes(v);return e.fromBytes(x).multiply(T).toBytes(I)}let l={isValidSecretKey:i,isValidPublicKey:s,randomSecretKey:a},b=hn(a,c);return Object.freeze({getPublicKey:c,getSharedSecret:u,keygen:b,Point:e,utils:l,lengths:o})}function Wa(e,t,r={}){sn(t),ye(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let n=r.randomBytes||Xe,o=r.hmac||((y,d)=>Ui(t,y,d)),{Fp:i,Fn:s}=e,{ORDER:a,BITS:c}=s,{keygen:f,getPublicKey:u,getSharedSecret:l,utils:b,lengths:v}=wd(e,r),x={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},I=a*Ya<i.ORDER;function T(y){let d=a>>or;return y>d}function w(y,d){if(!s.isValidNot0(d))throw new Error(`invalid signature ${y}: out of range 1..Point.Fn.ORDER`);return d}function C(){if(I)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function S(y,d){Li(d);let E=v.signature,U=d==="compact"?E:d==="recovered"?E+1:void 0;return $(y,U)}class R{r;s;recovery;constructor(d,E,U){if(this.r=w("r",d),this.s=w("s",E),U!=null){if(C(),![0,1,2,3].includes(U))throw new Error("invalid recovery id");this.recovery=U}Object.freeze(this)}static fromBytes(d,E=x.format){S(d,E);let U;if(E==="der"){let{r:O,s:q}=Ae.toSig($(d));return new R(O,q)}E==="recovered"&&(U=d[0],E="compact",d=d.subarray(1));let L=v.signature/2,k=d.subarray(0,L),K=d.subarray(L,L*2);return new R(s.fromBytes(k),s.fromBytes(K),U)}static fromHex(d,E){return this.fromBytes(te(d),E)}assertRecovery(){let{recovery:d}=this;if(d==null)throw new Error("invalid recovery id: must be present");return d}addRecoveryBit(d){return new R(this.r,this.s,d)}recoverPublicKey(d){let{r:E,s:U}=this,L=this.assertRecovery(),k=L===2||L===3?E+a:E;if(!i.isValid(k))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let K=i.toBytes(k),O=e.fromBytes(Et(Xa((L&1)===0),K)),q=s.inv(k),Q=M($(d,void 0,"msgHash")),W=s.create(-Q*q),H=s.create(U*q),tt=e.BASE.multiplyUnsafe(W).add(O.multiplyUnsafe(H));if(tt.is0())throw new Error("invalid recovery: point at infinify");return tt.assertValidity(),tt}hasHighS(){return T(this.s)}toBytes(d=x.format){if(Li(d),d==="der")return te(Ae.hexFromSig(this));let{r:E,s:U}=this,L=s.toBytes(E),k=s.toBytes(U);return d==="recovered"?(C(),Et(Uint8Array.of(this.assertRecovery()),L,k)):Et(L,k)}toHex(d){return Qt(this.toBytes(d))}}let P=r.bits2int||function(d){if(d.length>8192)throw new Error("input is too large");let E=We(d),U=d.length*8-c;return U>0?E>>BigInt(U):E},M=r.bits2int_modN||function(d){return s.create(P(d))},V=Ir(c);function h(y){return vr("num < 2^"+c,y,ne,V),s.toBytes(y)}function p(y,d){return $(y,void 0,"message"),d?$(t(y),void 0,"prehashed message"):y}function _(y,d,E){let{lowS:U,prehash:L,extraEntropy:k}=Ri(E,x);y=p(y,L);let K=M(y),O=s.fromBytes(d);if(!s.isValidNot0(O))throw new Error("invalid private key");let q=[h(O),h(K)];if(k!=null&&k!==!1){let tt=k===!0?n(v.secretKey):k;q.push($(tt,void 0,"extraEntropy"))}let Q=Et(...q),W=K;function H(tt){let ft=P(tt);if(!s.isValidNot0(ft))return;let Ft=s.inv(ft),et=e.BASE.multiply(ft).toAffine(),pt=s.create(et.x);if(pt===ne)return;let Gr=s.create(Ft*s.create(W+pt*O));if(Gr===ne)return;let es=(et.x===pt?0:2)|Number(et.y&or),rs=Gr;return U&&T(Gr)&&(rs=s.neg(Gr),es^=1),new R(pt,rs,I?void 0:es)}return{seed:Q,k2sig:H}}function D(y,d,E={}){let{seed:U,k2sig:L}=_(y,d,E);return Js(t.outputLen,s.BYTES,o)(U,L).toBytes(E.format)}function A(y,d,E,U={}){let{lowS:L,prehash:k,format:K}=Ri(U,x);if(E=$(E,void 0,"publicKey"),d=p(d,k),!Be(y)){let O=y instanceof R?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+O)}S(y,K);try{let O=R.fromBytes(y,K),q=e.fromBytes(E);if(L&&O.hasHighS())return!1;let{r:Q,s:W}=O,H=M(d),tt=s.inv(W),ft=s.create(H*tt),Ft=s.create(Q*tt),et=e.BASE.multiplyUnsafe(ft).add(q.multiplyUnsafe(Ft));return et.is0()?!1:s.create(et.x)===Q}catch{return!1}}function m(y,d,E={}){let{prehash:U}=Ri(E,x);return d=p(d,U),R.fromBytes(y,"recovered").recoverPublicKey(d).toBytes()}return Object.freeze({keygen:f,getPublicKey:u,getSharedSecret:l,utils:b,lengths:v,Point:e,sign:D,verify:A,recoverPublicKey:m,Signature:R,hash:t})}var Ki={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Ed={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Ja=BigInt(2);function Sd(e){let t=Ki.p,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=J(u,r,t)*u%t,b=J(l,r,t)*u%t,v=J(b,Ja,t)*f%t,x=J(v,o,t)*v%t,I=J(x,i,t)*x%t,T=J(I,a,t)*I%t,w=J(T,c,t)*T%t,C=J(w,a,t)*I%t,S=J(C,r,t)*u%t,R=J(S,s,t)*x%t,P=J(R,n,t)*f%t,M=J(P,Ja,t);if(!ki.eql(ki.sqr(M),e))throw new Error("Cannot find square root");return M}var ki=Qe(Ki.p,{sqrt:Sd}),Ad=Ga(Ki,{Fp:ki,endo:Ed}),ir=Wa(Ad,je);function Qa(e,t,r,n){let o=gr.digest(r instanceof Uint8Array?r:r.subarray());if(yn(o))return o.then(({digest:i})=>(n?.signal?.throwIfAborted(),ir.verify(t,i,e,{prehash:!1,format:"der"}))).catch(i=>{throw i.name==="AbortError"?i:new Cr(String(i))});try{return n?.signal?.throwIfAborted(),ir.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(i){throw new Cr(String(i))}}var An=class{type="secp256k1";raw;_key;constructor(t){this._key=ec(t),this.raw=tc(this._key)}toMultihash(){return Nt.digest(de(this))}toCID(){return j.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 Qa(this._key,r,t,n)}};function Pi(e){return new An(e)}function tc(e){return ir.Point.fromBytes(e).toBytes()}function ec(e){try{return ir.Point.fromBytes(e),e}catch(t){throw new Ve(String(t))}}function rc(e,t){let{Type:r,Data:n}=zt.decode(e),o=n??new Uint8Array;switch(r){case it.RSA:return Ci(o,t);case it.Ed25519:return ci(o);case it.secp256k1:return Pi(o);case it.ECDSA:return Po(o);default:throw new qe}}function vn(e){let{Type:t,Data:r}=zt.decode(e.digest),n=r??new Uint8Array;switch(t){case it.Ed25519:return ci(n);case it.secp256k1:return Pi(n);case it.ECDSA:return Po(n);default:throw new qe}}function de(e){return zt.encode({Type:it[e.type],Data:e.raw})}var nc=Symbol.for("nodejs.util.inspect.custom"),vd=114,kr=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()})`}[so]=!0;toString(){return this.string==null&&(this.string=G.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return j.createV1(vd,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")}[nc](){return`PeerId(${this.toString()})`}},In=class extends kr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Tn=class extends kr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Bn=class extends kr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Id=2336,Kr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Nt.digest(z(this.url))}[nc](){return`PeerId(${this.url})`}[so]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return j.createV1(Id,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=Z(t)),t.toString()===this.toString())}};var Td=114,oc=2336;function Cn(e,t){let r;if(e.charAt(0)==="1"||e.charAt(0)==="Q")r=Xt(G.decode(`z${e}`));else{if(e.startsWith("k51qzi5uqu5")||e.startsWith("kzwfwjn5ji4")||e.startsWith("k2k4r8")||e.startsWith("bafz"))return Oi(j.parse(e));if(t==null)throw new st('Please pass a multibase decoder for strings that do not start with "1" or "Q"');r=Xt(t.decode(e))}return ic(r)}function ic(e){if(Cd(e))return new In({multihash:e});if(Bd(e))try{let t=vn(e);if(t.type==="Ed25519")return new Tn({multihash:e,publicKey:t});if(t.type==="secp256k1")return new Bn({multihash:e,publicKey:t})}catch{let r=Z(e.digest);return new Kr(new URL(r))}throw new Jr("Supplied PeerID Multihash is invalid")}function Oi(e){if(e?.multihash==null||e.version==null||e.version===1&&e.code!==Td&&e.code!==oc)throw new Wr("Supplied PeerID CID is invalid");if(e.code===oc){let t=Z(e.multihash.digest);return new Kr(new URL(t))}return ic(e.multihash)}function Bd(e){return e.code===Nt.code}function Cd(e){return e.code===gr.code}X.formatters.b=e=>e==null?"undefined":G.baseEncode(e);X.formatters.t=e=>e==null?"undefined":Vt.baseEncode(e);X.formatters.m=e=>e==null?"undefined":hr.baseEncode(e);X.formatters.p=e=>e==null?"undefined":e.toString();X.formatters.c=e=>e==null?"undefined":e.toString();X.formatters.k=e=>e==null?"undefined":e.toString();X.formatters.a=e=>e==null?"undefined":e.toString();X.formatters.e=e=>e==null?"undefined":sc(e.stack)??sc(e.message)??e.toString();function _d(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 Ke(e){let t=_d(`${e}:trace`);return X.enabled(`${e}:trace`)&&X.names.map(r=>r.toString()).find(r=>r.includes(":trace"))!=null&&(t=X(`${e}:trace`)),Object.assign(X(e),{error:X(`${e}:error`),trace:t,newScope:r=>Ke(`${e}:${r}`)})}function sc(e){if(e!=null&&(e=e.trim(),e.length!==0))return e}var xu=jr(_n(),1);var Dn=class extends Error{static name="SignatureCreationError";constructor(t="Record signature creation failed"){super(t),this.name="SignatureCreationError"}},Pt=class extends Error{static name="SignatureVerificationError";constructor(t="Record signature verification failed"){super(t),this.name="SignatureVerificationError"}},Un=class extends Error{static name="RecordExpiredError";constructor(t="Record has expired"){super(t),this.name="RecordExpiredError"}},Pe=class extends Error{static name="UnsupportedValidityError";constructor(t="The validity type is unsupported"){super(t),this.name="UnsupportedValidityError"}},Rn=class extends Error{static name="RecordTooLargeError";constructor(t="The record is too large"){super(t),this.name="RecordTooLargeError"}},Pr=class extends Error{static name="InvalidValueError";constructor(t="Value must be a valid content path starting with /"){super(t),this.name="InvalidValueError"}},Ln=class extends Error{static name="InvalidRecordDataError";constructor(t="Invalid record data"){super(t),this.name="InvalidRecordDataError"}},Or=class extends Error{static name="InvalidEmbeddedPublicKeyError";constructor(t="Invalid embedded public key"){super(t),this.name="InvalidEmbeddedPublicKeyError"}};var dt;(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=()=>Rr(r)})(t=e.ValidityType||(e.ValidityType={}));let n;e.codec=()=>(n==null&&(n=Se((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=>Ee(o,e.codec()),e.decode=(o,i)=>we(o,e.codec(),i)})(dt||(dt={}));var Nn=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Dd=["string","number","bigint","symbol"],Ud=["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 ac(e){if(e===null)return"null";if(e===void 0)return"undefined";if(e===!0||e===!1)return"boolean";let t=typeof e;if(Dd.includes(t))return t;if(t==="function")return"Function";if(Array.isArray(e))return"Array";if(Rd(e))return"Buffer";let r=Ld(e);return r||"Object"}function Rd(e){return e&&e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer.call(null,e)}function Ld(e){let t=Object.prototype.toString.call(e).slice(8,-1);if(Ud.includes(t))return t}var g=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}};g.uint=new g(0,"uint",!0);g.negint=new g(1,"negint",!0);g.bytes=new g(2,"bytes",!0);g.string=new g(3,"string",!0);g.array=new g(4,"array",!1);g.map=new g(5,"map",!1);g.tag=new g(6,"tag",!1);g.float=new g(7,"float",!0);g.false=new g(7,"false",!0);g.true=new g(7,"true",!0);g.null=new g(7,"null",!0);g.undefined=new g(7,"undefined",!0);g.break=new g(7,"break",!0);var N=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 sr=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Nd=new TextDecoder,kd=new TextEncoder;function kn(e){return sr&&globalThis.Buffer.isBuffer(e)}function Fi(e){return e instanceof Uint8Array?kn(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e:Uint8Array.from(e)}var lc=sr?(e,t,r)=>r-t>64?globalThis.Buffer.from(e.subarray(t,r)).toString("utf8"):uc(e,t,r):(e,t,r)=>r-t>64?Nd.decode(e.subarray(t,r)):uc(e,t,r),dc=sr?e=>e.length>64?globalThis.Buffer.from(e):cc(e):e=>e.length>64?kd.encode(e):cc(e),Zt=e=>Uint8Array.from(e),ar=sr?(e,t,r)=>kn(e)?new Uint8Array(e.subarray(t,r)):e.slice(t,r):(e,t,r)=>e.slice(t,r),hc=sr?(e,t)=>(e=e.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),Fi(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},pc=sr?e=>globalThis.Buffer.allocUnsafe(e):e=>new Uint8Array(e);function mc(e,t){if(kn(e)&&kn(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 cc(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 uc(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 fc=4096;function Kd(e){let t=e.length;if(t<=fc)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=fc));return r}var Pd=256,Mr=class{constructor(t=Pd){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=pc(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=ar(n,0,this.cursor)}else r=hc(this.chunks,this.cursor);return t&&this.reset(),r}};var F="CBOR decode error:",Vi="CBOR encode error:",Fr=[];Fr[23]=1;Fr[24]=2;Fr[25]=3;Fr[26]=5;Fr[27]=9;function oe(e,t,r){if(e.length-t<r)throw new Error(`${F} not enough data for type`)}var ut=[24,256,65536,4294967296,BigInt("18446744073709551616")];function It(e,t,r){oe(e,t,1);let n=e[t];if(r.strict===!0&&n<ut[0])throw new Error(`${F} integer encoded in more bytes than necessary (strict decode)`);return n}function Tt(e,t,r){oe(e,t,2);let n=e[t]<<8|e[t+1];if(r.strict===!0&&n<ut[1])throw new Error(`${F} integer encoded in more bytes than necessary (strict decode)`);return n}function Bt(e,t,r){oe(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(`${F} integer encoded in more bytes than necessary (strict decode)`);return n}function Ct(e,t,r){oe(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(`${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 yc(e,t,r,n){return new N(g.uint,It(e,t+1,n),2)}function gc(e,t,r,n){return new N(g.uint,Tt(e,t+1,n),3)}function xc(e,t,r,n){return new N(g.uint,Bt(e,t+1,n),5)}function bc(e,t,r,n){return new N(g.uint,Ct(e,t+1,n),9)}function Ut(e,t){return ht(e,0,t.value)}function ht(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(`${F} encountered BigInt larger than allowable range`)}}Ut.encodedSize=function(t){return ht.encodedSize(t.value)};ht.encodedSize=function(t){return t<ut[0]?1:t<ut[1]?2:t<ut[2]?3:t<ut[3]?5:9};Ut.compareTokens=function(t,r){return t.value<r.value?-1:t.value>r.value?1:0};function wc(e,t,r,n){return new N(g.negint,-1-It(e,t+1,n),2)}function Ec(e,t,r,n){return new N(g.negint,-1-Tt(e,t+1,n),3)}function Sc(e,t,r,n){return new N(g.negint,-1-Bt(e,t+1,n),5)}var qi=BigInt(-1),Ac=BigInt(1);function vc(e,t,r,n){let o=Ct(e,t+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new N(g.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${F} integers outside of the safe integer range are not supported`);return new N(g.negint,qi-BigInt(o),9)}function Kn(e,t){let r=t.value,n=typeof r=="bigint"?r*qi-Ac:r*-1-1;ht(e,t.type.majorEncoded,n)}Kn.encodedSize=function(t){let r=t.value,n=typeof r=="bigint"?r*qi-Ac:r*-1-1;return n<ut[0]?1:n<ut[1]?2:n<ut[2]?3:n<ut[3]?5:9};Kn.compareTokens=function(t,r){return t.value<r.value?1:t.value>r.value?-1:0};function Vr(e,t,r,n){oe(e,t,r+n);let o=ar(e,t+r,t+r+n);return new N(g.bytes,o,r+n)}function Ic(e,t,r,n){return Vr(e,t,1,r)}function Tc(e,t,r,n){return Vr(e,t,2,It(e,t+1,n))}function Bc(e,t,r,n){return Vr(e,t,3,Tt(e,t+1,n))}function Cc(e,t,r,n){return Vr(e,t,5,Bt(e,t+1,n))}function _c(e,t,r,n){let o=Ct(e,t+1,n);if(typeof o=="bigint")throw new Error(`${F} 64-bit integer bytes lengths not supported`);return Vr(e,t,9,o)}function Pn(e){return e.encodedBytes===void 0&&(e.encodedBytes=e.type===g.string?dc(e.value):e.value),e.encodedBytes}function cr(e,t){let r=Pn(t);ht(e,t.type.majorEncoded,r.length),e.push(r)}cr.encodedSize=function(t){let r=Pn(t);return ht.encodedSize(r.length)+r.length};cr.compareTokens=function(t,r){return Md(Pn(t),Pn(r))};function Md(e,t){return e.length<t.length?-1:e.length>t.length?1:mc(e,t)}function qr(e,t,r,n,o){let i=r+n;oe(e,t,i);let s=new N(g.string,lc(e,t+r,t+i),i);return o.retainStringBytes===!0&&(s.byteValue=ar(e,t+r,t+i)),s}function Dc(e,t,r,n){return qr(e,t,1,r,n)}function Uc(e,t,r,n){return qr(e,t,2,It(e,t+1,n),n)}function Rc(e,t,r,n){return qr(e,t,3,Tt(e,t+1,n),n)}function Lc(e,t,r,n){return qr(e,t,5,Bt(e,t+1,n),n)}function Nc(e,t,r,n){let o=Ct(e,t+1,n);if(typeof o=="bigint")throw new Error(`${F} 64-bit integer string lengths not supported`);return qr(e,t,9,o,n)}var kc=cr;function ur(e,t,r,n){return new N(g.array,n,r)}function Kc(e,t,r,n){return ur(e,t,1,r)}function Pc(e,t,r,n){return ur(e,t,2,It(e,t+1,n))}function Oc(e,t,r,n){return ur(e,t,3,Tt(e,t+1,n))}function Mc(e,t,r,n){return ur(e,t,5,Bt(e,t+1,n))}function Fc(e,t,r,n){let o=Ct(e,t+1,n);if(typeof o=="bigint")throw new Error(`${F} 64-bit integer array lengths not supported`);return ur(e,t,9,o)}function Vc(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${F} indefinite length items not allowed`);return ur(e,t,1,1/0)}function On(e,t){ht(e,g.array.majorEncoded,t.value)}On.compareTokens=Ut.compareTokens;On.encodedSize=function(t){return ht.encodedSize(t.value)};function fr(e,t,r,n){return new N(g.map,n,r)}function qc(e,t,r,n){return fr(e,t,1,r)}function $c(e,t,r,n){return fr(e,t,2,It(e,t+1,n))}function Hc(e,t,r,n){return fr(e,t,3,Tt(e,t+1,n))}function zc(e,t,r,n){return fr(e,t,5,Bt(e,t+1,n))}function Zc(e,t,r,n){let o=Ct(e,t+1,n);if(typeof o=="bigint")throw new Error(`${F} 64-bit integer map lengths not supported`);return fr(e,t,9,o)}function Yc(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${F} indefinite length items not allowed`);return fr(e,t,1,1/0)}function Mn(e,t){ht(e,g.map.majorEncoded,t.value)}Mn.compareTokens=Ut.compareTokens;Mn.encodedSize=function(t){return ht.encodedSize(t.value)};function Gc(e,t,r,n){return new N(g.tag,r,1)}function Xc(e,t,r,n){return new N(g.tag,It(e,t+1,n),2)}function jc(e,t,r,n){return new N(g.tag,Tt(e,t+1,n),3)}function Wc(e,t,r,n){return new N(g.tag,Bt(e,t+1,n),5)}function Jc(e,t,r,n){return new N(g.tag,Ct(e,t+1,n),9)}function Fn(e,t){ht(e,g.tag.majorEncoded,t.value)}Fn.compareTokens=Ut.compareTokens;Fn.encodedSize=function(t){return ht.encodedSize(t.value)};var zd=20,Zd=21,Yd=22,Gd=23;function Qc(e,t,r,n){if(n.allowUndefined===!1)throw new Error(`${F} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new N(g.null,null,1):new N(g.undefined,void 0,1)}function tu(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${F} indefinite length items not allowed`);return new N(g.break,void 0,1)}function $i(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 N(g.float,e,t)}function eu(e,t,r,n){return $i(Hi(e,t+1),3,n)}function ru(e,t,r,n){return $i(zi(e,t+1),5,n)}function nu(e,t,r,n){return $i(au(e,t+1),9,n)}function Vn(e,t,r){let n=t.value;if(n===!1)e.push([g.float.majorEncoded|zd]);else if(n===!0)e.push([g.float.majorEncoded|Zd]);else if(n===null)e.push([g.float.majorEncoded|Yd]);else if(n===void 0)e.push([g.float.majorEncoded|Gd]);else{let o,i=!1;(!r||r.float64!==!0)&&(iu(n),o=Hi(Ot,1),n===o||Number.isNaN(n)?(Ot[0]=249,e.push(Ot.slice(0,3)),i=!0):(su(n),o=zi(Ot,1),n===o&&(Ot[0]=250,e.push(Ot.slice(0,5)),i=!0))),i||(Xd(n),o=au(Ot,1),Ot[0]=251,e.push(Ot.slice(0,9)))}}Vn.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){iu(n);let o=Hi(Ot,1);if(n===o||Number.isNaN(n))return 3;if(su(n),o=zi(Ot,1),n===o)return 5}return 9};var ou=new ArrayBuffer(9),Rt=new DataView(ou,1),Ot=new Uint8Array(ou,0);function iu(e){if(e===1/0)Rt.setUint16(0,31744,!1);else if(e===-1/0)Rt.setUint16(0,64512,!1);else if(Number.isNaN(e))Rt.setUint16(0,32256,!1);else{Rt.setFloat32(0,e);let t=Rt.getUint32(0),r=(t&2139095040)>>23,n=t&8388607;if(r===255)Rt.setUint16(0,31744,!1);else if(r===0)Rt.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?Rt.setUint16(0,0):o<-14?Rt.setUint16(0,(t&2147483648)>>16|1<<24+o,!1):Rt.setUint16(0,(t&2147483648)>>16|o+15<<10|n>>13,!1)}}}function Hi(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 su(e){Rt.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 Xd(e){Rt.setFloat64(0,e,!1)}function au(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)}Vn.compareTokens=Ut.compareTokens;function Y(e,t,r){throw new Error(`${F} encountered invalid minor (${r}) for major ${e[t]>>>5}`)}function qn(e){return()=>{throw new Error(`${F} ${e}`)}}var B=[];for(let e=0;e<=23;e++)B[e]=Y;B[24]=yc;B[25]=gc;B[26]=xc;B[27]=bc;B[28]=Y;B[29]=Y;B[30]=Y;B[31]=Y;for(let e=32;e<=55;e++)B[e]=Y;B[56]=wc;B[57]=Ec;B[58]=Sc;B[59]=vc;B[60]=Y;B[61]=Y;B[62]=Y;B[63]=Y;for(let e=64;e<=87;e++)B[e]=Ic;B[88]=Tc;B[89]=Bc;B[90]=Cc;B[91]=_c;B[92]=Y;B[93]=Y;B[94]=Y;B[95]=qn("indefinite length bytes/strings are not supported");for(let e=96;e<=119;e++)B[e]=Dc;B[120]=Uc;B[121]=Rc;B[122]=Lc;B[123]=Nc;B[124]=Y;B[125]=Y;B[126]=Y;B[127]=qn("indefinite length bytes/strings are not supported");for(let e=128;e<=151;e++)B[e]=Kc;B[152]=Pc;B[153]=Oc;B[154]=Mc;B[155]=Fc;B[156]=Y;B[157]=Y;B[158]=Y;B[159]=Vc;for(let e=160;e<=183;e++)B[e]=qc;B[184]=$c;B[185]=Hc;B[186]=zc;B[187]=Zc;B[188]=Y;B[189]=Y;B[190]=Y;B[191]=Yc;for(let e=192;e<=215;e++)B[e]=Gc;B[216]=Xc;B[217]=jc;B[218]=Wc;B[219]=Jc;B[220]=Y;B[221]=Y;B[222]=Y;B[223]=Y;for(let e=224;e<=243;e++)B[e]=qn("simple values are not supported");B[244]=Y;B[245]=Y;B[246]=Y;B[247]=Qc;B[248]=qn("simple values are not supported");B[249]=eu;B[250]=ru;B[251]=nu;B[252]=Y;B[253]=Y;B[254]=Y;B[255]=tu;var Mt=[];for(let e=0;e<24;e++)Mt[e]=new N(g.uint,e,1);for(let e=-1;e>=-24;e--)Mt[31-e]=new N(g.negint,e,1);Mt[64]=new N(g.bytes,new Uint8Array(0),1);Mt[96]=new N(g.string,"",1);Mt[128]=new N(g.array,0,1);Mt[160]=new N(g.map,0,1);Mt[244]=new N(g.false,!1,1);Mt[245]=new N(g.true,!0,1);Mt[246]=new N(g.null,null,1);function cu(e){switch(e.type){case g.false:return Zt([244]);case g.true:return Zt([245]);case g.null:return Zt([246]);case g.bytes:return e.value.length?void 0:Zt([64]);case g.string:return e.value===""?Zt([96]):void 0;case g.array:return e.value===0?Zt([128]):void 0;case g.map:return e.value===0?Zt([160]):void 0;case g.uint:return e.value<24?Zt([Number(e.value)]):void 0;case g.negint:if(e.value>=-24)return Zt([31-Number(e.value)])}}var Wd={float64:!1,mapSorter:th,quickEncodeToken:cu};function Jd(){let e=[];return e[g.uint.major]=Ut,e[g.negint.major]=Kn,e[g.bytes.major]=cr,e[g.string.major]=kc,e[g.array.major]=On,e[g.map.major]=Mn,e[g.tag.major]=Fn,e[g.float.major]=Vn,e}var uu=Jd(),Zi=new Mr,Hn=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(`${Vi} object contains circular references`);return new e(r,t)}},ve={null:new N(g.null,null),undefined:new N(g.undefined,void 0),true:new N(g.true,!0),false:new N(g.false,!1),emptyArray:new N(g.array,0),emptyMap:new N(g.map,0)},Ie={number(e,t,r,n){return!Number.isInteger(e)||!Number.isSafeInteger(e)?new N(g.float,e):e>=0?new N(g.uint,e):new N(g.negint,e)},bigint(e,t,r,n){return e>=BigInt(0)?new N(g.uint,e):new N(g.negint,e)},Uint8Array(e,t,r,n){return new N(g.bytes,e)},string(e,t,r,n){return new N(g.string,e)},boolean(e,t,r,n){return e?ve.true:ve.false},null(e,t,r,n){return ve.null},undefined(e,t,r,n){return ve.undefined},ArrayBuffer(e,t,r,n){return new N(g.bytes,new Uint8Array(e))},DataView(e,t,r,n){return new N(g.bytes,new Uint8Array(e.buffer,e.byteOffset,e.byteLength))},Array(e,t,r,n){if(!e.length)return r.addBreakTokens===!0?[ve.emptyArray,new N(g.break)]:ve.emptyArray;n=Hn.createCheck(n,e);let o=[],i=0;for(let s of e)o[i++]=$n(s,r,n);return r.addBreakTokens?[new N(g.array,e.length),o,new N(g.break)]:[new N(g.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?[ve.emptyMap,new N(g.break)]:ve.emptyMap;n=Hn.createCheck(n,e);let a=[],c=0;for(let f of i)a[c++]=[$n(f,r,n),$n(o?e.get(f):e[f],r,n)];return Qd(a,r),r.addBreakTokens?[new N(g.map,s),a,new N(g.break)]:[new N(g.map,s),a]}};Ie.Map=Ie.Object;Ie.Buffer=Ie.Uint8Array;for(let e of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))Ie[`${e}Array`]=Ie.DataView;function $n(e,t={},r){let n=ac(e),o=t&&t.typeEncoders&&t.typeEncoders[n]||Ie[n];if(typeof o=="function"){let s=o(e,n,t,r);if(s!=null)return s}let i=Ie[n];if(!i)throw new Error(`${Vi} 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=uu[o].compareTokens(r,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function fu(e,t,r,n){if(Array.isArray(t))for(let o of t)fu(e,o,r,n);else r[t.type.major](e,t,n)}function eh(e,t,r){let n=$n(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 Mr(s);if(i(a,n,r),a.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return Fi(a.chunks[0])}}return Zi.reset(),fu(Zi,n,t,r),Zi.toBytes(!0)}function Yi(e,t){return t=Object.assign({},Wd,t),eh(e,uu,t)}var rh={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},zn=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=Mt[t];if(r===void 0){let n=B[t];if(!n)throw new Error(`${F} no decoder for major type ${t>>>5} (byte 0x${t.toString(16).padStart(2,"0")})`);let o=t&31;r=n(this.data,this._pos,o,this.options)}return this._pos+=r.encodedLength,r}},$r=Symbol.for("DONE"),Zn=Symbol.for("BREAK");function nh(e,t,r){let n=[];for(let o=0;o<e.value;o++){let i=lr(t,r);if(i===Zn){if(e.value===1/0)break;throw new Error(`${F} got unexpected break to lengthed array`)}if(i===$r)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=lr(t,r);if(a===Zn){if(e.value===1/0)break;throw new Error(`${F} got unexpected break to lengthed map`)}if(a===$r)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=lr(t,r);if(c===$r)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 lr(e,t){if(e.done())return $r;let r=e.next();if(r.type===g.break)return Zn;if(r.type.terminal)return r.value;if(r.type===g.array)return nh(r,e,t);if(r.type===g.map)return oh(r,e,t);if(r.type===g.tag){if(t.tags&&typeof t.tags[r.value]=="function"){let n=lr(e,t);return t.tags[r.value](n)}throw new Error(`${F} tag not supported (${r.value})`)}throw new Error("unsupported")}function lu(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 zn(e,t),n=lr(r,t);if(n===$r)throw new Error(`${F} did not find any content to decode`);if(n===Zn)throw new Error(`${F} got unexpected break`);return[n,e.subarray(r.pos())]}function Gi(e,t){let[r,n]=lu(e,t);if(n.length>0)throw new Error(`${F} too many terminals, data makes no sense`);return r}var sh=Ke("ipns:utils"),du=z("/ipns/"),ah=114,ch=0,uh=18;function Hr(e){let t;if(e.pubKey!=null)try{t=rc(e.pubKey)}catch(r){throw sh.error(r),r}if(t!=null)return t}function hu(e,t,r){let n=z(t);return fe([e,r,n])}function Gn(e){let t=z("ipns-signature:");return fe([t,e])}function Xn(e){return"signatureV1"in e?dt.encode({value:z(e.value),signatureV1:e.signatureV1,validityType:e.validityType,validity:z(e.validity),sequence:e.sequence,ttl:e.ttl,pubKey:e.pubKey,signatureV2:e.signatureV2,data:e.data}):dt.encode({pubKey:e.pubKey,signatureV2:e.signatureV2,data:e.data})}function Yt(e){let t=dt.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 Pt("Missing data or signatureV2");let r=yu(t.data),n=fh(r.Value),o=Z(r.Validity);if(t.value!=null&&t.signatureV1!=null)return lh(t),{value:n,validityType:dt.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:dt.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 Me(e){return fe([du,e.bytes])}function pu(e){let t=Xt(e.slice(du.length));if(!Yn(t,ch)&&!Yn(t,uh))throw new Nn("Multihash in IPNS key was not identity or sha2-256");return t}function mu(e,t,r,n,o){let i;if(t===dt.ValidityType.EOL)i=0;else throw new Pe("The validity type is unsupported");return Yi({Value:e,Validity:r,ValidityType:i,Sequence:n,TTL:o})}function yu(e){let t=Gi(e);if(t.ValidityType===0)t.ValidityType=dt.ValidityType.EOL;else throw new Pe("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=Z(e).trim();if(t.startsWith("/"))return t;try{return`/ipfs/${j.decode(e).toV1().toString()}`}catch{}try{return`/ipfs/${j.parse(t).toV1().toString()}`}catch{}throw new Pr("Value must be a valid content path starting with /")}function gu(e){if(e!=null){let t=ph(e);if(t!=null)return t.code===ah?`/ipns/${t.toString(Lt)}`:`/ipfs/${t.toV1().toString()}`;if(dh(e))return`/ipns/${Lt.encode(e.bytes)}`;let r=e.toString().trim();if(r.startsWith("/")&&r.length>1)return r}throw new Pr("Value must be a valid content path starting with /")}function lh(e){if(e.data==null)throw new Ln("Record data is missing");let t=yu(e.data);if(!nt(t.Value,e.value??new Uint8Array(0)))throw new Pt('Field "value" did not match between protobuf and CBOR');if(!nt(t.Validity,e.validity??new Uint8Array(0)))throw new Pt('Field "validity" did not match between protobuf and CBOR');if(t.ValidityType!==e.validityType)throw new Pt('Field "validityType" did not match between protobuf and CBOR');if(t.Sequence!==e.sequence)throw new Pt('Field "sequence" did not match between protobuf and CBOR');if(t.TTL!==e.ttl)throw new Pt('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 Yn(e,t){return e.code===t}var mh=Ke("ipns"),bu=300*1e9,yh="/ipns/",ob=yh.length,wu={v1Compatible:!0,ttlNs:bu};async function Eu(e,t,r,n,o=wu){let i=new xu.default(Date.now()+Number(n)),s=dt.ValidityType.EOL,a=BigInt(o.ttlNs??bu);return gh(e,t,r,s,i.toString(),a,o)}var gh=async(e,t,r,n,o,i,s=wu)=>{r=BigInt(r);let a=z(o),c=gu(t),f=z(c),u=mu(f,n,a,r,i),l=Gn(u),b=await e.sign(l),v;if(e.type==="RSA"&&(v=de(e.publicKey)),s.v1Compatible===!0){let x=await xh(e,f,n,a),I={value:c,signatureV1:x,validity:o,validityType:n,sequence:r,ttl:i,signatureV2:b,data:u};return v!=null&&(I.pubKey=v),I}else{let x={value:c,validity:o,validityType:n,sequence:r,ttl:i,signatureV2:b,data:u};return v!=null&&(x.pubKey=v),x}},xh=async(e,t,r,n)=>{try{let o=hu(t,r,n);return await e.sign(o)}catch(o){throw mh.error("record signature creation failed",o),new Dn("Record signature creation failed")}};var Xi=jr(_n(),1);function jn(e,t){let r=t.map((n,o)=>({record:Yt(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===dt.ValidityType.EOL&&o.record.validityType===dt.ValidityType.EOL){let a=Xi.default.fromString(n.record.validity).toDate(),c=Xi.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 Su=jr(_n(),1);var Wn=Ke("ipns:validator"),bh=1024*10;async function wh(e,t){let r=Yt(t),n;try{let o=Gn(r.data);n=await e.verify(o,r.signatureV2)}catch{n=!1}if(!n)throw Wn.error("record signature verification failed"),new Pt("Record signature verification failed");if(r.validityType===dt.ValidityType.EOL){if(Su.default.fromString(r.validity).toDate().getTime()<Date.now())throw Wn.error("record has expired"),new Un("record has expired")}else if(r.validityType!=null)throw Wn.error("the validity type is unsupported"),new Pe("The validity type is unsupported");Wn("ipns record for %s is valid",r.value)}async function zr(e,t){if(t.byteLength>bh)throw new Rn("The record is too large");let r=pu(e),n;Yn(r,0)&&(n=vn(r));let o=Yt(t),i=Hr(o)??n;if(i==null)throw new Or("Could not extract public key from IPNS record or routing key");let s=Me(i.toMultihash());if(!nt(s,e))throw new Or("Embedded public key did not match routing key");await wh(i,t)}var yt=class extends Event{type;detail;constructor(t,r){super(t),this.type=t,this.detail=r}};var Ah=jr(vu(),1);var ie;(function(e){e[e.A=1]="A",e[e.CNAME=5]="CNAME",e[e.TXT=16]="TXT",e[e.AAAA=28]="AAAA"})(ie||(ie={}));var Jn=class extends Error{static name="DNSLinkNotFoundError";constructor(t="DNSLink not found"){super(t),this.name="DNSLinkNotFoundError"}},Qn=class extends Error{static name="RecordsFailedValidationError";constructor(t="Records failed validation"){super(t),this.name="RecordsFailedValidationError"}},to=class extends Error{static name="UnsupportedMultibasePrefixError";constructor(t="Unsupported multibase prefix"){super(t),this.name="UnsupportedMultibasePrefixError"}},eo=class extends Error{static name="UnsupportedMultihashCodecError";constructor(t="Unsupported multihash codec"){super(t),this.name="UnsupportedMultihashCodecError"}},ro=class extends Error{static name="InvalidValueError";constructor(t="Invalid value"){super(t),this.name="InvalidValueError"}};var vh=32;async function Iu(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:[ie.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,b,...v]=u.split("/");if(l==="ipfs")try{return{value:`/ipfs/${j.parse(b)}${v.length>0?`/${v.join("/")}`:""}`,answer:f}}catch{}else if(l==="ipns"){try{let x;return b.charAt(0)==="1"||b.charAt(0)==="Q"?x=Cn(b):x=Oi(j.parse(b)),{value:`/ipns/${x}${v.length>0?`/${v.join("/")}`:""}`,answer:f}}catch{}return await no(b,t-1,r,n,o)}else{if(l==="dnslink")return await no(b,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:[ie.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 no(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 Jn(`No DNSLink records found for domain: ${e}`)}async function no(e,t,r,n,o={}){if(t===0)throw new Error("recursion limit exceeded");e.startsWith("_dnslink.")||(e=`_dnslink.${e}`);try{return await Iu(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}`,Iu(e,t,r,n,o)}}async function Tu(e,t,r,n={}){return no(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 yt("ipns:routing:helia:error",o)),o}}async get(t,r={}){try{return await this.routing.get(t,r)}catch(n){throw r.onProgress?.(new yt("ipns:routing:helia:error",n)),n}}};function Bu(e){return new ji(e)}var Zr;(function(e){let t;e.codec=()=>(t==null&&(t=Se((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:_t(0),value:_t(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=>Ee(r,e.codec()),e.decode=(r,n)=>we(r,e.codec(),n)})(Zr||(Zr={}));function Cu(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 _u(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 Fe=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 Zr.encode(this.prepareSerialize())}prepareSerialize(){return{key:this.key,value:this.value,timeReceived:Cu(this.timeReceived)}}static deserialize(t){let r=Zr.decode(t);return new e(r.key,r.value,new Date(r.timeReceived))}static fromDeserialized(t){let r=_u(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 se="/",Du=new TextEncoder().encode(se),oo=Du[0],Yr=class e{_buf;constructor(t,r){if(typeof t=="string")this._buf=z(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]!==oo)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(se))}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=Du),this._buf[0]!==oo){let t=new Uint8Array(this._buf.byteLength+1);t.fill(oo,0,1),t.set(this._buf,1),this._buf=t}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===oo;)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(se).slice(1)}type(){return Th(this.baseNamespace())}name(){return Bh(this.baseNamespace())}instance(t){return new e(this.toString()+":"+t)}path(){let t=this.parent().toString();return t.endsWith(se)||(t+=se),t+=this.type(),new e(t)}parent(){let t=this.list();return t.length===1?new e(se):new e(t.slice(0,-1).join(se))}child(t){return this.toString()===se?t:t.toString()===se?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(),...Ch(t.map(r=>r.namespaces()))])}};function Th(e){let t=e.split(":");return t.length<2?"":t.slice(0,-1).join(":")}function Bh(e){let t=e.split(":");return t[t.length-1]}function Ch(e){return[].concat(...e)}var Uu;(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"})(Uu||(Uu={}));function io(e){return new Yr("/dht/record/"+Z(e,"base32"),!1)}function Ru(e){return{async put(t,r,n={}){try{let o=io(t);try{let s=await e.get(o),a=Fe.deserialize(s);if(nt(a.value,r))return}catch(s){if(s.name!=="NotFoundError")throw s}let i=new Fe(t,r,new Date);n.onProgress?.(new yt("ipns:routing:datastore:put")),await e.put(o,i.serialize(),n)}catch(o){throw n.onProgress?.(new yt("ipns:routing:datastore:error",o)),o}},async get(t,r={}){try{let n=io(t);r.onProgress?.(new yt("ipns:routing:datastore:get"));let o=await e.get(n,r),i=Fe.deserialize(o);return{record:i.value,created:i.timeReceived}}catch(n){throw r.onProgress?.(new yt("ipns:routing:datastore:error",n)),n}},async has(t,r={}){let n=io(t);return e.has(n,r)},async delete(t,r){let n=io(t);return e.delete(n,r)}}}var Wi="/ipns/";function Ji(e,t){return e.code===t}var ae=yo("helia:ipns"),ku=60*1e3,Ku=60*ku,Uh=48*Ku,Qi=23*Ku,Lu=BigInt(ku)*5000000n,Nu={[Lt.prefix]:Lt,[G.prefix]:G},ts=class{routers;localStore;timeout;dns;log;constructor(t,r=[]){this.routers=[Bu(t.routing),...r],this.localStore=Ru(t.datastore),this.dns=t.dns,this.log=t.logger.forComponent("helia:ipns")}async publish(t,r,n={}){try{let o=1n,i=Me(t.publicKey.toMultihash());if(await this.localStore.has(i,n)){let{record:f}=await this.localStore.get(i,n);o=Yt(f).sequence+1n}let s=n.ttl!=null?BigInt(n.ttl)*1000000n:Lu,a=await Eu(t,r,o,n.lifetime??Uh,{...n,ttlNs:s}),c=Xn(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 yt("ipns:publish:error",o)),o}}async resolve(t,r={}){let n=is(t)?t.toMultihash():t,o=Me(n),i=await this.#e(o,r);return{...await this.#t(i.value,r),record:i}}async resolveDNSLink(t,r={}){let n=await Tu(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 yt("ipns:republish:start"));let i=Date.now()-n,s=Qi-i;s<0&&(s=t.interval??Qi),setTimeout(()=>{r().catch(a=>{ae.error("error republishing",a)})},s)}this.timeout=setTimeout(()=>{r().catch(n=>{ae.error("error republishing",n)})},t.interval??Qi)}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(Nu[s]!=null)a=Nu[s].decode(i);else throw new to(`Unsupported multibase prefix "${s}"`);let c;try{c=Xt(a)}catch{c=j.decode(a).multihash}if(!Ji(c,0)&&!Ji(c,18))throw new eo(`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){ae.error("error parsing ipfs path",o)}throw ae.error("invalid ipfs path %s",t),new ro("Invalid value")}async#e(t,r={}){let n=[];if(await this.localStore.has(t,r))if(ae("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 zr(t,a),this.log("record was valid");let f=Yt(a),u=Number((f.ttl??Lu)/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 ae("ignoring local cache due to nocache=true option");if(r.offline===!0)throw new dr("Record was not present in the cache or has expired");ae("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){ae.error("error finding IPNS record",f);return}try{await zr(t,c),n.push(c)}catch(f){i++,ae.error("error finding IPNS record",f)}})),n.length===0)throw i>0?new Qn(`${i>1?`${i} records`:"Record"} found for routing key ${i>1?"were":"was"} invalid`):new dr("Could not find record for routing key");let s=n[jn(t,n)];return await this.localStore.put(t,s,r),Yt(s)}async republishRecord(t,r,n={}){let o;try{if(o=Hr(r)?.toMultihash(),o==null)if(typeof t=="string"){t.startsWith(Wi)&&(t=t.slice(Wi.length));try{o=Cn(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=Me(o),s=Xn(r);await zr(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 yt("ipns:republish:error",{key:o,record:r,err:i})),i}}};function Rh(e,{routers:t=[]}={}){return new ts(e,t)}return qu(Lh);})();
4
5
  /*! Bundled license information:
5
6
 
6
- @noble/hashes/esm/utils.js:
7
+ @noble/hashes/utils.js:
7
8
  (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
8
9
 
9
- @noble/curves/esm/utils.js:
10
- @noble/curves/esm/abstract/modular.js:
11
- @noble/curves/esm/abstract/curve.js:
12
- @noble/curves/esm/abstract/edwards.js:
13
- @noble/curves/esm/ed25519.js:
14
- @noble/curves/esm/abstract/weierstrass.js:
15
- @noble/curves/esm/_shortw_utils.js:
16
- @noble/curves/esm/secp256k1.js:
10
+ @noble/curves/utils.js:
11
+ @noble/curves/abstract/modular.js:
12
+ @noble/curves/abstract/curve.js:
13
+ @noble/curves/abstract/edwards.js:
14
+ @noble/curves/ed25519.js:
15
+ @noble/curves/abstract/weierstrass.js:
16
+ @noble/curves/secp256k1.js:
17
17
  (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
18
18
  */
19
19
  return HeliaIpns}));