@helia/ipns 8.1.0-70b8fa9 → 8.1.0-73cb631

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,6 +1,6 @@
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 hu=Object.create;var Vr=Object.defineProperty;var pu=Object.getOwnPropertyDescriptor;var mu=Object.getOwnPropertyNames;var gu=Object.getPrototypeOf,yu=Object.prototype.hasOwnProperty;var Ki=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),xt=(e,t)=>{for(var r in t)Vr(e,r,{get:t[r],enumerable:!0})},Vi=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of mu(t))!yu.call(e,o)&&o!==r&&Vr(e,o,{get:()=>t[o],enumerable:!(n=pu(t,o))||n.enumerable});return e};var qr=(e,t,r)=>(r=e!=null?hu(gu(e)):{},Vi(t||!e||!e.__esModule?Vr(r,"default",{value:e,enumerable:!0}):r,e)),xu=e=>Vi(Vr({},"__esModule",{value:!0}),e);var En=Ki((ey,yi)=>{var ty=function(){typeof yi<"u"&&(yi.exports=y);var e=86400,t=3200,r=146097*t/400,n=e*r,o=1e3*n,i=864e13,s=4294967296,a=1e6,u="000000000",f=Math.trunc||function(w){var b=w-w%1;return b==0&&(w<0||w===0&&1/w!=1/0)?-0:b},c=y.prototype,l=(y.fromDate=function(w){return new y(+w)},y.fromInt64BE=_(0,1,2,3,0,4),y.fromInt64LE=_(3,2,1,0,4,0),y.fromString=function(L){var b,F=new y,L=(L+="").replace(/^\s*[+\-]?\d+/,function(V){var V=+V,v=1970+(V-1970)%400;return F.year=V-v,v}).replace(/(?:Z|([+\-]\d{2}):?(\d{2}))$/,function(U,V,v){return V<0&&(v*=-1),b=6e4*(60*+V+ +v),""}).replace(/\.\d+$/,function(U){return F.nano=+(U+u).substr(1,9),""}).split(/\D+/);if(1<L.length?L[1]--:L[1]=0,F.time=b=Date.UTC.apply(Date,L)-(b||0),isNaN(b))throw new TypeError("Invalid Date");return h(F)},y.fromTimeT=function(w){return C(w,0)},c.year=0,c.time=0,c.nano=0,c.addNano=function(w){return this.nano+=+w||0,this},c.getNano=function(){var w=h(this);return(w.time%1e3*a+ +w.nano+1e9)%1e9},c.getTimeT=function(){var b=h(this),w=Math.floor(b.time/1e3),b=b.year;return b&&(w+=b*r*e/t),w},c.getYear=function(){return this.toDate().getUTCFullYear()+this.year},c.toDate=function(){return S(h(this).time)},c.toJSON=function(){return this.toString().replace(/0{1,6}Z$/,"Z")},c.toString=function(w){var b=this,F=b.toDate(),L={H:function(){return k(F.getUTCHours())},L:function(){return N(F.getUTCMilliseconds(),3)},M:function(){return k(F.getUTCMinutes())},N:function(){return N(b.getNano(),9)},S:function(){return k(F.getUTCSeconds())},Y:function(){var U=b.getYear();return 999999<U?"+"+U:9999<U?"+"+N(U,6):0<=U?N(U,4):-999999<=U?"-"+N(-U,6):U},a:function(){return T[F.getUTCDay()]},b:function(){return d[F.getUTCMonth()]},d:function(){return k(F.getUTCDate())},e:function(){return function(U){return(9<U?"":" ")+(0|U)}(F.getUTCDate())},m:function(){return k(F.getUTCMonth()+1)}};return function U(V){return V.replace(/%./g,function(v){var g=v[1],B=A[g],g=L[g];return B?U(B):g?g():v})}(w||l)},c.writeInt64BE=x(0,1,2,3,0,4),c.writeInt64LE=x(3,2,1,0,4,0),"%Y-%m-%dT%H:%M:%S.%NZ"),d=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],T=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],A={"%":"%",F:"%Y-%m-%d",n:`
3
- `,R:"%H:%M",T:"%H:%M:%S",t:" ",X:"%T",Z:"GMT",z:"+0000"};return y;function y(w,b,F){var L=this;if(!(L instanceof y))return new y(w,b,F);L.time=+w||0,L.nano=+b||0,L.year=+F||0,h(L)}function h(w){var b,F,L,U=w.year,V=w.time,v=w.nano,B=((v<0||a<=v)&&(v-=(F=Math.floor(v/a))*a,V+=F,F=1),U%t);return(V<-i||i<V||B)&&((b=f(V/o))&&(U+=b*t,V-=b*o),(L=S(V)).setUTCFullYear(B+L.getUTCFullYear()),L=(V=+L)+(b=f((U-=B)/t))*o,b&&-i<=L&&L<=i&&(U-=b*t,V=L),F=1),F&&(w.year=U,w.time=V,w.nano=v),w}function S(w){var b=new Date(0);return b.setTime(w),b}function C(U,L){U=+U||0;var F=f((L=(L|0)*s)/n)+f(U/n),L=L%n+U%n,U=f(L/n);return U&&(F+=U,L-=U*n),new y(1e3*L,0,F*t)}function x(w,b,F,L,U,V){return function(B,g){var E=h(this);B=B||new Array(8),P(B,g|=0);var R=Math.floor(E.time/1e3),E=E.year*(r*e/t),p=f(E/s)+f(R/s),E=E%s+R%s,R=Math.floor(E/s);return R&&(p+=R,E-=R*s),v(B,g+U,p),v(B,g+V,E),B};function v(B,g,p){B[g+w]=p>>24&255,B[g+b]=p>>16&255,B[g+F]=p>>8&255,B[g+L]=255&p}}function _(w,b,F,L,U,V){return function(B,g){P(B,g|=0);var p=v(B,g+U);return C(v(B,g+V),p)};function v(B,g){return 16777216*B[g+w]+(B[g+b]<<16|B[g+F]<<8|B[g+L])}}function P(w,b){if(w=w&&w.length,w==null)throw new TypeError("Invalid Buffer");if(w<b+8)throw new RangeError("Out of range")}function k(w){return(9<w?"":"0")+(0|w)}function N(w,b){return(u+(0|w)).substr(-b)}}()});var Gc=Ki((hw,Zc)=>{Zc.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 Ih={};xt(Ih,{ipns:()=>Th,ipnsSelector:()=>Kn,ipnsValidator:()=>qn});function qi(e){return e==null?!1:(e.type==="RSA"||e.type==="Ed25519"||e.type==="secp256k1")&&e.raw instanceof Uint8Array&&typeof e.equals=="function"&&typeof e.toMultihash=="function"&&typeof e.toCID=="function"&&typeof e.verify=="function"}var to=Symbol.for("@libp2p/peer-id");var mt=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},He=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var hr=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}};var Hr=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},ze=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var $e=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var io={};xt(io,{base32:()=>le,base32hex:()=>Iu,base32hexpad:()=>Uu,base32hexpadupper:()=>Ru,base32hexupper:()=>Cu,base32pad:()=>Bu,base32padupper:()=>Tu,base32upper:()=>vu,base32z:()=>_u});var Nh=new Uint8Array(0);function Hi(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 jt(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 zi(e){return new TextEncoder().encode(e)}function $i(e){return new TextDecoder().decode(e)}function wu(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),f=Math.log(a)/Math.log(256),c=Math.log(256)/Math.log(a);function l(A){if(A instanceof Uint8Array||(ArrayBuffer.isView(A)?A=new Uint8Array(A.buffer,A.byteOffset,A.byteLength):Array.isArray(A)&&(A=Uint8Array.from(A))),!(A instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(A.length===0)return"";for(var y=0,h=0,S=0,C=A.length;S!==C&&A[S]===0;)S++,y++;for(var x=(C-S)*c+1>>>0,_=new Uint8Array(x);S!==C;){for(var P=A[S],k=0,N=x-1;(P!==0||k<h)&&N!==-1;N--,k++)P+=256*_[N]>>>0,_[N]=P%a>>>0,P=P/a>>>0;if(P!==0)throw new Error("Non-zero carry");h=k,S++}for(var w=x-h;w!==x&&_[w]===0;)w++;for(var b=u.repeat(y);w<x;++w)b+=e.charAt(_[w]);return b}function d(A){if(typeof A!="string")throw new TypeError("Expected String");if(A.length===0)return new Uint8Array;var y=0;if(A[y]!==" "){for(var h=0,S=0;A[y]===u;)h++,y++;for(var C=(A.length-y)*f+1>>>0,x=new Uint8Array(C);A[y];){var _=r[A.charCodeAt(y)];if(_===255)return;for(var P=0,k=C-1;(_!==0||P<S)&&k!==-1;k--,P++)_+=a*x[k]>>>0,x[k]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");S=P,y++}if(A[y]!==" "){for(var N=C-S;N!==C&&x[N]===0;)N++;for(var w=new Uint8Array(h+(C-N)),b=h;N!==C;)w[b++]=x[N++];return w}}}function T(A){var y=d(A);if(y)return y;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:d,decode:T}}var bu=wu,Eu=bu,Gi=Eu;var eo=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")}},ro=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 Yi(this,t)}},no=class{decoders;constructor(t){this.decoders=t}or(t){return Yi(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 Yi(e,t){return new no({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var oo=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 eo(t,r,n),this.decoder=new ro(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Ze({name:e,prefix:t,encode:r,decode:n}){return new oo(e,t,r,n)}function fe({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Gi(r,e);return Ze({prefix:t,name:e,encode:n,decode:i=>jt(o(i))})}function Su(e,t,r,n){let o={};for(let c=0;c<t.length;++c)o[t[c]]=c;let i=e.length;for(;e[i-1]==="=";)--i;let s=new Uint8Array(i*r/8|0),a=0,u=0,f=0;for(let c=0;c<i;++c){let l=o[e[c]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);u=u<<r|l,a+=r,a>=8&&(a-=8,s[f++]=255&u>>a)}if(a>=r||(255&u<<8-a)!==0)throw new SyntaxError("Unexpected end of data");return s}function Au(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 nt({name:e,prefix:t,bitsPerChar:r,alphabet:n}){return Ze({prefix:t,name:e,encode(o){return Au(o,n,r)},decode(o){return Su(o,n,r,e)}})}var le=nt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),vu=nt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Bu=nt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Tu=nt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Iu=nt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Cu=nt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Uu=nt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Ru=nt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),_u=nt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var so={};xt(so,{base58btc:()=>j,base58flickr:()=>Nu});var j=fe({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Nu=fe({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var co={};xt(co,{base64:()=>ao,base64pad:()=>Lu,base64url:()=>Du,base64urlpad:()=>ku});var ao=nt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Lu=nt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Du=nt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),ku=nt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});function Pu(e,t){try{if(typeof e=="string"&&e.length>0)return Fu(e);if(typeof e=="number"&&isFinite(e))return t?.long?Mu(e):Ou(e);throw new Error("Value is not a string or number.")}catch(r){let n=Ku(r)?`${r.message}. value=${JSON.stringify(e)}`:"An unknown error has occured.";throw new Error(n)}}function Fu(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 $r=Pu;function Ou(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 Mu(e){let t=Math.abs(e);return t>=864e5?zr(e,t,864e5,"day"):t>=36e5?zr(e,t,36e5,"hour"):t>=6e4?zr(e,t,6e4,"minute"):t>=1e3?zr(e,t,1e3,"second"):`${e} ms`}function zr(e,t,r,n){let o=t>=r*1.5;return`${Math.round(e/r)} ${n}${o?"s":""}`}function Ku(e){return typeof e=="object"&&e!==null&&"message"in e}function uo(e){r.debug=r,r.default=r,r.coerce=u,r.disable=i,r.enable=o,r.enabled=s,r.humanize=$r,r.destroy=f,Object.keys(e).forEach(c=>{r[c]=e[c]}),r.names=[],r.skips=[],r.formatters={};function t(c){let l=0;for(let d=0;d<c.length;d++)l=(l<<5)-l+c.charCodeAt(d),l|=0;return r.colors[Math.abs(l)%r.colors.length]}r.selectColor=t;function r(c){let l,d=null,T,A;function y(...h){if(!y.enabled)return;let S=y,C=Number(new Date),x=C-(l||C);S.diff=x,S.prev=l,S.curr=C,l=C,h[0]=r.coerce(h[0]),typeof h[0]!="string"&&h.unshift("%O");let _=0;h[0]=h[0].replace(/%([a-zA-Z%])/g,(k,N)=>{if(k==="%%")return"%";_++;let w=r.formatters[N];if(typeof w=="function"){let b=h[_];k=w.call(S,b),h.splice(_,1),_--}return k}),r.formatArgs.call(S,h),(S.log||r.log).apply(S,h)}return y.namespace=c,y.useColors=r.useColors(),y.color=r.selectColor(c),y.extend=n,y.destroy=r.destroy,Object.defineProperty(y,"enabled",{enumerable:!0,configurable:!1,get:()=>d!==null?d:(T!==r.namespaces&&(T=r.namespaces,A=r.enabled(c)),A),set:h=>{d=h}}),typeof r.init=="function"&&r.init(y),y}function n(c,l){let d=r(this.namespace+(typeof l>"u"?":":l)+c);return d.log=this.log,d}function o(c){r.save(c),r.namespaces=c,r.names=[],r.skips=[];let l,d=(typeof c=="string"?c:"").split(/[\s,]+/),T=d.length;for(l=0;l<T;l++)d[l]&&(c=d[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,d;for(l=0,d=r.skips.length;l<d;l++)if(r.skips[l].test(c))return!1;for(l=0,d=r.names.length;l<d;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 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 Zr=Gu(),Vu=["#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 qu(){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 Hu(e){if(e[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+e[0]+(this.useColors?"%c ":" ")+"+"+$r(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 zu=console.debug??console.log??(()=>{});function $u(e){try{e?Zr?.setItem("debug",e):Zr?.removeItem("debug")}catch{}}function Zu(){let e;try{e=Zr?.getItem("debug")}catch{}return!e&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(e=globalThis.process.env.DEBUG),e}function Gu(){try{return localStorage}catch{}}function Yu(e){e.j=function(t){try{return JSON.stringify(t)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var Wi=uo({formatArgs:Hu,save:$u,load:Zu,useColors:qu,setupFormatters:Yu,colors:Vu,storage:Zr,log:zu});var St=Wi;St.formatters.b=e=>e==null?"undefined":j.baseEncode(e);St.formatters.t=e=>e==null?"undefined":le.baseEncode(e);St.formatters.m=e=>e==null?"undefined":ao.baseEncode(e);St.formatters.p=e=>e==null?"undefined":e.toString();St.formatters.c=e=>e==null?"undefined":e.toString();St.formatters.k=e=>e==null?"undefined":e.toString();St.formatters.a=e=>e==null?"undefined":e.toString();St.formatters.e=e=>e==null?"undefined":Xi(e.stack)??Xi(e.message)??e.toString();function Wu(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 de(e){let t=Wu(`${e}:trace`);return St.enabled(`${e}:trace`)&&St.names.map(r=>r.toString()).find(r=>r.includes(":trace"))!=null&&(t=St(`${e}:trace`)),Object.assign(St(e),{error:St(`${e}:error`),trace:t})}function Xi(e){if(e!=null&&(e=e.trim(),e.length!==0))return e}var fo={};xt(fo,{base36:()=>kt,base36upper:()=>Xu});var kt=fe({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Xu=fe({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ju=Qi,ji=128,Ju=127,Qu=~Ju,tf=Math.pow(2,31);function Qi(e,t,r){t=t||[],r=r||0;for(var n=r;e>=tf;)t[r++]=e&255|ji,e/=128;for(;e&Qu;)t[r++]=e&255|ji,e>>>=7;return t[r]=e|0,Qi.bytes=r-n+1,t}var ef=lo,rf=128,Ji=127;function lo(e,n){var r=0,n=n||0,o=0,i=n,s,a=e.length;do{if(i>=a)throw lo.bytes=0,new RangeError("Could not decode varint");s=e[i++],r+=o<28?(s&Ji)<<o:(s&Ji)*Math.pow(2,o),o+=7}while(s>=rf);return lo.bytes=i-n,r}var nf=Math.pow(2,7),of=Math.pow(2,14),sf=Math.pow(2,21),af=Math.pow(2,28),cf=Math.pow(2,35),uf=Math.pow(2,42),ff=Math.pow(2,49),lf=Math.pow(2,56),df=Math.pow(2,63),hf=function(e){return e<nf?1:e<of?2:e<sf?3:e<af?4:e<cf?5:e<uf?6:e<ff?7:e<lf?8:e<df?9:10},pf={encode:ju,decode:ef,encodingLength:hf},mf=pf,pr=mf;function mr(e,t=0){return[pr.decode(e,t),pr.decode.bytes]}function Ge(e,t,r=0){return pr.encode(e,t,r),t}function Ye(e){return pr.encodingLength(e)}function Pt(e,t){let r=t.byteLength,n=Ye(e),o=n+Ye(r),i=new Uint8Array(o+r);return Ge(e,i,0),Ge(r,i,n),i.set(t,o),new We(e,r,t,i)}function Jt(e){let t=jt(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 We(r,o,s,t)}function ts(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Hi(e.bytes,r.bytes)}}var We=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function es(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return yf(r,ho(e),t??j.encoder);default:return xf(r,ho(e),t??le.encoder)}}var rs=new WeakMap;function ho(e){let t=rs.get(e);if(t==null){let r=new Map;return rs.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!==gr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==wf)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=Pt(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&&ts(t.multihash,n.multihash)}toString(t){return es(this,t)}toJSON(){return{"/":es(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??ns(n,o,i.bytes))}else if(r[bf]===!0){let{version:n,multihash:o,code:i}=r,s=Jt(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!==gr)throw new Error(`Version 0 CID must use dag-pb (code: ${gr}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=ns(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,gr,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=jt(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 We(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,d]=mr(t.subarray(r));return r+=d,l},o=n(),i=gr;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(),f=r+u,c=f-s;return{version:o,codec:i,multihashCode:a,digestSize:u,multihashSize:c,size:f}}static parse(t,r){let[n,o]=gf(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 ho(i).set(n,t),i}};function gf(e,t){switch(e[0]){case"Q":{let r=t??j;return[j.prefix,r.decode(`${j.prefix}${e}`)]}case j.prefix:{let r=t??j;return[j.prefix,r.decode(e)]}case le.prefix:{let r=t??le;return[le.prefix,r.decode(e)]}case kt.prefix:{let r=t??kt;return[kt.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 yf(e,t,r){let{prefix:n}=r;if(n!==j.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 xf(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 gr=112,wf=18;function ns(e,t,r){let n=Ye(e),o=n+Ye(t),i=new Uint8Array(o+r.byteLength);return Ge(e,i,0),Ge(t,i,n),i.set(r,o),i}var bf=Symbol.for("@ipld/js-cid/CID");var po={};xt(po,{identity:()=>Qt});var os=0,Ef="identity",is=jt;function Sf(e){return Pt(os,is(e))}var Qt={code:os,name:Ef,encode:is,digest:Sf};function ot(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function ss(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function Af(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Xe(e,...t){if(!Af(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 as(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");ss(e.outputLen),ss(e.blockLen)}function je(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 cs(e,t){Xe(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}var _e=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Yr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Ft(e,t){return e<<32-t|e>>>t}function us(e){if(typeof e!="string")throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array(new TextEncoder().encode(e))}function yr(e){return typeof e=="string"&&(e=us(e)),Xe(e),e}function mo(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];Xe(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 Je=class{clone(){return this._cloneInto()}};function Wr(e){let t=n=>e().update(yr(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function Xr(e=32){if(_e&&typeof _e.getRandomValues=="function")return _e.getRandomValues(new Uint8Array(e));if(_e&&typeof _e.randomBytes=="function")return _e.randomBytes(e);throw new Error("crypto.getRandomValues must be defined")}function vf(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,f=n?0:4;e.setUint32(t+u,s,n),e.setUint32(t+f,a,n)}function fs(e,t,r){return e&t^~e&r}function ls(e,t,r){return e&t^e&r^t&r}var Qe=class extends Je{constructor(t,r,n,o){super(),this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=Yr(this.buffer)}update(t){je(this);let{view:r,buffer:n,blockLen:o}=this;t=yr(t);let i=t.length;for(let s=0;s<i;){let a=Math.min(o-this.pos,i-s);if(a===o){let u=Yr(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){je(this),cs(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;r[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>o-s&&(this.process(n,0),s=0);for(let l=s;l<o;l++)r[l]=0;vf(n,o-8,BigInt(this.length*8),i),this.process(n,0);let a=Yr(t),u=this.outputLen;if(u%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=u/4,c=this.get();if(f>c.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<f;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.length=o,t.pos=a,t.finished=i,t.destroyed=s,o%r&&t.buffer.set(n),t}};var jr=BigInt(4294967295),go=BigInt(32);function ds(e,t=!1){return t?{h:Number(e&jr),l:Number(e>>go&jr)}:{h:Number(e>>go&jr)|0,l:Number(e&jr)|0}}function Bf(e,t=!1){let r=new Uint32Array(e.length),n=new Uint32Array(e.length);for(let o=0;o<e.length;o++){let{h:i,l:s}=ds(e[o],t);[r[o],n[o]]=[i,s]}return[r,n]}var Tf=(e,t)=>BigInt(e>>>0)<<go|BigInt(t>>>0),If=(e,t,r)=>e>>>r,Cf=(e,t,r)=>e<<32-r|t>>>r,Uf=(e,t,r)=>e>>>r|t<<32-r,Rf=(e,t,r)=>e<<32-r|t>>>r,_f=(e,t,r)=>e<<64-r|t>>>r-32,Nf=(e,t,r)=>e>>>r-32|t<<64-r,Lf=(e,t)=>t,Df=(e,t)=>e,kf=(e,t,r)=>e<<r|t>>>32-r,Pf=(e,t,r)=>t<<r|e>>>32-r,Ff=(e,t,r)=>t<<r-32|e>>>64-r,Of=(e,t,r)=>e<<r-32|t>>>64-r;function Mf(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var Kf=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Vf=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,qf=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),Hf=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,zf=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),$f=(e,t,r,n,o,i)=>t+r+n+o+i+(e/2**32|0)|0;var Zf={fromBig:ds,split:Bf,toBig:Tf,shrSH:If,shrSL:Cf,rotrSH:Uf,rotrSL:Rf,rotrBH:_f,rotrBL:Nf,rotr32H:Lf,rotr32L:Df,rotlSH:kf,rotlSL:Pf,rotlBH:Ff,rotlBL:Of,add:Mf,add3L:Kf,add3H:Vf,add4L:qf,add4H:Hf,add5H:$f,add5L:zf},H=Zf;var[Gf,Yf]=H.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))),pe=new Uint32Array(80),me=new Uint32Array(80),yo=class extends Qe{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:i,Cl:s,Dh:a,Dl:u,Eh:f,El:c,Fh:l,Fl:d,Gh:T,Gl:A,Hh:y,Hl:h}=this;return[t,r,n,o,i,s,a,u,f,c,l,d,T,A,y,h]}set(t,r,n,o,i,s,a,u,f,c,l,d,T,A,y,h){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=f|0,this.El=c|0,this.Fh=l|0,this.Fl=d|0,this.Gh=T|0,this.Gl=A|0,this.Hh=y|0,this.Hl=h|0}process(t,r){for(let x=0;x<16;x++,r+=4)pe[x]=t.getUint32(r),me[x]=t.getUint32(r+=4);for(let x=16;x<80;x++){let _=pe[x-15]|0,P=me[x-15]|0,k=H.rotrSH(_,P,1)^H.rotrSH(_,P,8)^H.shrSH(_,P,7),N=H.rotrSL(_,P,1)^H.rotrSL(_,P,8)^H.shrSL(_,P,7),w=pe[x-2]|0,b=me[x-2]|0,F=H.rotrSH(w,b,19)^H.rotrBH(w,b,61)^H.shrSH(w,b,6),L=H.rotrSL(w,b,19)^H.rotrBL(w,b,61)^H.shrSL(w,b,6),U=H.add4L(N,L,me[x-7],me[x-16]),V=H.add4H(U,k,F,pe[x-7],pe[x-16]);pe[x]=V|0,me[x]=U|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:u,Dh:f,Dl:c,Eh:l,El:d,Fh:T,Fl:A,Gh:y,Gl:h,Hh:S,Hl:C}=this;for(let x=0;x<80;x++){let _=H.rotrSH(l,d,14)^H.rotrSH(l,d,18)^H.rotrBH(l,d,41),P=H.rotrSL(l,d,14)^H.rotrSL(l,d,18)^H.rotrBL(l,d,41),k=l&T^~l&y,N=d&A^~d&h,w=H.add5L(C,P,N,Yf[x],me[x]),b=H.add5H(w,S,_,k,Gf[x],pe[x]),F=w|0,L=H.rotrSH(n,o,28)^H.rotrBH(n,o,34)^H.rotrBH(n,o,39),U=H.rotrSL(n,o,28)^H.rotrBL(n,o,34)^H.rotrBL(n,o,39),V=n&i^n&a^i&a,v=o&s^o&u^s&u;S=y|0,C=h|0,y=T|0,h=A|0,T=l|0,A=d|0,{h:l,l:d}=H.add(f|0,c|0,b|0,F|0),f=a|0,c=u|0,a=i|0,u=s|0,i=n|0,s=o|0;let B=H.add3L(F,U,v);n=H.add3H(B,b,L,V),o=B|0}({h:n,l:o}=H.add(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=H.add(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:u}=H.add(this.Ch|0,this.Cl|0,a|0,u|0),{h:f,l:c}=H.add(this.Dh|0,this.Dl|0,f|0,c|0),{h:l,l:d}=H.add(this.Eh|0,this.El|0,l|0,d|0),{h:T,l:A}=H.add(this.Fh|0,this.Fl|0,T|0,A|0),{h:y,l:h}=H.add(this.Gh|0,this.Gl|0,y|0,h|0),{h:S,l:C}=H.add(this.Hh|0,this.Hl|0,S|0,C|0),this.set(n,o,i,s,a,u,f,c,l,d,T,A,y,h,S,C)}roundClean(){pe.fill(0),me.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var hs=Wr(()=>new yo);var tn={};xt(tn,{aInRange:()=>At,abool:()=>Ot,abytes:()=>tr,bitGet:()=>tl,bitLen:()=>Eo,bitMask:()=>wr,bitSet:()=>el,bytesToHex:()=>ee,bytesToNumberBE:()=>re,bytesToNumberLE:()=>ye,concatBytes:()=>ne,createHmacDrbg:()=>So,ensureBytes:()=>rt,equalBytes:()=>Jf,hexToBytes:()=>Le,hexToNumber:()=>bo,inRange:()=>xr,isBytes:()=>ge,memoized:()=>ke,notImplemented:()=>nl,numberToBytesBE:()=>xe,numberToBytesLE:()=>De,numberToHexUnpadded:()=>Ne,numberToVarBytesBE:()=>jf,utf8ToBytes:()=>Qf,validateObject:()=>Zt});var Jr=BigInt(0),Qr=BigInt(1),Wf=BigInt(2);function ge(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function tr(e){if(!ge(e))throw new Error("Uint8Array expected")}function Ot(e,t){if(typeof t!="boolean")throw new Error(e+" boolean expected, got "+t)}var Xf=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function ee(e){tr(e);let t="";for(let r=0;r<e.length;r++)t+=Xf[e[r]];return t}function Ne(e){let t=e.toString(16);return t.length&1?"0"+t:t}function bo(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?Jr:BigInt("0x"+e)}var te={_0:48,_9:57,A:65,F:70,a:97,f:102};function ps(e){if(e>=te._0&&e<=te._9)return e-te._0;if(e>=te.A&&e<=te.F)return e-(te.A-10);if(e>=te.a&&e<=te.f)return e-(te.a-10)}function Le(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof 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=ps(e.charCodeAt(i)),a=ps(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 re(e){return bo(ee(e))}function ye(e){return tr(e),bo(ee(Uint8Array.from(e).reverse()))}function xe(e,t){return Le(e.toString(16).padStart(t*2,"0"))}function De(e,t){return xe(e,t).reverse()}function jf(e){return Le(Ne(e))}function rt(e,t,r){let n;if(typeof t=="string")try{n=Le(t)}catch(i){throw new Error(e+" must be hex string or Uint8Array, cause: "+i)}else if(ge(t))n=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");let o=n.length;if(typeof r=="number"&&o!==r)throw new Error(e+" of length "+r+" expected, got "+o);return n}function ne(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];tr(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 Jf(e,t){if(e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}function Qf(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}var xo=e=>typeof e=="bigint"&&Jr<=e;function xr(e,t,r){return xo(e)&&xo(t)&&xo(r)&&t<=e&&e<r}function At(e,t,r,n){if(!xr(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Eo(e){let t;for(t=0;e>Jr;e>>=Qr,t+=1);return t}function tl(e,t){return e>>BigInt(t)&Qr}function el(e,t,r){return e|(r?Qr:Jr)<<BigInt(t)}var wr=e=>(Wf<<BigInt(e-1))-Qr,wo=e=>new Uint8Array(e),ms=e=>Uint8Array.from(e);function So(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=wo(e),o=wo(e),i=0,s=()=>{n.fill(1),o.fill(0),i=0},a=(...l)=>r(o,n,...l),u=(l=wo())=>{o=a(ms([0]),l),n=a(),l.length!==0&&(o=a(ms([1]),l),n=a())},f=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let l=0,d=[];for(;l<t;){n=a();let T=n.slice();d.push(T),l+=n.length}return ne(...d)};return(l,d)=>{s(),u(l);let T;for(;!(T=d(f()));)u();return s(),T}}var rl={bigint:e=>typeof e=="bigint",function:e=>typeof e=="function",boolean:e=>typeof e=="boolean",string:e=>typeof e=="string",stringOrUint8Array:e=>typeof e=="string"||ge(e),isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,t)=>t.Fp.isValid(e),hash:e=>typeof e=="function"&&Number.isSafeInteger(e.outputLen)};function Zt(e,t,r={}){let n=(o,i,s)=>{let a=rl[i];if(typeof a!="function")throw new Error("invalid validator function");let u=e[o];if(!(s&&u===void 0)&&!a(u,e))throw new Error("param "+String(o)+" is invalid. Expected "+i+", got "+u)};for(let[o,i]of Object.entries(t))n(o,i,!1);for(let[o,i]of Object.entries(r))n(o,i,!0);return e}var nl=()=>{throw new Error("not implemented")};function ke(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 it=BigInt(0),Q=BigInt(1),Pe=BigInt(2),ol=BigInt(3),Ao=BigInt(4),gs=BigInt(5),ys=BigInt(8),il=BigInt(9),sl=BigInt(16);function W(e,t){let r=e%t;return r>=it?r:t+r}function al(e,t,r){if(t<it)throw new Error("invalid exponent, negatives unsupported");if(r<=it)throw new Error("invalid modulus");if(r===Q)return it;let n=Q;for(;t>it;)t&Q&&(n=n*e%r),e=e*e%r,t>>=Q;return n}function tt(e,t,r){let n=e;for(;t-- >it;)n*=n,n%=r;return n}function en(e,t){if(e===it)throw new Error("invert: expected non-zero number");if(t<=it)throw new Error("invert: expected positive modulus, got "+t);let r=W(e,t),n=t,o=it,i=Q,s=Q,a=it;for(;r!==it;){let f=n/r,c=n%r,l=o-s*f,d=i-a*f;n=r,r=c,o=s,i=a,s=l,a=d}if(n!==Q)throw new Error("invert: does not exist");return W(o,t)}function cl(e){let t=(e-Q)/Pe,r,n,o;for(r=e-Q,n=0;r%Pe===it;r/=Pe,n++);for(o=Pe;o<e&&al(o,t,e)!==e-Q;o++)if(o>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){let s=(e+Q)/Ao;return function(u,f){let c=u.pow(f,s);if(!u.eql(u.sqr(c),f))throw new Error("Cannot find square root");return c}}let i=(r+Q)/Pe;return function(a,u){if(a.pow(u,t)===a.neg(a.ONE))throw new Error("Cannot find square root");let f=n,c=a.pow(a.mul(a.ONE,o),r),l=a.pow(u,i),d=a.pow(u,r);for(;!a.eql(d,a.ONE);){if(a.eql(d,a.ZERO))return a.ZERO;let T=1;for(let y=a.sqr(d);T<f&&!a.eql(y,a.ONE);T++)y=a.sqr(y);let A=a.pow(c,Q<<BigInt(f-T-1));c=a.sqr(A),l=a.mul(l,A),d=a.mul(d,c),f=T}return l}}function ul(e){if(e%Ao===ol){let t=(e+Q)/Ao;return function(n,o){let i=n.pow(o,t);if(!n.eql(n.sqr(i),o))throw new Error("Cannot find square root");return i}}if(e%ys===gs){let t=(e-gs)/ys;return function(n,o){let i=n.mul(o,Pe),s=n.pow(i,t),a=n.mul(o,s),u=n.mul(n.mul(a,Pe),s),f=n.mul(a,n.sub(u,n.ONE));if(!n.eql(n.sqr(f),o))throw new Error("Cannot find square root");return f}}return e%sl,cl(e)}var xs=(e,t)=>(W(e,t)&Q)===Q,fl=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function vo(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},r=fl.reduce((n,o)=>(n[o]="function",n),t);return Zt(e,r)}function ll(e,t,r){if(r<it)throw new Error("invalid exponent, negatives unsupported");if(r===it)return e.ONE;if(r===Q)return t;let n=e.ONE,o=t;for(;r>it;)r&Q&&(n=e.mul(n,o)),o=e.sqr(o),r>>=Q;return n}function dl(e,t){let r=new Array(t.length),n=t.reduce((i,s,a)=>e.is0(s)?i:(r[a]=i,e.mul(i,s)),e.ONE),o=e.inv(n);return t.reduceRight((i,s,a)=>e.is0(s)?i:(r[a]=e.mul(i,r[a]),e.mul(i,s)),o),r}function Bo(e,t){let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function we(e,t,r=!1,n={}){if(e<=it)throw new Error("invalid field: expected ORDER > 0, got "+e);let{nBitLength:o,nByteLength:i}=Bo(e,t);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let s,a=Object.freeze({ORDER:e,isLE:r,BITS:o,BYTES:i,MASK:wr(o),ZERO:it,ONE:Q,create:u=>W(u,e),isValid:u=>{if(typeof u!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof u);return it<=u&&u<e},is0:u=>u===it,isOdd:u=>(u&Q)===Q,neg:u=>W(-u,e),eql:(u,f)=>u===f,sqr:u=>W(u*u,e),add:(u,f)=>W(u+f,e),sub:(u,f)=>W(u-f,e),mul:(u,f)=>W(u*f,e),pow:(u,f)=>ll(a,u,f),div:(u,f)=>W(u*en(f,e),e),sqrN:u=>u*u,addN:(u,f)=>u+f,subN:(u,f)=>u-f,mulN:(u,f)=>u*f,inv:u=>en(u,e),sqrt:n.sqrt||(u=>(s||(s=ul(e)),s(a,u))),invertBatch:u=>dl(a,u),cmov:(u,f,c)=>c?f:u,toBytes:u=>r?De(u,i):xe(u,i),fromBytes:u=>{if(u.length!==i)throw new Error("Field.fromBytes: expected "+i+" bytes, got "+u.length);return r?ye(u):re(u)}});return Object.freeze(a)}function ws(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 To(e){let t=ws(e);return t+Math.ceil(t/2)}function bs(e,t,r=!1){let n=e.length,o=ws(t),i=To(t);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=r?ye(e):re(e),a=W(s,t-Q)+Q;return r?De(a,o):xe(a,o)}var Es=BigInt(0),rn=BigInt(1);function Io(e,t){let r=t.negate();return e?r:t}function Ss(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Co(e,t){Ss(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1);return{windows:r,windowSize:n}}function hl(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 pl(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 Uo=new WeakMap,As=new WeakMap;function Ro(e){return As.get(e)||1}function nn(e,t){return{constTimeNegate:Io,hasPrecomputes(r){return Ro(r)!==1},unsafeLadder(r,n,o=e.ZERO){let i=r;for(;n>Es;)n&rn&&(o=o.add(i)),i=i.double(),n>>=rn;return o},precomputeWindow(r,n){let{windows:o,windowSize:i}=Co(n,t),s=[],a=r,u=a;for(let f=0;f<o;f++){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{windows:i,windowSize:s}=Co(r,t),a=e.ZERO,u=e.BASE,f=BigInt(2**r-1),c=2**r,l=BigInt(r);for(let d=0;d<i;d++){let T=d*s,A=Number(o&f);o>>=l,A>s&&(A-=c,o+=rn);let y=T,h=T+Math.abs(A)-1,S=d%2!==0,C=A<0;A===0?u=u.add(Io(S,n[y])):a=a.add(Io(C,n[h]))}return{p:a,f:u}},wNAFUnsafe(r,n,o,i=e.ZERO){let{windows:s,windowSize:a}=Co(r,t),u=BigInt(2**r-1),f=2**r,c=BigInt(r);for(let l=0;l<s;l++){let d=l*a;if(o===Es)break;let T=Number(o&u);if(o>>=c,T>a&&(T-=f,o+=rn),T===0)continue;let A=n[d+Math.abs(T)-1];T<0&&(A=A.negate()),i=i.add(A)}return i},getPrecomputes(r,n,o){let i=Uo.get(n);return i||(i=this.precomputeWindow(n,r),r!==1&&Uo.set(n,o(i))),i},wNAFCached(r,n,o){let i=Ro(r);return this.wNAF(i,this.getPrecomputes(i,r,o),n)},wNAFCachedUnsafe(r,n,o,i){let s=Ro(r);return s===1?this.unsafeLadder(r,n,i):this.wNAFUnsafe(s,this.getPrecomputes(s,r,o),n,i)},setWindowSize(r,n){Ss(n,t),As.set(r,n),Uo.delete(r)}}}function on(e,t,r,n){if(hl(r,e),pl(n,t),r.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let o=e.ZERO,i=Eo(BigInt(r.length)),s=i>12?i-3:i>4?i-2:i?2:1,a=(1<<s)-1,u=new Array(a+1).fill(o),f=Math.floor((t.BITS-1)/s)*s,c=o;for(let l=f;l>=0;l-=s){u.fill(o);for(let T=0;T<n.length;T++){let A=n[T],y=Number(A>>BigInt(l)&BigInt(a));u[y]=u[y].add(r[T])}let d=o;for(let T=u.length-1,A=o;T>0;T--)A=A.add(u[T]),d=d.add(A);if(c=c.add(d),l!==0)for(let T=0;T<s;T++)c=c.double()}return c}function br(e){return vo(e.Fp),Zt(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Bo(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}var Mt=BigInt(0),vt=BigInt(1),sn=BigInt(2),ml=BigInt(8),gl={zip215:!0};function yl(e){let t=br(e);return Zt(e,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function vs(e){let t=yl(e),{Fp:r,n,prehash:o,hash:i,randomBytes:s,nByteLength:a,h:u}=t,f=sn<<BigInt(a*8)-vt,c=r.create,l=we(t.n,t.nBitLength),d=t.uvRatio||((g,p)=>{try{return{isValid:!0,value:r.sqrt(g*r.inv(p))}}catch{return{isValid:!1,value:Mt}}}),T=t.adjustScalarBytes||(g=>g),A=t.domain||((g,p,E)=>{if(Ot("phflag",E),p.length||E)throw new Error("Contexts/pre-hash are not supported");return g});function y(g,p){At("coordinate "+g,p,Mt,f)}function h(g){if(!(g instanceof x))throw new Error("ExtendedPoint expected")}let S=ke((g,p)=>{let{ex:E,ey:R,ez:O}=g,M=g.is0();p==null&&(p=M?ml:r.inv(O));let z=c(E*p),$=c(R*p),q=c(O*p);if(M)return{x:Mt,y:vt};if(q!==vt)throw new Error("invZ was invalid");return{x:z,y:$}}),C=ke(g=>{let{a:p,d:E}=t;if(g.is0())throw new Error("bad point: ZERO");let{ex:R,ey:O,ez:M,et:z}=g,$=c(R*R),q=c(O*O),G=c(M*M),X=c(G*G),at=c($*p),ct=c(G*c(at+q)),lt=c(X+c(E*c($*q)));if(ct!==lt)throw new Error("bad point: equation left != right (1)");let pt=c(R*O),Et=c(M*z);if(pt!==Et)throw new Error("bad point: equation left != right (2)");return!0});class x{constructor(p,E,R,O){this.ex=p,this.ey=E,this.ez=R,this.et=O,y("x",p),y("y",E),y("z",R),y("t",O),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(p){if(p instanceof x)throw new Error("extended point not allowed");let{x:E,y:R}=p||{};return y("x",E),y("y",R),new x(E,R,vt,c(E*R))}static normalizeZ(p){let E=r.invertBatch(p.map(R=>R.ez));return p.map((R,O)=>R.toAffine(E[O])).map(x.fromAffine)}static msm(p,E){return on(x,l,p,E)}_setWindowSize(p){k.setWindowSize(this,p)}assertValidity(){C(this)}equals(p){h(p);let{ex:E,ey:R,ez:O}=this,{ex:M,ey:z,ez:$}=p,q=c(E*$),G=c(M*O),X=c(R*$),at=c(z*O);return q===G&&X===at}is0(){return this.equals(x.ZERO)}negate(){return new x(c(-this.ex),this.ey,this.ez,c(-this.et))}double(){let{a:p}=t,{ex:E,ey:R,ez:O}=this,M=c(E*E),z=c(R*R),$=c(sn*c(O*O)),q=c(p*M),G=E+R,X=c(c(G*G)-M-z),at=q+z,ct=at-$,lt=q-z,pt=c(X*ct),Et=c(at*lt),yt=c(X*lt),$t=c(ct*at);return new x(pt,Et,$t,yt)}add(p){h(p);let{a:E,d:R}=t,{ex:O,ey:M,ez:z,et:$}=this,{ex:q,ey:G,ez:X,et:at}=p;if(E===BigInt(-1)){let Li=c((M-O)*(G+q)),Di=c((M+O)*(G-q)),Qn=c(Di-Li);if(Qn===Mt)return this.double();let ki=c(z*sn*at),Pi=c($*sn*X),Fi=Pi+ki,Oi=Di+Li,Mi=Pi-ki,uu=c(Fi*Qn),fu=c(Oi*Mi),lu=c(Fi*Mi),du=c(Qn*Oi);return new x(uu,fu,du,lu)}let ct=c(O*q),lt=c(M*G),pt=c($*R*at),Et=c(z*X),yt=c((O+M)*(q+G)-ct-lt),$t=Et-pt,Xt=Et+pt,dr=c(lt-E*ct),iu=c(yt*$t),su=c(Xt*dr),au=c(yt*dr),cu=c($t*Xt);return new x(iu,su,cu,au)}subtract(p){return this.add(p.negate())}wNAF(p){return k.wNAFCached(this,p,x.normalizeZ)}multiply(p){let E=p;At("scalar",E,vt,n);let{p:R,f:O}=this.wNAF(E);return x.normalizeZ([R,O])[0]}multiplyUnsafe(p,E=x.ZERO){let R=p;return At("scalar",R,Mt,n),R===Mt?P:this.is0()||R===vt?this:k.wNAFCachedUnsafe(this,R,x.normalizeZ,E)}isSmallOrder(){return this.multiplyUnsafe(u).is0()}isTorsionFree(){return k.unsafeLadder(this,n).is0()}toAffine(p){return S(this,p)}clearCofactor(){let{h:p}=t;return p===vt?this:this.multiplyUnsafe(p)}static fromHex(p,E=!1){let{d:R,a:O}=t,M=r.BYTES;p=rt("pointHex",p,M),Ot("zip215",E);let z=p.slice(),$=p[M-1];z[M-1]=$&-129;let q=ye(z),G=E?f:r.ORDER;At("pointHex.y",q,Mt,G);let X=c(q*q),at=c(X-vt),ct=c(R*X-O),{isValid:lt,value:pt}=d(at,ct);if(!lt)throw new Error("Point.fromHex: invalid y coordinate");let Et=(pt&vt)===vt,yt=($&128)!==0;if(!E&&pt===Mt&&yt)throw new Error("Point.fromHex: x=0 and x_0=1");return yt!==Et&&(pt=c(-pt)),x.fromAffine({x:pt,y:q})}static fromPrivateKey(p){return b(p).point}toRawBytes(){let{x:p,y:E}=this.toAffine(),R=De(E,r.BYTES);return R[R.length-1]|=p&vt?128:0,R}toHex(){return ee(this.toRawBytes())}}x.BASE=new x(t.Gx,t.Gy,vt,c(t.Gx*t.Gy)),x.ZERO=new x(Mt,vt,vt,Mt);let{BASE:_,ZERO:P}=x,k=nn(x,a*8);function N(g){return W(g,n)}function w(g){return N(ye(g))}function b(g){let p=r.BYTES;g=rt("private key",g,p);let E=rt("hashed private key",i(g),2*p),R=T(E.slice(0,p)),O=E.slice(p,2*p),M=w(R),z=_.multiply(M),$=z.toRawBytes();return{head:R,prefix:O,scalar:M,point:z,pointBytes:$}}function F(g){return b(g).pointBytes}function L(g=new Uint8Array,...p){let E=ne(...p);return w(i(A(E,rt("context",g),!!o)))}function U(g,p,E={}){g=rt("message",g),o&&(g=o(g));let{prefix:R,scalar:O,pointBytes:M}=b(p),z=L(E.context,R,g),$=_.multiply(z).toRawBytes(),q=L(E.context,$,M,g),G=N(z+q*O);At("signature.s",G,Mt,n);let X=ne($,De(G,r.BYTES));return rt("result",X,r.BYTES*2)}let V=gl;function v(g,p,E,R=V){let{context:O,zip215:M}=R,z=r.BYTES;g=rt("signature",g,2*z),p=rt("message",p),E=rt("publicKey",E,z),M!==void 0&&Ot("zip215",M),o&&(p=o(p));let $=ye(g.slice(z,2*z)),q,G,X;try{q=x.fromHex(E,M),G=x.fromHex(g.slice(0,z),M),X=_.multiplyUnsafe($)}catch{return!1}if(!M&&q.isSmallOrder())return!1;let at=L(O,G.toRawBytes(),q.toRawBytes(),p);return G.add(q.multiplyUnsafe(at)).subtract(X).clearCofactor().equals(x.ZERO)}return _._setWindowSize(8),{CURVE:t,getPublicKey:F,sign:U,verify:v,ExtendedPoint:x,utils:{getExtendedPublicKey:b,randomPrivateKey:()=>s(r.BYTES),precompute(g=8,p=x.BASE){return p._setWindowSize(g),p.multiply(BigInt(3)),p}}}}var _o=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Bs=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),O0=BigInt(0),xl=BigInt(1),Ts=BigInt(2),M0=BigInt(3),wl=BigInt(5),bl=BigInt(8);function El(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),i=_o,a=e*e%i*e%i,u=tt(a,Ts,i)*a%i,f=tt(u,xl,i)*e%i,c=tt(f,wl,i)*f%i,l=tt(c,t,i)*c%i,d=tt(l,r,i)*l%i,T=tt(d,n,i)*d%i,A=tt(T,o,i)*T%i,y=tt(A,o,i)*T%i,h=tt(y,t,i)*c%i;return{pow_p_5_8:tt(h,Ts,i)*e%i,b2:a}}function Sl(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}function Al(e,t){let r=_o,n=W(t*t*t,r),o=W(n*n*t,r),i=El(e*o).pow_p_5_8,s=W(e*n*i,r),a=W(t*s*s,r),u=s,f=W(s*Bs,r),c=a===e,l=a===W(-e,r),d=a===W(-e*Bs,r);return c&&(s=u),(l||d)&&(s=f),xs(s,r)&&(s=W(-s,r)),{isValid:c||l,value:s}}var vl=we(_o,void 0,!0),Bl={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:vl,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:bl,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:hs,randomBytes:Xr,adjustScalarBytes:Sl,uvRatio:Al},Is=vs(Bl);var an=32;function Cs(e,t,r){return Is.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}var cn=class{type="Ed25519";raw;constructor(t){this.raw=No(t,an)}toMultihash(){return Qt.digest(er(this))}toCID(){return J.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ot(this.raw,t.raw)}verify(t,r){return Cs(this.raw,r,t)}};function Lo(e){return e=No(e,an),new cn(e)}function No(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new mt(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}function _t(e=0){return new Uint8Array(e)}function Bt(e=0){return new Uint8Array(e)}var Il=Math.pow(2,7),Cl=Math.pow(2,14),Ul=Math.pow(2,21),Rs=Math.pow(2,28),_s=Math.pow(2,35),Ns=Math.pow(2,42),Ls=Math.pow(2,49),wt=128,be=127;function Er(e){if(e<Il)return 1;if(e<Cl)return 2;if(e<Ul)return 3;if(e<Rs)return 4;if(e<_s)return 5;if(e<Ns)return 6;if(e<Ls)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ds(e,t,r=0){switch(Er(e)){case 8:t[r++]=e&255|wt,e/=128;case 7:t[r++]=e&255|wt,e/=128;case 6:t[r++]=e&255|wt,e/=128;case 5:t[r++]=e&255|wt,e/=128;case 4:t[r++]=e&255|wt,e>>>=7;case 3:t[r++]=e&255|wt,e>>>=7;case 2:t[r++]=e&255|wt,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function ks(e,t){let r=e[t],n=0;if(n+=r&be,r<wt||(r=e[t+1],n+=(r&be)<<7,r<wt)||(r=e[t+2],n+=(r&be)<<14,r<wt)||(r=e[t+3],n+=(r&be)<<21,r<wt)||(r=e[t+4],n+=(r&be)*Rs,r<wt)||(r=e[t+5],n+=(r&be)*_s,r<wt)||(r=e[t+6],n+=(r&be)*Ns,r<wt)||(r=e[t+7],n+=(r&be)*Ls,r<wt))return n;throw new RangeError("Could not decode varint")}var Do=new Float32Array([-0]),Ee=new Uint8Array(Do.buffer);function Ps(e,t,r){Do[0]=e,t[r]=Ee[0],t[r+1]=Ee[1],t[r+2]=Ee[2],t[r+3]=Ee[3]}function Fs(e,t){return Ee[0]=e[t],Ee[1]=e[t+1],Ee[2]=e[t+2],Ee[3]=e[t+3],Do[0]}var ko=new Float64Array([-0]),gt=new Uint8Array(ko.buffer);function Os(e,t,r){ko[0]=e,t[r]=gt[0],t[r+1]=gt[1],t[r+2]=gt[2],t[r+3]=gt[3],t[r+4]=gt[4],t[r+5]=gt[5],t[r+6]=gt[6],t[r+7]=gt[7]}function Ms(e,t){return gt[0]=e[t],gt[1]=e[t+1],gt[2]=e[t+2],gt[3]=e[t+3],gt[4]=e[t+4],gt[5]=e[t+5],gt[6]=e[t+6],gt[7]=e[t+7],ko[0]}var Rl=BigInt(Number.MAX_SAFE_INTEGER),_l=BigInt(Number.MIN_SAFE_INTEGER),Tt=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 Fe;if(t<Rl&&t>_l)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>Ks&&(o=0n,++n>Ks&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return Fe;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):Fe}},Fe=new Tt(0,0);Fe.toBigInt=function(){return 0n};Fe.zzEncode=Fe.zzDecode=function(){return this};Fe.length=function(){return 1};var Ks=4294967296n;function Vs(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 qs(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 Po(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 un(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var Fo=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 un(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Kt(this,4);return un(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Kt(this,4);let t=Fs(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Kt(this,4);let t=Ms(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 qs(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 Tt(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=un(this.buf,this.pos+=4),r=un(this.buf,this.pos+=4);return new Tt(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=ks(this.buf,this.pos);return this.pos+=Er(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 Oo(e){return new Fo(e instanceof Uint8Array?e:e.subarray())}function Se(e,t,r){let n=Oo(e);return t.decode(n,void 0,r)}var Mo={};xt(Mo,{base10:()=>Nl});var Nl=fe({prefix:"9",name:"base10",alphabet:"0123456789"});var Ko={};xt(Ko,{base16:()=>Ll,base16upper:()=>Dl});var Ll=nt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Dl=nt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Vo={};xt(Vo,{base2:()=>kl});var kl=nt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var qo={};xt(qo,{base256emoji:()=>Kl});var zs=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}"),Pl=zs.reduce((e,t,r)=>(e[r]=t,e),[]),Fl=zs.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Ol(e){return e.reduce((t,r)=>(t+=Pl[r],t),"")}function Ml(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Fl[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var Kl=Ze({prefix:"\u{1F680}",name:"base256emoji",encode:Ol,decode:Ml});var Ho={};xt(Ho,{base8:()=>Vl});var Vl=nt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var zo={};xt(zo,{identity:()=>ql});var ql=Ze({prefix:"\0",name:"identity",encode:e=>$i(e),decode:e=>zi(e)});var Ep=new TextEncoder,Sp=new TextDecoder;var Go={};xt(Go,{sha256:()=>Sr,sha512:()=>$l});function Zo({name:e,code:t,encode:r}){return new $o(e,t,r)}var $o=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?Pt(this.code,r):r.then(n=>Pt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Zs(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var Sr=Zo({name:"sha2-256",code:18,encode:Zs("SHA-256")}),$l=Zo({name:"sha2-512",code:19,encode:Zs("SHA-512")});var Yo={...zo,...Vo,...Ho,...Mo,...Ko,...io,...fo,...so,...co,...qo},Dp={...Go,...po};function Ys(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Gs=Ys("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Wo=Ys("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=Bt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Zl={utf8:Gs,"utf-8":Gs,hex:Yo.base16,latin1:Wo,ascii:Wo,binary:Wo,...Yo},fn=Zl;function Y(e,t="utf8"){let r=fn[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function Xo(e){let t=e??8192,r=t>>>1,n,o=t;return function(s){if(s<1||s>r)return Bt(s);o+s>t&&(n=Bt(t),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var Oe=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function jo(){}var Qo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Gl=Xo();function Yl(e){return globalThis.Buffer!=null?Bt(e):Gl(e)}var vr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Oe(jo,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new Oe(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new ti((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(ln,10,Tt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=Tt.fromBigInt(t);return this._push(ln,r.length(),r)}uint64Number(t){return this._push(Ds,Er(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=Tt.fromBigInt(t).zzEncode();return this._push(ln,r.length(),r)}sint64Number(t){let r=Tt.fromNumber(t).zzEncode();return this._push(ln,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Jo,1,t?1:0)}fixed32(t){return this._push(Ar,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=Tt.fromBigInt(t);return this._push(Ar,4,r.lo)._push(Ar,4,r.hi)}fixed64Number(t){let r=Tt.fromNumber(t);return this._push(Ar,4,r.lo)._push(Ar,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(Ps,4,t)}double(t){return this._push(Os,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Jo,1,0):this.uint32(r)._push(Xl,r,t)}string(t){let r=Vs(t);return r!==0?this.uint32(r)._push(Po,r,t):this._push(Jo,1,0)}fork(){return this.states=new Qo(this),this.head=this.tail=new Oe(jo,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 Oe(jo,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=Yl(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Jo(e,t,r){t[r]=e&255}function Wl(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var ti=class extends Oe{next;constructor(t,r){super(Wl,t,r),this.next=void 0}};function ln(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function Ar(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 Xl(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(vr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(jl,t,e),this},vr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Jl,t,e),this});function jl(e,t,r){t.set(e,r)}function Jl(e,t,r){e.length<40?Po(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(Y(e),r)}function ei(){return new vr}function Ae(e,t){let r=ei();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 dn(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function Br(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 dn("enum",rr.VARINT,r,n)}function ve(e,t){return dn("message",rr.LENGTH_DELIMITED,e,t)}var st;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1"})(st||(st={}));var ri;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1"})(ri||(ri={}));(function(e){e.codec=()=>Br(ri)})(st||(st={}));var Gt;(function(e){let t;e.codec=()=>(t==null&&(t=ve((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),st.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=st.codec().decode(r);break}case 2:{i.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return i})),t),e.encode=r=>Ae(r,e.codec()),e.decode=(r,n)=>Se(r,e.codec(),n)})(Gt||(Gt={}));var ni;(function(e){let t;e.codec=()=>(t==null&&(t=ve((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),st.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=st.codec().decode(r);break}case 2:{i.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return i})),t),e.encode=r=>Ae(r,e.codec()),e.decode=(r,n)=>Se(r,e.codec(),n)})(ni||(ni={}));var Cr={};xt(Cr,{MAX_RSA_KEY_SIZE:()=>ci,generateRSAKeyPair:()=>ua,jwkToJWKKeyPair:()=>fa,jwkToPkcs1:()=>fd,jwkToPkix:()=>fi,jwkToRSAPrivateKey:()=>ca,pkcs1ToJwk:()=>ia,pkcs1ToRSAPrivateKey:()=>aa,pkixToJwk:()=>sa,pkixToRSAPublicKey:()=>li});var Ql=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Be=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Te=new Uint32Array(64),oi=class extends Qe{constructor(){super(64,32,8,!1),this.A=Be[0]|0,this.B=Be[1]|0,this.C=Be[2]|0,this.D=Be[3]|0,this.E=Be[4]|0,this.F=Be[5]|0,this.G=Be[6]|0,this.H=Be[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)Te[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let d=Te[l-15],T=Te[l-2],A=Ft(d,7)^Ft(d,18)^d>>>3,y=Ft(T,17)^Ft(T,19)^T>>>10;Te[l]=y+Te[l-7]+A+Te[l-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:u,G:f,H:c}=this;for(let l=0;l<64;l++){let d=Ft(a,6)^Ft(a,11)^Ft(a,25),T=c+d+fs(a,u,f)+Ql[l]+Te[l]|0,y=(Ft(n,2)^Ft(n,13)^Ft(n,22))+ls(n,o,i)|0;c=f,f=u,u=a,a=s+T|0,s=i,i=o,o=n,n=T+y|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,f=f+this.G|0,c=c+this.H|0,this.set(n,o,i,s,a,u,f,c)}roundClean(){Te.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var nr=Wr(()=>new oi);function et(e,t="utf8"){let r=fn[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}function Ie(e,t){t==null&&(t=e.reduce((o,i)=>o+i.length,0));let r=Bt(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var js=Symbol.for("@achingbrain/uint8arraylist");function Xs(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 hn(e){return!!e?.[js]}var Vt=class e{bufs;length;[js]=!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(hn(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(hn(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=Xs(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Xs(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(hn(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 Ie(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Ie(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 f=t>=a&&t<u,c=r>a&&r<=u;if(f&&c){if(t===a&&r===u){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(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(!hn(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,f=n.byteLength-1,c;for(let l=r;l<=u;l+=c){c=0;for(let d=f;d>=0;d--){let T=this.get(l+d);if(n[d]!==T){c=Math.max(1,d-a[T]);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=Bt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=_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=Bt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=_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(!ot(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,i)=>o+i.byteLength,0)),n.length=r,n}};var td=parseInt("11111",2),si=parseInt("10000000",2),ed=parseInt("01111111",2),Js={2:rd,3:id,5:od,6:nd,16:ii,22:ii,48:ii};function Tr(e,t={offset:0}){let r=e[t.offset]&td;if(t.offset++,Js[r]!=null)return Js[r](e,t);throw new Error("No decoder for tag "+r)}function pn(e,t){let r=0;if((e[t.offset]&si)===si){let n=e[t.offset]&ed,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 ii(e,t){pn(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Tr(e,t);if(n===null)break;r.push(n)}return r}function rd(e,t){let r=pn(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 nd(e,t){let r=pn(e,t);return t.offset+=r,["oid-unimplemented"]}function od(e,t){return t.offset++,null}function id(e,t){let r=pn(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return Tr(o,{offset:0})}function sd(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new Vt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function ai(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=sd(e.byteLength);return new Vt(Uint8Array.from([t.byteLength|si]),t)}function Nt(e){let t=new Vt,r=parseInt("10000000",2);return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new Vt(Uint8Array.from([2]),ai(t),t)}function Qs(e){let t=Uint8Array.from([0]),r=new Vt(t,e);return new Vt(Uint8Array.from([3]),ai(r),r)}function mn(e){let t=new Vt;for(let r of e)t.append(r);return new Vt(Uint8Array.from([48]),ai(t),t)}var Ir=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},gn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var ta={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new gn("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 Ce=ta;async function ea(e){let t=await Ce.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),r=await ad(t);return{privateKey:r[0],publicKey:r[1]}}async function ra(e,t){let r=await Ce.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await Ce.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},r,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(n,0,n.byteLength)}async function na(e,t,r){let n=await Ce.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return Ce.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,t,r instanceof Uint8Array?r:r.subarray())}async function ad(e){if(e.privateKey==null||e.publicKey==null)throw new mt("Private and public key are required");return Promise.all([Ce.get().subtle.exportKey("jwk",e.privateKey),Ce.get().subtle.exportKey("jwk",e.publicKey)])}function oa(e){if(e.kty!=="RSA")throw new mt("invalid key type");if(e.n==null)throw new mt("invalid key modulus");return Y(e.n,"base64url").length*8}var or=class{type="RSA";_key;_raw;_multihash;constructor(t,r){this._key=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Cr.jwkToPkix(this._key)),this._raw}toMultihash(){return this._multihash}toCID(){return J.createV1(114,this._multihash)}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ot(this.raw,t.raw)}verify(t,r){return na(this._key,r,t)}},Ur=class{type="RSA";_key;_raw;publicKey;constructor(t,r){this._key=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Cr.jwkToPkcs1(this._key)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ot(this.raw,t.raw)}sign(t){return ra(this._key,t)}};var ci=8192,ui=18,cd=1062,ud=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function ia(e){let t=Tr(e);return{n:et(t[1],"base64url"),e:et(t[2],"base64url"),d:et(t[3],"base64url"),p:et(t[4],"base64url"),q:et(t[5],"base64url"),dp:et(t[6],"base64url"),dq:et(t[7],"base64url"),qi:et(t[8],"base64url"),kty:"RSA"}}function fd(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 mt("JWK was missing components");return mn([Nt(Uint8Array.from([0])),Nt(Y(e.n,"base64url")),Nt(Y(e.e,"base64url")),Nt(Y(e.d,"base64url")),Nt(Y(e.p,"base64url")),Nt(Y(e.q,"base64url")),Nt(Y(e.dp,"base64url")),Nt(Y(e.dq,"base64url")),Nt(Y(e.qi,"base64url"))]).subarray()}function sa(e){let t=Tr(e,{offset:0});return{kty:"RSA",n:et(t[1][0],"base64url"),e:et(t[1][1],"base64url")}}function fi(e){if(e.n==null||e.e==null)throw new mt("JWK was missing components");return mn([ud,Qs(mn([Nt(Y(e.n,"base64url")),Nt(Y(e.e,"base64url"))]))]).subarray()}function aa(e){let t=ia(e);return ca(t)}function li(e,t){if(e.byteLength>=cd)throw new He("Key size is too large");let r=sa(e);if(t==null){let n=nr(Gt.encode({Type:st.RSA,Data:e}));t=Pt(ui,n)}return new or(r,t)}function ca(e){if(oa(e)>ci)throw new mt("Key size is too large");let t=fa(e),r=nr(Gt.encode({Type:st.RSA,Data:fi(t.publicKey)})),n=Pt(ui,r);return new Ur(t.privateKey,new or(t.publicKey,n))}async function ua(e){if(e>ci)throw new mt("Key size is too large");let t=await ea(e),r=nr(Gt.encode({Type:st.RSA,Data:fi(t.publicKey)})),n=Pt(ui,r);return new Ur(t.privateKey,new or(t.publicKey,n))}function fa(e){if(e==null)throw new mt("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}var yn=class extends Je{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,as(t);let n=yr(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),i.fill(0)}update(t){return je(this),this.iHash.update(t),this}digestInto(t){je(this),Xe(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}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},di=(e,t,r)=>new yn(e,t).update(r).digest();di.create=(e,t)=>new yn(e,t);function la(e){e.lowS!==void 0&&Ot("lowS",e.lowS),e.prehash!==void 0&&Ot("prehash",e.prehash)}function ld(e){let t=br(e);Zt(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:r,Fp:n,a:o}=t;if(r){if(!n.eql(o,n.ZERO))throw new Error("invalid endomorphism, can only be defined for Koblitz curves that have a=0");if(typeof r!="object"||typeof r.beta!="bigint"||typeof r.splitScalar!="function")throw new Error("invalid endomorphism, expected beta: bigint and splitScalar: function")}return Object.freeze({...t})}var{bytesToNumberBE:dd,hexToBytes:hd}=tn,hi=class extends Error{constructor(t=""){super(t)}},oe={Err:hi,_tlv:{encode:(e,t)=>{let{Err:r}=oe;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=Ne(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let i=n>127?Ne(o.length/2|128):"";return Ne(e)+i+o+t},decode(e,t){let{Err:r}=oe,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 f=t.subarray(n,n+u);if(f.length!==u)throw new r("tlv.decode: length bytes not complete");if(f[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let c of f)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}=oe;if(e<ie)throw new t("integer: negative integers are not allowed");let r=Ne(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}=oe;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 dd(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=oe,o=typeof e=="string"?hd(e):e;tr(o);let{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:f,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(f)}},hexFromSig(e){let{_tlv:t,_int:r}=oe,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),i=n+o;return t.encode(48,i)}},ie=BigInt(0),ut=BigInt(1),rg=BigInt(2),da=BigInt(3),ng=BigInt(4);function pd(e){let t=ld(e),{Fp:r}=t,n=we(t.n,t.nBitLength),o=t.toBytes||((y,h,S)=>{let C=h.toAffine();return ne(Uint8Array.from([4]),r.toBytes(C.x),r.toBytes(C.y))}),i=t.fromBytes||(y=>{let h=y.subarray(1),S=r.fromBytes(h.subarray(0,r.BYTES)),C=r.fromBytes(h.subarray(r.BYTES,2*r.BYTES));return{x:S,y:C}});function s(y){let{a:h,b:S}=t,C=r.sqr(y),x=r.mul(C,y);return r.add(r.add(x,r.mul(y,h)),S)}if(!r.eql(r.sqr(t.Gy),s(t.Gx)))throw new Error("bad generator point: equation left != right");function a(y){return xr(y,ut,t.n)}function u(y){let{allowedPrivateKeyLengths:h,nByteLength:S,wrapPrivateKey:C,n:x}=t;if(h&&typeof y!="bigint"){if(ge(y)&&(y=ee(y)),typeof y!="string"||!h.includes(y.length))throw new Error("invalid private key");y=y.padStart(S*2,"0")}let _;try{_=typeof y=="bigint"?y:re(rt("private key",y,S))}catch{throw new Error("invalid private key, expected hex or "+S+" bytes, got "+typeof y)}return C&&(_=W(_,x)),At("private key",_,ut,x),_}function f(y){if(!(y instanceof d))throw new Error("ProjectivePoint expected")}let c=ke((y,h)=>{let{px:S,py:C,pz:x}=y;if(r.eql(x,r.ONE))return{x:S,y:C};let _=y.is0();h==null&&(h=_?r.ONE:r.inv(x));let P=r.mul(S,h),k=r.mul(C,h),N=r.mul(x,h);if(_)return{x:r.ZERO,y:r.ZERO};if(!r.eql(N,r.ONE))throw new Error("invZ was invalid");return{x:P,y:k}}),l=ke(y=>{if(y.is0()){if(t.allowInfinityPoint&&!r.is0(y.py))return;throw new Error("bad point: ZERO")}let{x:h,y:S}=y.toAffine();if(!r.isValid(h)||!r.isValid(S))throw new Error("bad point: x or y not FE");let C=r.sqr(S),x=s(h);if(!r.eql(C,x))throw new Error("bad point: equation left != right");if(!y.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class d{constructor(h,S,C){if(this.px=h,this.py=S,this.pz=C,h==null||!r.isValid(h))throw new Error("x required");if(S==null||!r.isValid(S))throw new Error("y required");if(C==null||!r.isValid(C))throw new Error("z required");Object.freeze(this)}static fromAffine(h){let{x:S,y:C}=h||{};if(!h||!r.isValid(S)||!r.isValid(C))throw new Error("invalid affine point");if(h instanceof d)throw new Error("projective point not allowed");let x=_=>r.eql(_,r.ZERO);return x(S)&&x(C)?d.ZERO:new d(S,C,r.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){let S=r.invertBatch(h.map(C=>C.pz));return h.map((C,x)=>C.toAffine(S[x])).map(d.fromAffine)}static fromHex(h){let S=d.fromAffine(i(rt("pointHex",h)));return S.assertValidity(),S}static fromPrivateKey(h){return d.BASE.multiply(u(h))}static msm(h,S){return on(d,n,h,S)}_setWindowSize(h){A.setWindowSize(this,h)}assertValidity(){l(this)}hasEvenY(){let{y:h}=this.toAffine();if(r.isOdd)return!r.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){f(h);let{px:S,py:C,pz:x}=this,{px:_,py:P,pz:k}=h,N=r.eql(r.mul(S,k),r.mul(_,x)),w=r.eql(r.mul(C,k),r.mul(P,x));return N&&w}negate(){return new d(this.px,r.neg(this.py),this.pz)}double(){let{a:h,b:S}=t,C=r.mul(S,da),{px:x,py:_,pz:P}=this,k=r.ZERO,N=r.ZERO,w=r.ZERO,b=r.mul(x,x),F=r.mul(_,_),L=r.mul(P,P),U=r.mul(x,_);return U=r.add(U,U),w=r.mul(x,P),w=r.add(w,w),k=r.mul(h,w),N=r.mul(C,L),N=r.add(k,N),k=r.sub(F,N),N=r.add(F,N),N=r.mul(k,N),k=r.mul(U,k),w=r.mul(C,w),L=r.mul(h,L),U=r.sub(b,L),U=r.mul(h,U),U=r.add(U,w),w=r.add(b,b),b=r.add(w,b),b=r.add(b,L),b=r.mul(b,U),N=r.add(N,b),L=r.mul(_,P),L=r.add(L,L),b=r.mul(L,U),k=r.sub(k,b),w=r.mul(L,F),w=r.add(w,w),w=r.add(w,w),new d(k,N,w)}add(h){f(h);let{px:S,py:C,pz:x}=this,{px:_,py:P,pz:k}=h,N=r.ZERO,w=r.ZERO,b=r.ZERO,F=t.a,L=r.mul(t.b,da),U=r.mul(S,_),V=r.mul(C,P),v=r.mul(x,k),B=r.add(S,C),g=r.add(_,P);B=r.mul(B,g),g=r.add(U,V),B=r.sub(B,g),g=r.add(S,x);let p=r.add(_,k);return g=r.mul(g,p),p=r.add(U,v),g=r.sub(g,p),p=r.add(C,x),N=r.add(P,k),p=r.mul(p,N),N=r.add(V,v),p=r.sub(p,N),b=r.mul(F,g),N=r.mul(L,v),b=r.add(N,b),N=r.sub(V,b),b=r.add(V,b),w=r.mul(N,b),V=r.add(U,U),V=r.add(V,U),v=r.mul(F,v),g=r.mul(L,g),V=r.add(V,v),v=r.sub(U,v),v=r.mul(F,v),g=r.add(g,v),U=r.mul(V,g),w=r.add(w,U),U=r.mul(p,g),N=r.mul(B,N),N=r.sub(N,U),U=r.mul(B,V),b=r.mul(p,b),b=r.add(b,U),new d(N,w,b)}subtract(h){return this.add(h.negate())}is0(){return this.equals(d.ZERO)}wNAF(h){return A.wNAFCached(this,h,d.normalizeZ)}multiplyUnsafe(h){let{endo:S,n:C}=t;At("scalar",h,ie,C);let x=d.ZERO;if(h===ie)return x;if(this.is0()||h===ut)return this;if(!S||A.hasPrecomputes(this))return A.wNAFCachedUnsafe(this,h,d.normalizeZ);let{k1neg:_,k1:P,k2neg:k,k2:N}=S.splitScalar(h),w=x,b=x,F=this;for(;P>ie||N>ie;)P&ut&&(w=w.add(F)),N&ut&&(b=b.add(F)),F=F.double(),P>>=ut,N>>=ut;return _&&(w=w.negate()),k&&(b=b.negate()),b=new d(r.mul(b.px,S.beta),b.py,b.pz),w.add(b)}multiply(h){let{endo:S,n:C}=t;At("scalar",h,ut,C);let x,_;if(S){let{k1neg:P,k1:k,k2neg:N,k2:w}=S.splitScalar(h),{p:b,f:F}=this.wNAF(k),{p:L,f:U}=this.wNAF(w);b=A.constTimeNegate(P,b),L=A.constTimeNegate(N,L),L=new d(r.mul(L.px,S.beta),L.py,L.pz),x=b.add(L),_=F.add(U)}else{let{p:P,f:k}=this.wNAF(h);x=P,_=k}return d.normalizeZ([x,_])[0]}multiplyAndAddUnsafe(h,S,C){let x=d.BASE,_=(k,N)=>N===ie||N===ut||!k.equals(x)?k.multiplyUnsafe(N):k.multiply(N),P=_(this,S).add(_(h,C));return P.is0()?void 0:P}toAffine(h){return c(this,h)}isTorsionFree(){let{h,isTorsionFree:S}=t;if(h===ut)return!0;if(S)return S(d,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:S}=t;return h===ut?this:S?S(d,this):this.multiplyUnsafe(t.h)}toRawBytes(h=!0){return Ot("isCompressed",h),this.assertValidity(),o(d,this,h)}toHex(h=!0){return Ot("isCompressed",h),ee(this.toRawBytes(h))}}d.BASE=new d(t.Gx,t.Gy,r.ONE),d.ZERO=new d(r.ZERO,r.ONE,r.ZERO);let T=t.nBitLength,A=nn(d,t.endo?Math.ceil(T/2):T);return{CURVE:t,ProjectivePoint:d,normPrivateKeyToScalar:u,weierstrassEquation:s,isWithinCurveOrder:a}}function md(e){let t=br(e);return Zt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function ha(e){let t=md(e),{Fp:r,n}=t,o=r.BYTES+1,i=2*r.BYTES+1;function s(v){return W(v,n)}function a(v){return en(v,n)}let{ProjectivePoint:u,normPrivateKeyToScalar:f,weierstrassEquation:c,isWithinCurveOrder:l}=pd({...t,toBytes(v,B,g){let p=B.toAffine(),E=r.toBytes(p.x),R=ne;return Ot("isCompressed",g),g?R(Uint8Array.from([B.hasEvenY()?2:3]),E):R(Uint8Array.from([4]),E,r.toBytes(p.y))},fromBytes(v){let B=v.length,g=v[0],p=v.subarray(1);if(B===o&&(g===2||g===3)){let E=re(p);if(!xr(E,ut,r.ORDER))throw new Error("Point is not on curve");let R=c(E),O;try{O=r.sqrt(R)}catch($){let q=$ instanceof Error?": "+$.message:"";throw new Error("Point is not on curve"+q)}let M=(O&ut)===ut;return(g&1)===1!==M&&(O=r.neg(O)),{x:E,y:O}}else if(B===i&&g===4){let E=r.fromBytes(p.subarray(0,r.BYTES)),R=r.fromBytes(p.subarray(r.BYTES,2*r.BYTES));return{x:E,y:R}}else{let E=o,R=i;throw new Error("invalid Point, expected length of "+E+", or uncompressed "+R+", got "+B)}}}),d=v=>ee(xe(v,t.nByteLength));function T(v){let B=n>>ut;return v>B}function A(v){return T(v)?s(-v):v}let y=(v,B,g)=>re(v.slice(B,g));class h{constructor(B,g,p){this.r=B,this.s=g,this.recovery=p,this.assertValidity()}static fromCompact(B){let g=t.nByteLength;return B=rt("compactSignature",B,g*2),new h(y(B,0,g),y(B,g,2*g))}static fromDER(B){let{r:g,s:p}=oe.toSig(rt("DER",B));return new h(g,p)}assertValidity(){At("r",this.r,ut,n),At("s",this.s,ut,n)}addRecoveryBit(B){return new h(this.r,this.s,B)}recoverPublicKey(B){let{r:g,s:p,recovery:E}=this,R=k(rt("msgHash",B));if(E==null||![0,1,2,3].includes(E))throw new Error("recovery id invalid");let O=E===2||E===3?g+t.n:g;if(O>=r.ORDER)throw new Error("recovery id 2 or 3 invalid");let M=(E&1)===0?"02":"03",z=u.fromHex(M+d(O)),$=a(O),q=s(-R*$),G=s(p*$),X=u.BASE.multiplyAndAddUnsafe(z,q,G);if(!X)throw new Error("point at infinify");return X.assertValidity(),X}hasHighS(){return T(this.s)}normalizeS(){return this.hasHighS()?new h(this.r,s(-this.s),this.recovery):this}toDERRawBytes(){return Le(this.toDERHex())}toDERHex(){return oe.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Le(this.toCompactHex())}toCompactHex(){return d(this.r)+d(this.s)}}let S={isValidPrivateKey(v){try{return f(v),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{let v=To(t.n);return bs(t.randomBytes(v),t.n)},precompute(v=8,B=u.BASE){return B._setWindowSize(v),B.multiply(BigInt(3)),B}};function C(v,B=!0){return u.fromPrivateKey(v).toRawBytes(B)}function x(v){let B=ge(v),g=typeof v=="string",p=(B||g)&&v.length;return B?p===o||p===i:g?p===2*o||p===2*i:v instanceof u}function _(v,B,g=!0){if(x(v))throw new Error("first arg must be private key");if(!x(B))throw new Error("second arg must be public key");return u.fromHex(B).multiply(f(v)).toRawBytes(g)}let P=t.bits2int||function(v){if(v.length>8192)throw new Error("input is too large");let B=re(v),g=v.length*8-t.nBitLength;return g>0?B>>BigInt(g):B},k=t.bits2int_modN||function(v){return s(P(v))},N=wr(t.nBitLength);function w(v){return At("num < 2^"+t.nBitLength,v,ie,N),xe(v,t.nByteLength)}function b(v,B,g=F){if(["recovered","canonical"].some(ct=>ct in g))throw new Error("sign() legacy options not supported");let{hash:p,randomBytes:E}=t,{lowS:R,prehash:O,extraEntropy:M}=g;R==null&&(R=!0),v=rt("msgHash",v),la(g),O&&(v=rt("prehashed msgHash",p(v)));let z=k(v),$=f(B),q=[w($),w(z)];if(M!=null&&M!==!1){let ct=M===!0?E(r.BYTES):M;q.push(rt("extraEntropy",ct))}let G=ne(...q),X=z;function at(ct){let lt=P(ct);if(!l(lt))return;let pt=a(lt),Et=u.BASE.multiply(lt).toAffine(),yt=s(Et.x);if(yt===ie)return;let $t=s(pt*s(X+yt*$));if($t===ie)return;let Xt=(Et.x===yt?0:2)|Number(Et.y&ut),dr=$t;return R&&T($t)&&(dr=A($t),Xt^=1),new h(yt,dr,Xt)}return{seed:G,k2sig:at}}let F={lowS:t.lowS,prehash:!1},L={lowS:t.lowS,prehash:!1};function U(v,B,g=F){let{seed:p,k2sig:E}=b(v,B,g),R=t;return So(R.hash.outputLen,R.nByteLength,R.hmac)(p,E)}u.BASE._setWindowSize(8);function V(v,B,g,p=L){let E=v;B=rt("msgHash",B),g=rt("publicKey",g);let{lowS:R,prehash:O,format:M}=p;if(la(p),"strict"in p)throw new Error("options.strict was renamed to lowS");if(M!==void 0&&M!=="compact"&&M!=="der")throw new Error("format must be compact or der");let z=typeof E=="string"||ge(E),$=!z&&!M&&typeof E=="object"&&E!==null&&typeof E.r=="bigint"&&typeof E.s=="bigint";if(!z&&!$)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let q,G;try{if($&&(q=new h(E.r,E.s)),z){try{M!=="compact"&&(q=h.fromDER(E))}catch(Xt){if(!(Xt instanceof oe.Err))throw Xt}!q&&M!=="der"&&(q=h.fromCompact(E))}G=u.fromHex(g)}catch{return!1}if(!q||R&&q.hasHighS())return!1;O&&(B=t.hash(B));let{r:X,s:at}=q,ct=k(B),lt=a(at),pt=s(ct*lt),Et=s(X*lt),yt=u.BASE.multiplyAndAddUnsafe(G,pt,Et)?.toAffine();return yt?s(yt.x)===X:!1}return{CURVE:t,getPublicKey:C,getSharedSecret:_,sign:U,verify:V,ProjectivePoint:u,Signature:h,utils:S}}function gd(e){return{hash:e,hmac:(t,...r)=>di(e,t,mo(...r)),randomBytes:Xr}}function pa(e,t){let r=n=>ha({...e,...gd(n)});return{...r(t),create:r}}var ya=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),ma=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),yd=BigInt(1),pi=BigInt(2),ga=(e,t)=>(e+t/pi)/t;function xd(e){let t=ya,r=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),u=BigInt(88),f=e*e*e%t,c=f*f*e%t,l=tt(c,r,t)*c%t,d=tt(l,r,t)*c%t,T=tt(d,pi,t)*f%t,A=tt(T,o,t)*T%t,y=tt(A,i,t)*A%t,h=tt(y,a,t)*y%t,S=tt(h,u,t)*h%t,C=tt(S,a,t)*y%t,x=tt(C,r,t)*c%t,_=tt(x,s,t)*A%t,P=tt(_,n,t)*f%t,k=tt(P,pi,t);if(!mi.eql(mi.sqr(k),e))throw new Error("Cannot find square root");return k}var mi=we(ya,void 0,void 0,{sqrt:xd}),Me=pa({a:BigInt(0),b:BigInt(7),Fp:mi,n:ma,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{let t=ma,r=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-yd*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=r,s=BigInt("0x100000000000000000000000000000000"),a=ga(i*e,t),u=ga(-n*e,t),f=W(e-a*r-u*o,t),c=W(-a*n-u*i,t),l=f>s,d=c>s;if(l&&(f=t-f),d&&(c=t-c),f>s||c>s)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:l,k1:f,k2neg:d,k2:c}}}},nr),dg=BigInt(0);var hg=Me.ProjectivePoint;function xa(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}function wa(e,t,r){let n=Sr.digest(r instanceof Uint8Array?r:r.subarray());if(xa(n))return n.then(({digest:o})=>Me.verify(t,o,e)).catch(o=>{throw new Ir(String(o))});try{return Me.verify(t,n.digest,e)}catch(o){throw new Ir(String(o))}}var xn=class{type="secp256k1";raw;_key;constructor(t){this._key=Ea(t),this.raw=ba(this._key)}toMultihash(){return Qt.digest(er(this))}toCID(){return J.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ot(this.raw,t.raw)}verify(t,r){return wa(this._key,r,t)}};function gi(e){return new xn(e)}function ba(e){return Me.ProjectivePoint.fromHex(e).toRawBytes(!0)}function Ea(e){try{return Me.ProjectivePoint.fromHex(e),e}catch(t){throw new He(String(t))}}function Sa(e,t){let{Type:r,Data:n}=Gt.decode(e),o=n??new Uint8Array;switch(r){case st.RSA:return li(o,t);case st.Ed25519:return Lo(o);case st.secp256k1:return gi(o);default:throw new $e}}function wn(e){let{Type:t,Data:r}=Gt.decode(e.digest),n=r??new Uint8Array;switch(t){case st.Ed25519:return Lo(n);case st.secp256k1:return gi(n);default:throw new $e}}function er(e){return Gt.encode({Type:st[e.type],Data:e.raw})}var se="/",Aa=new TextEncoder().encode(se),bn=Aa[0],Rr=class e{_buf;constructor(t,r){if(typeof t=="string")this._buf=Y(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]!==bn)throw new Error("Invalid key")}toString(t="utf8"){return et(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=Aa),this._buf[0]!==bn){let t=new Uint8Array(this._buf.byteLength+1);t.fill(bn,0,1),t.set(this._buf,1),this._buf=t}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===bn;)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 wd(this.baseNamespace())}name(){return bd(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(),...Ed(t.map(r=>r.namespaces()))])}};function wd(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 Ed(e){return[].concat(...e)}var Pc=qr(En(),1);var Sn=class extends Error{static name="SignatureCreationError";constructor(t="Record signature creation failed"){super(t),this.name="SignatureCreationError"}},qt=class extends Error{static name="SignatureVerificationError";constructor(t="Record signature verification failed"){super(t),this.name="SignatureVerificationError"}},An=class extends Error{static name="RecordExpiredError";constructor(t="Record has expired"){super(t),this.name="RecordExpiredError"}},Ke=class extends Error{static name="UnsupportedValidityError";constructor(t="The validity type is unsupported"){super(t),this.name="UnsupportedValidityError"}},vn=class extends Error{static name="RecordTooLargeError";constructor(t="The record is too large"){super(t),this.name="RecordTooLargeError"}},_r=class extends Error{static name="InvalidValueError";constructor(t="Value must be a valid content path starting with /"){super(t),this.name="InvalidValueError"}},Bn=class extends Error{static name="InvalidRecordDataError";constructor(t="Invalid record data"){super(t),this.name="InvalidRecordDataError"}},Nr=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=()=>Br(r)}(t=e.ValidityType||(e.ValidityType={}));let n;e.codec=()=>(n==null&&(n=ve((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 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=>Ae(o,e.codec()),e.decode=(o,i)=>Se(o,e.codec(),i)})(dt||(dt={}));var Sd=["string","number","bigint","symbol"],Ad=["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 va(e){if(e===null)return"null";if(e===void 0)return"undefined";if(e===!0||e===!1)return"boolean";let t=typeof e;if(Sd.includes(t))return t;if(t==="function")return"Function";if(Array.isArray(e))return"Array";if(vd(e))return"Buffer";let r=Bd(e);return r||"Object"}function vd(e){return e&&e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer.call(null,e)}function Bd(e){let t=Object.prototype.toString.call(e).slice(8,-1);if(Ad.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 D=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",Td=new TextDecoder,Id=new TextEncoder;function Tn(e){return ir&&globalThis.Buffer.isBuffer(e)}function xi(e){return e instanceof Uint8Array?Tn(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e:Uint8Array.from(e)}var Ca=ir?(e,t,r)=>r-t>64?globalThis.Buffer.from(e.subarray(t,r)).toString("utf8"):Ta(e,t,r):(e,t,r)=>r-t>64?Td.decode(e.subarray(t,r)):Ta(e,t,r),Ua=ir?e=>e.length>64?globalThis.Buffer.from(e):Ba(e):e=>e.length>64?Id.encode(e):Ba(e),Yt=e=>Uint8Array.from(e),sr=ir?(e,t,r)=>Tn(e)?new Uint8Array(e.subarray(t,r)):e.slice(t,r):(e,t,r)=>e.slice(t,r),Ra=ir?(e,t)=>(e=e.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),xi(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},_a=ir?e=>globalThis.Buffer.allocUnsafe(e):e=>new Uint8Array(e);function Na(e,t){if(Tn(e)&&Tn(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 Ba(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 Ta(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,f,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],f=e[t+3],(a&192)===128&&(u&192)===128&&(f&192)===128&&(c=(o&15)<<18|(a&63)<<12|(u&63)<<6|f&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 Cd(n)}var Ia=4096;function Cd(e){let t=e.length;if(t<=Ia)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=Ia));return r}var Ud=256,Lr=class{constructor(t=Ud){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=_a(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=Ra(this.chunks,this.cursor);return t&&this.reset(),r}};var K="CBOR decode error:",wi="CBOR encode error:",Dr=[];Dr[23]=1;Dr[24]=2;Dr[25]=3;Dr[26]=5;Dr[27]=9;function ae(e,t,r){if(e.length-t<r)throw new Error(`${K} not enough data for type`)}var ft=[24,256,65536,4294967296,BigInt("18446744073709551616")];function It(e,t,r){ae(e,t,1);let n=e[t];if(r.strict===!0&&n<ft[0])throw new Error(`${K} integer encoded in more bytes than necessary (strict decode)`);return n}function Ct(e,t,r){ae(e,t,2);let n=e[t]<<8|e[t+1];if(r.strict===!0&&n<ft[1])throw new Error(`${K} integer encoded in more bytes than necessary (strict decode)`);return n}function Ut(e,t,r){ae(e,t,4);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];if(r.strict===!0&&n<ft[2])throw new Error(`${K} integer encoded in more bytes than necessary (strict decode)`);return n}function Rt(e,t,r){ae(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<ft[3])throw new Error(`${K} 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(`${K} integers outside of the safe integer range are not supported`)}function La(e,t,r,n){return new D(m.uint,It(e,t+1,n),2)}function Da(e,t,r,n){return new D(m.uint,Ct(e,t+1,n),3)}function ka(e,t,r,n){return new D(m.uint,Ut(e,t+1,n),5)}function Pa(e,t,r,n){return new D(m.uint,Rt(e,t+1,n),9)}function Lt(e,t){return ht(e,0,t.value)}function ht(e,t,r){if(r<ft[0]){let n=Number(r);e.push([t|n])}else if(r<ft[1]){let n=Number(r);e.push([t|24,n])}else if(r<ft[2]){let n=Number(r);e.push([t|25,n>>>8,n&255])}else if(r<ft[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<ft[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(`${K} encountered BigInt larger than allowable range`)}}Lt.encodedSize=function(t){return ht.encodedSize(t.value)};ht.encodedSize=function(t){return t<ft[0]?1:t<ft[1]?2:t<ft[2]?3:t<ft[3]?5:9};Lt.compareTokens=function(t,r){return t.value<r.value?-1:t.value>r.value?1:0};function Fa(e,t,r,n){return new D(m.negint,-1-It(e,t+1,n),2)}function Oa(e,t,r,n){return new D(m.negint,-1-Ct(e,t+1,n),3)}function Ma(e,t,r,n){return new D(m.negint,-1-Ut(e,t+1,n),5)}var bi=BigInt(-1),Ka=BigInt(1);function Va(e,t,r,n){let o=Rt(e,t+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new D(m.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${K} integers outside of the safe integer range are not supported`);return new D(m.negint,bi-BigInt(o),9)}function In(e,t){let r=t.value,n=typeof r=="bigint"?r*bi-Ka:r*-1-1;ht(e,t.type.majorEncoded,n)}In.encodedSize=function(t){let r=t.value,n=typeof r=="bigint"?r*bi-Ka:r*-1-1;return n<ft[0]?1:n<ft[1]?2:n<ft[2]?3:n<ft[3]?5:9};In.compareTokens=function(t,r){return t.value<r.value?1:t.value>r.value?-1:0};function kr(e,t,r,n){ae(e,t,r+n);let o=sr(e,t+r,t+r+n);return new D(m.bytes,o,r+n)}function qa(e,t,r,n){return kr(e,t,1,r)}function Ha(e,t,r,n){return kr(e,t,2,It(e,t+1,n))}function za(e,t,r,n){return kr(e,t,3,Ct(e,t+1,n))}function $a(e,t,r,n){return kr(e,t,5,Ut(e,t+1,n))}function Za(e,t,r,n){let o=Rt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${K} 64-bit integer bytes lengths not supported`);return kr(e,t,9,o)}function Cn(e){return e.encodedBytes===void 0&&(e.encodedBytes=e.type===m.string?Ua(e.value):e.value),e.encodedBytes}function ar(e,t){let r=Cn(t);ht(e,t.type.majorEncoded,r.length),e.push(r)}ar.encodedSize=function(t){let r=Cn(t);return ht.encodedSize(r.length)+r.length};ar.compareTokens=function(t,r){return _d(Cn(t),Cn(r))};function _d(e,t){return e.length<t.length?-1:e.length>t.length?1:Na(e,t)}function Pr(e,t,r,n,o){let i=r+n;ae(e,t,i);let s=new D(m.string,Ca(e,t+r,t+i),i);return o.retainStringBytes===!0&&(s.byteValue=sr(e,t+r,t+i)),s}function Ga(e,t,r,n){return Pr(e,t,1,r,n)}function Ya(e,t,r,n){return Pr(e,t,2,It(e,t+1,n),n)}function Wa(e,t,r,n){return Pr(e,t,3,Ct(e,t+1,n),n)}function Xa(e,t,r,n){return Pr(e,t,5,Ut(e,t+1,n),n)}function ja(e,t,r,n){let o=Rt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${K} 64-bit integer string lengths not supported`);return Pr(e,t,9,o,n)}var Ja=ar;function cr(e,t,r,n){return new D(m.array,n,r)}function Qa(e,t,r,n){return cr(e,t,1,r)}function tc(e,t,r,n){return cr(e,t,2,It(e,t+1,n))}function ec(e,t,r,n){return cr(e,t,3,Ct(e,t+1,n))}function rc(e,t,r,n){return cr(e,t,5,Ut(e,t+1,n))}function nc(e,t,r,n){let o=Rt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${K} 64-bit integer array lengths not supported`);return cr(e,t,9,o)}function oc(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${K} indefinite length items not allowed`);return cr(e,t,1,1/0)}function Un(e,t){ht(e,m.array.majorEncoded,t.value)}Un.compareTokens=Lt.compareTokens;Un.encodedSize=function(t){return ht.encodedSize(t.value)};function ur(e,t,r,n){return new D(m.map,n,r)}function ic(e,t,r,n){return ur(e,t,1,r)}function sc(e,t,r,n){return ur(e,t,2,It(e,t+1,n))}function ac(e,t,r,n){return ur(e,t,3,Ct(e,t+1,n))}function cc(e,t,r,n){return ur(e,t,5,Ut(e,t+1,n))}function uc(e,t,r,n){let o=Rt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${K} 64-bit integer map lengths not supported`);return ur(e,t,9,o)}function fc(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${K} indefinite length items not allowed`);return ur(e,t,1,1/0)}function Rn(e,t){ht(e,m.map.majorEncoded,t.value)}Rn.compareTokens=Lt.compareTokens;Rn.encodedSize=function(t){return ht.encodedSize(t.value)};function lc(e,t,r,n){return new D(m.tag,r,1)}function dc(e,t,r,n){return new D(m.tag,It(e,t+1,n),2)}function hc(e,t,r,n){return new D(m.tag,Ct(e,t+1,n),3)}function pc(e,t,r,n){return new D(m.tag,Ut(e,t+1,n),5)}function mc(e,t,r,n){return new D(m.tag,Rt(e,t+1,n),9)}function _n(e,t){ht(e,m.tag.majorEncoded,t.value)}_n.compareTokens=Lt.compareTokens;_n.encodedSize=function(t){return ht.encodedSize(t.value)};var Fd=20,Od=21,Md=22,Kd=23;function gc(e,t,r,n){if(n.allowUndefined===!1)throw new Error(`${K} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new D(m.null,null,1):new D(m.undefined,void 0,1)}function yc(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${K} indefinite length items not allowed`);return new D(m.break,void 0,1)}function Ei(e,t,r){if(r){if(r.allowNaN===!1&&Number.isNaN(e))throw new Error(`${K} NaN values are not supported`);if(r.allowInfinity===!1&&(e===1/0||e===-1/0))throw new Error(`${K} Infinity values are not supported`)}return new D(m.float,e,t)}function xc(e,t,r,n){return Ei(Si(e,t+1),3,n)}function wc(e,t,r,n){return Ei(Ai(e,t+1),5,n)}function bc(e,t,r,n){return Ei(vc(e,t+1),9,n)}function Nn(e,t,r){let n=t.value;if(n===!1)e.push([m.float.majorEncoded|Fd]);else if(n===!0)e.push([m.float.majorEncoded|Od]);else if(n===null)e.push([m.float.majorEncoded|Md]);else if(n===void 0)e.push([m.float.majorEncoded|Kd]);else{let o,i=!1;(!r||r.float64!==!0)&&(Sc(n),o=Si(Ht,1),n===o||Number.isNaN(n)?(Ht[0]=249,e.push(Ht.slice(0,3)),i=!0):(Ac(n),o=Ai(Ht,1),n===o&&(Ht[0]=250,e.push(Ht.slice(0,5)),i=!0))),i||(Vd(n),o=vc(Ht,1),Ht[0]=251,e.push(Ht.slice(0,9)))}}Nn.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){Sc(n);let o=Si(Ht,1);if(n===o||Number.isNaN(n))return 3;if(Ac(n),o=Ai(Ht,1),n===o)return 5}return 9};var Ec=new ArrayBuffer(9),Dt=new DataView(Ec,1),Ht=new Uint8Array(Ec,0);function Sc(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 Si(e,t){if(e.length-t<2)throw new Error(`${K} 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 Ac(e){Dt.setFloat32(0,e,!1)}function Ai(e,t){if(e.length-t<4)throw new Error(`${K} not enough data for float32`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,4).getFloat32(0,!1)}function Vd(e){Dt.setFloat64(0,e,!1)}function vc(e,t){if(e.length-t<8)throw new Error(`${K} not enough data for float64`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,8).getFloat64(0,!1)}Nn.compareTokens=Lt.compareTokens;function Z(e,t,r){throw new Error(`${K} encountered invalid minor (${r}) for major ${e[t]>>>5}`)}function Ln(e){return()=>{throw new Error(`${K} ${e}`)}}var I=[];for(let e=0;e<=23;e++)I[e]=Z;I[24]=La;I[25]=Da;I[26]=ka;I[27]=Pa;I[28]=Z;I[29]=Z;I[30]=Z;I[31]=Z;for(let e=32;e<=55;e++)I[e]=Z;I[56]=Fa;I[57]=Oa;I[58]=Ma;I[59]=Va;I[60]=Z;I[61]=Z;I[62]=Z;I[63]=Z;for(let e=64;e<=87;e++)I[e]=qa;I[88]=Ha;I[89]=za;I[90]=$a;I[91]=Za;I[92]=Z;I[93]=Z;I[94]=Z;I[95]=Ln("indefinite length bytes/strings are not supported");for(let e=96;e<=119;e++)I[e]=Ga;I[120]=Ya;I[121]=Wa;I[122]=Xa;I[123]=ja;I[124]=Z;I[125]=Z;I[126]=Z;I[127]=Ln("indefinite length bytes/strings are not supported");for(let e=128;e<=151;e++)I[e]=Qa;I[152]=tc;I[153]=ec;I[154]=rc;I[155]=nc;I[156]=Z;I[157]=Z;I[158]=Z;I[159]=oc;for(let e=160;e<=183;e++)I[e]=ic;I[184]=sc;I[185]=ac;I[186]=cc;I[187]=uc;I[188]=Z;I[189]=Z;I[190]=Z;I[191]=fc;for(let e=192;e<=215;e++)I[e]=lc;I[216]=dc;I[217]=hc;I[218]=pc;I[219]=mc;I[220]=Z;I[221]=Z;I[222]=Z;I[223]=Z;for(let e=224;e<=243;e++)I[e]=Ln("simple values are not supported");I[244]=Z;I[245]=Z;I[246]=Z;I[247]=gc;I[248]=Ln("simple values are not supported");I[249]=xc;I[250]=wc;I[251]=bc;I[252]=Z;I[253]=Z;I[254]=Z;I[255]=yc;var zt=[];for(let e=0;e<24;e++)zt[e]=new D(m.uint,e,1);for(let e=-1;e>=-24;e--)zt[31-e]=new D(m.negint,e,1);zt[64]=new D(m.bytes,new Uint8Array(0),1);zt[96]=new D(m.string,"",1);zt[128]=new D(m.array,0,1);zt[160]=new D(m.map,0,1);zt[244]=new D(m.false,!1,1);zt[245]=new D(m.true,!0,1);zt[246]=new D(m.null,null,1);function Bc(e){switch(e.type){case m.false:return Yt([244]);case m.true:return Yt([245]);case m.null:return Yt([246]);case m.bytes:return e.value.length?void 0:Yt([64]);case m.string:return e.value===""?Yt([96]):void 0;case m.array:return e.value===0?Yt([128]):void 0;case m.map:return e.value===0?Yt([160]):void 0;case m.uint:return e.value<24?Yt([Number(e.value)]):void 0;case m.negint:if(e.value>=-24)return Yt([31-Number(e.value)])}}var Hd={float64:!1,mapSorter:Zd,quickEncodeToken:Bc};function zd(){let e=[];return e[m.uint.major]=Lt,e[m.negint.major]=In,e[m.bytes.major]=ar,e[m.string.major]=Ja,e[m.array.major]=Un,e[m.map.major]=Rn,e[m.tag.major]=_n,e[m.float.major]=Nn,e}var Tc=zd(),vi=new Lr,kn=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(`${wi} object contains circular references`);return new e(r,t)}},Ue={null:new D(m.null,null),undefined:new D(m.undefined,void 0),true:new D(m.true,!0),false:new D(m.false,!1),emptyArray:new D(m.array,0),emptyMap:new D(m.map,0)},Re={number(e,t,r,n){return!Number.isInteger(e)||!Number.isSafeInteger(e)?new D(m.float,e):e>=0?new D(m.uint,e):new D(m.negint,e)},bigint(e,t,r,n){return e>=BigInt(0)?new D(m.uint,e):new D(m.negint,e)},Uint8Array(e,t,r,n){return new D(m.bytes,e)},string(e,t,r,n){return new D(m.string,e)},boolean(e,t,r,n){return e?Ue.true:Ue.false},null(e,t,r,n){return Ue.null},undefined(e,t,r,n){return Ue.undefined},ArrayBuffer(e,t,r,n){return new D(m.bytes,new Uint8Array(e))},DataView(e,t,r,n){return new D(m.bytes,new Uint8Array(e.buffer,e.byteOffset,e.byteLength))},Array(e,t,r,n){if(!e.length)return r.addBreakTokens===!0?[Ue.emptyArray,new D(m.break)]:Ue.emptyArray;n=kn.createCheck(n,e);let o=[],i=0;for(let s of e)o[i++]=Dn(s,r,n);return r.addBreakTokens?[new D(m.array,e.length),o,new D(m.break)]:[new D(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?[Ue.emptyMap,new D(m.break)]:Ue.emptyMap;n=kn.createCheck(n,e);let a=[],u=0;for(let f of i)a[u++]=[Dn(f,r,n),Dn(o?e.get(f):e[f],r,n)];return $d(a,r),r.addBreakTokens?[new D(m.map,s),a,new D(m.break)]:[new D(m.map,s),a]}};Re.Map=Re.Object;Re.Buffer=Re.Uint8Array;for(let e of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))Re[`${e}Array`]=Re.DataView;function Dn(e,t={},r){let n=va(e),o=t&&t.typeEncoders&&t.typeEncoders[n]||Re[n];if(typeof o=="function"){let s=o(e,n,t,r);if(s!=null)return s}let i=Re[n];if(!i)throw new Error(`${wi} unsupported type: ${n}`);return i(e,n,t,r)}function $d(e,t){t.mapSorter&&e.sort(t.mapSorter)}function Zd(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=Tc[o].compareTokens(r,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function Ic(e,t,r,n){if(Array.isArray(t))for(let o of t)Ic(e,o,r,n);else r[t.type.major](e,t,n)}function Gd(e,t,r){let n=Dn(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 Lr(s);if(i(a,n,r),a.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return xi(a.chunks[0])}}return vi.reset(),Ic(vi,n,t,r),vi.toBytes(!0)}function Bi(e,t){return t=Object.assign({},Hd,t),Gd(e,Tc,t)}var Yd={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},Pn=class{constructor(t,r={}){this._pos=0,this.data=t,this.options=r}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let t=this.data[this._pos],r=zt[t];if(r===void 0){let n=I[t];if(!n)throw new Error(`${K} 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}},Fr=Symbol.for("DONE"),Fn=Symbol.for("BREAK");function Wd(e,t,r){let n=[];for(let o=0;o<e.value;o++){let i=fr(t,r);if(i===Fn){if(e.value===1/0)break;throw new Error(`${K} got unexpected break to lengthed array`)}if(i===Fr)throw new Error(`${K} found array but not enough entries (got ${o}, expected ${e.value})`);n[o]=i}return n}function Xd(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===Fn){if(e.value===1/0)break;throw new Error(`${K} got unexpected break to lengthed map`)}if(a===Fr)throw new Error(`${K} found map but not enough entries (got ${s} [no key], expected ${e.value})`);if(n!==!0&&typeof a!="string")throw new Error(`${K} non-string keys not supported (got ${typeof a})`);if(r.rejectDuplicateMapKeys===!0&&(n&&i.has(a)||!n&&a in o))throw new Error(`${K} found repeat map key "${a}"`);let u=fr(t,r);if(u===Fr)throw new Error(`${K} 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 Fr;let r=e.next();if(r.type===m.break)return Fn;if(r.type.terminal)return r.value;if(r.type===m.array)return Wd(r,e,t);if(r.type===m.map)return Xd(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(`${K} tag not supported (${r.value})`)}throw new Error("unsupported")}function Cc(e,t){if(!(e instanceof Uint8Array))throw new Error(`${K} data to decode must be a Uint8Array`);t=Object.assign({},Yd,t);let r=t.tokenizer||new Pn(e,t),n=fr(r,t);if(n===Fr)throw new Error(`${K} did not find any content to decode`);if(n===Fn)throw new Error(`${K} got unexpected break`);return[n,e.subarray(r.pos())]}function Ti(e,t){let[r,n]=Cc(e,t);if(n.length>0)throw new Error(`${K} too many terminals, data makes no sense`);return r}var Jd=de("ipns:utils"),Uc=Y("/ipns/"),Qd=114,th=0,eh=18;function Rc(e){let t;if(e.pubKey!=null)try{t=Sa(e.pubKey)}catch(r){throw Jd.error(r),r}if(t!=null)return t}function _c(e,t,r){let n=Y(t);return Ie([e,r,n])}function Mn(e){let t=Y("ipns-signature:");return Ie([t,e])}function Ii(e){return"signatureV1"in e?dt.encode({value:Y(e.value),signatureV1:e.signatureV1,validityType:e.validityType,validity:Y(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 Wt(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 qt("Missing data or signatureV2");let r=Dc(t.data),n=rh(r.Value),o=et(r.Validity);if(t.value!=null&&t.signatureV1!=null)return nh(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 lr(e){return Ie([Uc,e.bytes])}function Nc(e){let t=Jt(e.slice(Uc.length));if(!On(t,th)&&!On(t,eh))throw new ze("Multihash in IPNS key was not identity or sha2-256");return t}function Lc(e,t,r,n,o){let i;if(t===dt.ValidityType.EOL)i=0;else throw new Ke("The validity type is unsupported");return Bi({Value:e,Validity:r,ValidityType:i,Sequence:n,TTL:o})}function Dc(e){let t=Ti(e);if(t.ValidityType===0)t.ValidityType=dt.ValidityType.EOL;else throw new Ke("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 rh(e){let t=et(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 _r("Value must be a valid content path starting with /")}function kc(e){if(e!=null){let t=sh(e);if(t!=null)return t.code===Qd?`/ipns/${t.toString(kt)}`:`/ipfs/${t.toV1().toString()}`;if(oh(e))return`/ipns/${kt.encode(e.bytes)}`;let r=e.toString().trim();if(r.startsWith("/")&&r.length>1)return r}throw new _r("Value must be a valid content path starting with /")}function nh(e){if(e.data==null)throw new Bn("Record data is missing");let t=Dc(e.data);if(!ot(t.Value,e.value??new Uint8Array(0)))throw new qt('Field "value" did not match between protobuf and CBOR');if(!ot(t.Validity,e.validity??new Uint8Array(0)))throw new qt('Field "validity" did not match between protobuf and CBOR');if(t.ValidityType!==e.validityType)throw new qt('Field "validityType" did not match between protobuf and CBOR');if(t.Sequence!==e.sequence)throw new qt('Field "sequence" did not match between protobuf and CBOR');if(t.TTL!==e.ttl)throw new qt('Field "ttl" did not match between protobuf and CBOR')}function oh(e){return e.bytes instanceof Uint8Array}function ih(e){return typeof e?.toCID=="function"}function sh(e){if(ih(e))return e.toCID();try{return J.parse(e)}catch{}return J.asCID(e)}function On(e,t){return e.code===t}var ah=de("ipns"),Fc=60*60*1e9,ch="/ipns/",Ex=ch.length,Oc={v1Compatible:!0,ttlNs:Fc};async function Mc(e,t,r,n,o=Oc){let i=new Pc.default(Date.now()+Number(n)),s=dt.ValidityType.EOL,a=BigInt(o.ttlNs??Fc);return uh(e,t,r,s,i.toString(),a,o)}var uh=async(e,t,r,n,o,i,s=Oc)=>{r=BigInt(r);let a=Y(o),u=kc(t),f=Y(u),c=Lc(f,n,a,r,i),l=Mn(c),d=await e.sign(l),T;if(e.type==="RSA"&&(T=er(e.publicKey)),s.v1Compatible===!0){let A=await fh(e,f,n,a),y={value:u,signatureV1:A,validity:o,validityType:n,sequence:r,ttl:i,signatureV2:d,data:c};return T!=null&&(y.pubKey=T),y}else{let A={value:u,validity:o,validityType:n,sequence:r,ttl:i,signatureV2:d,data:c};return T!=null&&(A.pubKey=T),A}},fh=async(e,t,r,n)=>{try{let o=_c(t,r,n);return await e.sign(o)}catch(o){throw ah.error("record signature creation failed",o),new Sn("Record signature creation failed")}};var Ci=qr(En(),1);function Kn(e,t){let r=t.map((n,o)=>({record:Wt(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=Ci.default.fromString(n.record.validity).toDate(),u=Ci.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 Kc=qr(En(),1);var Vn=de("ipns:validator"),lh=1024*10,dh=async(e,t)=>{let r=Wt(t),n;try{let o=Mn(r.data);n=await e.verify(o,r.signatureV2)}catch{n=!1}if(!n)throw Vn.error("record signature verification failed"),new qt("Record signature verification failed");if(r.validityType===dt.ValidityType.EOL){if(Kc.default.fromString(r.validity).toDate().getTime()<Date.now())throw Vn.error("record has expired"),new An("record has expired")}else if(r.validityType!=null)throw Vn.error("the validity type is unsupported"),new Ke("The validity type is unsupported");Vn("ipns record for %s is valid",r.value)};async function qn(e,t){if(t.byteLength>lh)throw new vn("The record is too large");let r=Nc(e),n;On(r,0)&&(n=wn(r));let o=Wt(t),i=Rc(o)??n;if(i==null)throw new Nr("Could not extract public key from IPNS record or routing key");let s=lr(i.toMultihash());if(!ot(s,e))throw new Nr("Embedded public key did not match routing key");await dh(i,t)}var bt=class extends Event{type;detail;constructor(t,r){super(t),this.type=t,this.detail=r}};var Vc=Symbol.for("nodejs.util.inspect.custom"),hh=114,Or=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()})`}[to]=!0;toString(){return this.string==null&&(this.string=j.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return J.createV1(hh,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return ot(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return ot(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Vc](){return`PeerId(${this.toString()})`}},Hn=class extends Or{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},zn=class extends Or{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},$n=class extends Or{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},ph=2336,Mr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Qt.digest(Y(this.url))}[Vc](){return`PeerId(${this.url})`}[to]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return J.createV1(ph,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=et(t)),t.toString()===this.toString())}};var mh=114,qc=2336;function Hc(e,t){let r;if(e.charAt(0)==="1"||e.charAt(0)==="Q")r=Jt(j.decode(`z${e}`));else{if(t==null)throw new mt('Please pass a multibase decoder for strings that do not start with "1" or "Q"');r=Jt(t.decode(e))}return zc(r)}function zc(e){if(yh(e))return new Hn({multihash:e});if(gh(e))try{let t=wn(e);if(t.type==="Ed25519")return new zn({multihash:e,publicKey:t});if(t.type==="secp256k1")return new $n({multihash:e,publicKey:t})}catch{let r=et(e.digest);return new Mr(new URL(r))}throw new ze("Supplied PeerID Multihash is invalid")}function $c(e){if(e?.multihash==null||e.version==null||e.version===1&&e.code!==mh&&e.code!==qc)throw new Hr("Supplied PeerID CID is invalid");if(e.code===qc){let t=et(e.multihash.digest);return new Mr(new URL(t))}return zc(e.multihash)}function gh(e){return e.code===Qt.code}function yh(e){return e.code===Sr.code}var bh=qr(Gc(),1);var ce;(function(e){e[e.A=1]="A",e[e.CNAME=5]="CNAME",e[e.TXT=16]="TXT",e[e.AAAA=28]="AAAA"})(ce||(ce={}));var Zn=class extends Error{static name="DNSLinkNotFoundError";constructor(t="DNSLink not found"){super(t),this.name="DNSLinkNotFoundError"}},Gn=class extends Error{static name="RecordsFailedValidationError";constructor(t="Records failed validation"){super(t),this.name="RecordsFailedValidationError"}},Yn=class extends Error{static name="UnsupportedMultibasePrefixError";constructor(t="Unsupported multibase prefix"){super(t),this.name="UnsupportedMultibasePrefixError"}},Wn=class extends Error{static name="UnsupportedMultihashCodecError";constructor(t="Unsupported multihash codec"){super(t),this.name="UnsupportedMultihashCodecError"}},Xn=class extends Error{static name="InvalidValueError";constructor(t="Invalid value"){super(t),this.name="InvalidValueError"}};var Eh=32;async function Yc(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:[ce.TXT]}))?.Answer??[]).sort((f,c)=>f.data.localeCompare(c.data));n("found %d TXT records for %s",s.length,e);for(let f of s)try{let c=f.data;if(c.startsWith('"')&&c.endsWith('"')&&(c=c.substring(1,c.length-1)),!c.startsWith("dnslink="))continue;n("%s TXT %s",f.name,c),c=c.replace("dnslink=","");let[,l,d,...T]=c.split("/");if(l==="ipfs")try{return{value:`/ipfs/${J.parse(d)}${T.length>0?`/${T.join("/")}`:""}`,answer:f}}catch{}else if(l==="ipns"){try{let A;return d.charAt(0)==="1"||d.charAt(0)==="Q"?A=Hc(d):A=$c(J.parse(d)),{value:`/ipns/${A}${T.length>0?`/${T.join("/")}`:""}`,answer:f}}catch{}return await jn(d,t-1,r,n,o)}else{if(l==="dnslink")return await jn(d,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,f.data,c)}n("no DNSLink records found for %s, falling back to CNAME",e);let u=((await r.query(e,{...o,types:[ce.CNAME]}))?.Answer??[]).sort((f,c)=>f.data.localeCompare(c.data));n("found %d CNAME records for %s",u.length,e);for(let f of u)try{return await jn(f.data,t-1,r,n,o)}catch(c){n.error("domain %s cname %s had no DNSLink records",e,f.data,c)}throw new Zn(`No DNSLink records found for domain: ${e}`)}async function jn(e,t,r,n,o={}){if(t===0)throw new Error("recursion limit exceeded");e.startsWith("_dnslink.")||(e=`_dnslink.${e}`);try{return await Yc(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}`,Yc(e,t,r,n,o)}}async function Wc(e,t,r,n={}){return jn(e,n.maxRecursiveDepth??Eh,t,r,n)}var Ui=class{routing;constructor(t){this.routing=t}async put(t,r,n={}){try{await this.routing.put(t,r,n)}catch(o){n.onProgress?.(new bt("ipns:routing:helia:error",o))}}async get(t,r={}){try{return await this.routing.get(t,r)}catch(n){r.onProgress?.(new bt("ipns:routing:helia:error",n))}throw new Error("Not found")}};function Xc(e){return new Ui(e)}var Kr;(function(e){let t;e.codec=()=>(t==null&&(t=ve((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=>Ae(r,e.codec()),e.decode=(r,n)=>Se(r,e.codec(),n)})(Kr||(Kr={}));function jc(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 Jc(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),f=parseInt(r[7].slice(0,-6),10);return new Date(Date.UTC(n,o,i,s,a,u,f))}var qe=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 Kr.encode(this.prepareSerialize())}prepareSerialize(){return{key:this.key,value:this.value,timeReceived:jc(this.timeReceived)}}static deserialize(t){let r=Kr.decode(t);return new e(r.key,r.value,new Date(r.timeReceived))}static fromDeserialized(t){let r=Jc(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 Qc;(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"})(Qc||(Qc={}));function Jn(e){return new Rr("/dht/record/"+et(e,"base32"),!1)}function tu(e){return{async put(t,r,n={}){try{let o=Jn(t);try{let s=await e.get(o),a=qe.deserialize(s);if(ot(a.value,r))return}catch(s){if(s.name!=="NotFoundError")throw s}let i=new qe(t,r,new Date);n.onProgress?.(new bt("ipns:routing:datastore:put")),await e.put(o,i.serialize(),n)}catch(o){throw n.onProgress?.(new bt("ipns:routing:datastore:error",o)),o}},async get(t,r={}){try{let n=Jn(t);r.onProgress?.(new bt("ipns:routing:datastore:get"));let o=await e.get(n,r),i=qe.deserialize(o);return{record:i.value,created:i.timeReceived}}catch(n){throw r.onProgress?.(new bt("ipns:routing:datastore:error",n)),n}},async has(t,r={}){let n=Jn(t);return e.has(n,r)},async delete(t,r){let n=Jn(t);return e.delete(n,r)}}}function Ri(e,t){return e.code===t}var ue=de("helia:ipns"),nu=60*1e3,ou=60*nu,Bh=48*ou,_i=23*ou,eu=BigInt(nu)*5000000n,ru={[kt.prefix]:kt,[j.prefix]:j},Ni=class{routers;localStore;timeout;dns;log;constructor(t,r=[]){this.routers=[Xc(t.routing),...r],this.localStore=tu(t.datastore),this.dns=t.dns,this.log=t.logger.forComponent("helia:ipns")}async publish(t,r,n={}){try{let o=1n,i=lr(t.publicKey.toMultihash());if(await this.localStore.has(i,n)){let{record:f}=await this.localStore.get(i,n);o=Wt(f).sequence+1n}let s=n.ttl!=null?BigInt(n.ttl)*1000000n:eu,a=await Mc(t,r,o,n.lifetime??Bh,{...n,ttlNs:s}),u=Ii(a);return await this.localStore.put(i,u,n),n.offline!==!0&&await Promise.all(this.routers.map(async f=>{await f.put(i,u,n)})),a}catch(o){throw n.onProgress?.(new bt("ipns:publish:error",o)),o}}async resolve(t,r={}){let n=qi(t)?t.toMultihash():t,o=lr(n),i=await this.#e(o,r);return{...await this.#t(i.value,r),record:i}}async resolveDNSLink(t,r={}){let n=await Wc(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 bt("ipns:republish:start"));let i=Date.now()-n,s=_i-i;s<0&&(s=t.interval??_i),setTimeout(()=>{r().catch(a=>{ue.error("error republishing",a)})},s)}this.timeout=setTimeout(()=>{r().catch(n=>{ue.error("error republishing",n)})},t.interval??_i)}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=j.decode(`z${i}`);else if(ru[s]!=null)a=ru[s].decode(i);else throw new Yn(`Unsupported multibase prefix "${s}"`);let u;try{u=Jt(a)}catch{u=J.decode(a).multihash}if(!Ri(u,0)&&!Ri(u,18))throw new Wn(`Unsupported multihash codec "${u.code}"`);let{cid:f}=await this.resolve(u,r),c=n.slice(3).join("/");return{cid:f,path:c}}else if(o==="ipfs"){let i=J.parse(n[2]),s=n.slice(3).join("/");return{cid:i,path:s}}}catch(o){ue.error("error parsing ipfs path",o)}throw ue.error("invalid ipfs path %s",t),new Xn("Invalid value")}async#e(t,r={}){let n=[];if(await this.localStore.has(t,r))if(ue("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 qn(t,a),this.log("record was valid");let f=Wt(a),c=Number((f.ttl??eu)/1000000n);if(u.getTime()+c>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 ue("ignoring local cache due to nocache=true option");if(r.offline===!0)throw new hr("Record was not present in the cache or has expired");ue("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(f){ue.error("error finding IPNS record",f);return}try{await qn(t,u),n.push(u)}catch(f){i++,ue.error("error finding IPNS record",f)}})),n.length===0)throw i>0?new Gn(`${i>1?`${i} records`:"Record"} found for routing key ${i>1?"were":"was"} invalid`):new hr("Could not find record for routing key");let s=n[Kn(t,n)];return await this.localStore.put(t,s,r),Wt(s)}};function Th(e,{routers:t=[]}={}){return new Ni(e,t)}return xu(Ih);})();
2
+ "use strict";var HeliaIpns=(()=>{var pu=Object.create;var Hr=Object.defineProperty;var mu=Object.getOwnPropertyDescriptor;var gu=Object.getOwnPropertyNames;var yu=Object.getPrototypeOf,xu=Object.prototype.hasOwnProperty;var zi=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),wt=(e,t)=>{for(var r in t)Hr(e,r,{get:t[r],enumerable:!0})},$i=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of gu(t))!xu.call(e,o)&&o!==r&&Hr(e,o,{get:()=>t[o],enumerable:!(n=mu(t,o))||n.enumerable});return e};var zr=(e,t,r)=>(r=e!=null?pu(yu(e)):{},$i(t||!e||!e.__esModule?Hr(r,"default",{value:e,enumerable:!0}):r,e)),wu=e=>$i(Hr({},"__esModule",{value:!0}),e);var In=zi((wy,Ei)=>{var xy=function(){typeof Ei<"u"&&(Ei.exports=y);var e=86400,t=3200,r=146097*t/400,n=e*r,o=1e3*n,i=864e13,s=4294967296,a=1e6,u="000000000",f=Math.trunc||function(w){var b=w-w%1;return b==0&&(w<0||w===0&&1/w!=1/0)?-0:b},c=y.prototype,l=(y.fromDate=function(w){return new y(+w)},y.fromInt64BE=_(0,1,2,3,0,4),y.fromInt64LE=_(3,2,1,0,4,0),y.fromString=function(L){var b,F=new y,L=(L+="").replace(/^\s*[+\-]?\d+/,function(V){var V=+V,v=1970+(V-1970)%400;return F.year=V-v,v}).replace(/(?:Z|([+\-]\d{2}):?(\d{2}))$/,function(U,V,v){return V<0&&(v*=-1),b=6e4*(60*+V+ +v),""}).replace(/\.\d+$/,function(U){return F.nano=+(U+u).substr(1,9),""}).split(/\D+/);if(1<L.length?L[1]--:L[1]=0,F.time=b=Date.UTC.apply(Date,L)-(b||0),isNaN(b))throw new TypeError("Invalid Date");return h(F)},y.fromTimeT=function(w){return C(w,0)},c.year=0,c.time=0,c.nano=0,c.addNano=function(w){return this.nano+=+w||0,this},c.getNano=function(){var w=h(this);return(w.time%1e3*a+ +w.nano+1e9)%1e9},c.getTimeT=function(){var b=h(this),w=Math.floor(b.time/1e3),b=b.year;return b&&(w+=b*r*e/t),w},c.getYear=function(){return this.toDate().getUTCFullYear()+this.year},c.toDate=function(){return S(h(this).time)},c.toJSON=function(){return this.toString().replace(/0{1,6}Z$/,"Z")},c.toString=function(w){var b=this,F=b.toDate(),L={H:function(){return k(F.getUTCHours())},L:function(){return N(F.getUTCMilliseconds(),3)},M:function(){return k(F.getUTCMinutes())},N:function(){return N(b.getNano(),9)},S:function(){return k(F.getUTCSeconds())},Y:function(){var U=b.getYear();return 999999<U?"+"+U:9999<U?"+"+N(U,6):0<=U?N(U,4):-999999<=U?"-"+N(-U,6):U},a:function(){return T[F.getUTCDay()]},b:function(){return d[F.getUTCMonth()]},d:function(){return k(F.getUTCDate())},e:function(){return function(U){return(9<U?"":" ")+(0|U)}(F.getUTCDate())},m:function(){return k(F.getUTCMonth()+1)}};return function U(V){return V.replace(/%./g,function(v){var g=v[1],B=A[g],g=L[g];return B?U(B):g?g():v})}(w||l)},c.writeInt64BE=x(0,1,2,3,0,4),c.writeInt64LE=x(3,2,1,0,4,0),"%Y-%m-%dT%H:%M:%S.%NZ"),d=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],T=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],A={"%":"%",F:"%Y-%m-%d",n:`
3
+ `,R:"%H:%M",T:"%H:%M:%S",t:" ",X:"%T",Z:"GMT",z:"+0000"};return y;function y(w,b,F){var L=this;if(!(L instanceof y))return new y(w,b,F);L.time=+w||0,L.nano=+b||0,L.year=+F||0,h(L)}function h(w){var b,F,L,U=w.year,V=w.time,v=w.nano,B=((v<0||a<=v)&&(v-=(F=Math.floor(v/a))*a,V+=F,F=1),U%t);return(V<-i||i<V||B)&&((b=f(V/o))&&(U+=b*t,V-=b*o),(L=S(V)).setUTCFullYear(B+L.getUTCFullYear()),L=(V=+L)+(b=f((U-=B)/t))*o,b&&-i<=L&&L<=i&&(U-=b*t,V=L),F=1),F&&(w.year=U,w.time=V,w.nano=v),w}function S(w){var b=new Date(0);return b.setTime(w),b}function C(U,L){U=+U||0;var F=f((L=(L|0)*s)/n)+f(U/n),L=L%n+U%n,U=f(L/n);return U&&(F+=U,L-=U*n),new y(1e3*L,0,F*t)}function x(w,b,F,L,U,V){return function(B,g){var E=h(this);B=B||new Array(8),P(B,g|=0);var R=Math.floor(E.time/1e3),E=E.year*(r*e/t),p=f(E/s)+f(R/s),E=E%s+R%s,R=Math.floor(E/s);return R&&(p+=R,E-=R*s),v(B,g+U,p),v(B,g+V,E),B};function v(B,g,p){B[g+w]=p>>24&255,B[g+b]=p>>16&255,B[g+F]=p>>8&255,B[g+L]=255&p}}function _(w,b,F,L,U,V){return function(B,g){P(B,g|=0);var p=v(B,g+U);return C(v(B,g+V),p)};function v(B,g){return 16777216*B[g+w]+(B[g+b]<<16|B[g+F]<<8|B[g+L])}}function P(w,b){if(w=w&&w.length,w==null)throw new TypeError("Invalid Buffer");if(w<b+8)throw new RangeError("Out of range")}function k(w){return(9<w?"":"0")+(0|w)}function N(w,b){return(u+(0|w)).substr(-b)}}()});var Wc=zi((mw,Zc)=>{Zc.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={};wt(Ch,{ipns:()=>Ih,ipnsSelector:()=>Zn,ipnsValidator:()=>Vr});function Gi(e){return e==null?!1:(e.type==="RSA"||e.type==="Ed25519"||e.type==="secp256k1")&&e.raw instanceof Uint8Array&&typeof e.equals=="function"&&typeof e.toMultihash=="function"&&typeof e.toCID=="function"&&typeof e.verify=="function"}var no=Symbol.for("@libp2p/peer-id");var mt=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},ze=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var hr=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}};var $r=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},$e=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Ge=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var co={};wt(co,{base32:()=>le,base32hex:()=>Cu,base32hexpad:()=>Ru,base32hexpadupper:()=>_u,base32hexupper:()=>Uu,base32pad:()=>Tu,base32padupper:()=>Iu,base32upper:()=>Bu,base32z:()=>Nu});var Lh=new Uint8Array(0);function Zi(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 jt(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 Wi(e){return new TextEncoder().encode(e)}function Yi(e){return new TextDecoder().decode(e)}function bu(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),f=Math.log(a)/Math.log(256),c=Math.log(256)/Math.log(a);function l(A){if(A instanceof Uint8Array||(ArrayBuffer.isView(A)?A=new Uint8Array(A.buffer,A.byteOffset,A.byteLength):Array.isArray(A)&&(A=Uint8Array.from(A))),!(A instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(A.length===0)return"";for(var y=0,h=0,S=0,C=A.length;S!==C&&A[S]===0;)S++,y++;for(var x=(C-S)*c+1>>>0,_=new Uint8Array(x);S!==C;){for(var P=A[S],k=0,N=x-1;(P!==0||k<h)&&N!==-1;N--,k++)P+=256*_[N]>>>0,_[N]=P%a>>>0,P=P/a>>>0;if(P!==0)throw new Error("Non-zero carry");h=k,S++}for(var w=x-h;w!==x&&_[w]===0;)w++;for(var b=u.repeat(y);w<x;++w)b+=e.charAt(_[w]);return b}function d(A){if(typeof A!="string")throw new TypeError("Expected String");if(A.length===0)return new Uint8Array;var y=0;if(A[y]!==" "){for(var h=0,S=0;A[y]===u;)h++,y++;for(var C=(A.length-y)*f+1>>>0,x=new Uint8Array(C);A[y];){var _=r[A.charCodeAt(y)];if(_===255)return;for(var P=0,k=C-1;(_!==0||P<S)&&k!==-1;k--,P++)_+=a*x[k]>>>0,x[k]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");S=P,y++}if(A[y]!==" "){for(var N=C-S;N!==C&&x[N]===0;)N++;for(var w=new Uint8Array(h+(C-N)),b=h;N!==C;)w[b++]=x[N++];return w}}}function T(A){var y=d(A);if(y)return y;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:d,decode:T}}var Eu=bu,Su=Eu,ji=Su;var oo=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")}},io=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 Ji(this,t)}},so=class{decoders;constructor(t){this.decoders=t}or(t){return Ji(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 Ji(e,t){return new so({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var ao=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 oo(t,r,n),this.decoder=new io(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Ze({name:e,prefix:t,encode:r,decode:n}){return new ao(e,t,r,n)}function fe({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=ji(r,e);return Ze({prefix:t,name:e,encode:n,decode:i=>jt(o(i))})}function Au(e,t,r,n){let o={};for(let c=0;c<t.length;++c)o[t[c]]=c;let i=e.length;for(;e[i-1]==="=";)--i;let s=new Uint8Array(i*r/8|0),a=0,u=0,f=0;for(let c=0;c<i;++c){let l=o[e[c]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);u=u<<r|l,a+=r,a>=8&&(a-=8,s[f++]=255&u>>a)}if(a>=r||(255&u<<8-a)!==0)throw new SyntaxError("Unexpected end of data");return s}function vu(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 nt({name:e,prefix:t,bitsPerChar:r,alphabet:n}){return Ze({prefix:t,name:e,encode(o){return vu(o,n,r)},decode(o){return Au(o,n,r,e)}})}var le=nt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Bu=nt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Tu=nt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Iu=nt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Cu=nt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Uu=nt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ru=nt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),_u=nt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Nu=nt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var uo={};wt(uo,{base58btc:()=>j,base58flickr:()=>Lu});var j=fe({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Lu=fe({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var lo={};wt(lo,{base64:()=>fo,base64pad:()=>Du,base64url:()=>ku,base64urlpad:()=>Pu});var fo=nt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Du=nt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),ku=nt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Pu=nt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});function Fu(e,t){try{if(typeof e=="string"&&e.length>0)return Ou(e);if(typeof e=="number"&&isFinite(e))return t?.long?Ku(e):Mu(e);throw new Error("Value is not a string or number.")}catch(r){let n=Vu(r)?`${r.message}. value=${JSON.stringify(e)}`:"An unknown error has occured.";throw new Error(n)}}function Ou(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 Zr=Fu;function Mu(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 Ku(e){let t=Math.abs(e);return t>=864e5?Gr(e,t,864e5,"day"):t>=36e5?Gr(e,t,36e5,"hour"):t>=6e4?Gr(e,t,6e4,"minute"):t>=1e3?Gr(e,t,1e3,"second"):`${e} ms`}function Gr(e,t,r,n){let o=t>=r*1.5;return`${Math.round(e/r)} ${n}${o?"s":""}`}function Vu(e){return typeof e=="object"&&e!==null&&"message"in e}function ho(e){r.debug=r,r.default=r,r.coerce=u,r.disable=i,r.enable=o,r.enabled=s,r.humanize=Zr,r.destroy=f,Object.keys(e).forEach(c=>{r[c]=e[c]}),r.names=[],r.skips=[],r.formatters={};function t(c){let l=0;for(let d=0;d<c.length;d++)l=(l<<5)-l+c.charCodeAt(d),l|=0;return r.colors[Math.abs(l)%r.colors.length]}r.selectColor=t;function r(c){let l,d=null,T,A;function y(...h){if(!y.enabled)return;let S=y,C=Number(new Date),x=C-(l||C);S.diff=x,S.prev=l,S.curr=C,l=C,h[0]=r.coerce(h[0]),typeof h[0]!="string"&&h.unshift("%O");let _=0;h[0]=h[0].replace(/%([a-zA-Z%])/g,(k,N)=>{if(k==="%%")return"%";_++;let w=r.formatters[N];if(typeof w=="function"){let b=h[_];k=w.call(S,b),h.splice(_,1),_--}return k}),r.formatArgs.call(S,h),(S.log||r.log).apply(S,h)}return y.namespace=c,y.useColors=r.useColors(),y.color=r.selectColor(c),y.extend=n,y.destroy=r.destroy,Object.defineProperty(y,"enabled",{enumerable:!0,configurable:!1,get:()=>d!==null?d:(T!==r.namespaces&&(T=r.namespaces,A=r.enabled(c)),A),set:h=>{d=h}}),typeof r.init=="function"&&r.init(y),y}function n(c,l){let d=r(this.namespace+(typeof l>"u"?":":l)+c);return d.log=this.log,d}function o(c){r.save(c),r.namespaces=c,r.names=[],r.skips=[];let l,d=(typeof c=="string"?c:"").split(/[\s,]+/),T=d.length;for(l=0;l<T;l++)d[l]&&(c=d[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,d;for(l=0,d=r.skips.length;l<d;l++)if(r.skips[l].test(c))return!1;for(l=0,d=r.names.length;l<d;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 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 Wr=Wu(),qu=["#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 Hu(){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 zu(e){if(e[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+e[0]+(this.useColors?"%c ":" ")+"+"+Zr(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 $u=console.debug??console.log??(()=>{});function Gu(e){try{e?Wr?.setItem("debug",e):Wr?.removeItem("debug")}catch{}}function Zu(){let e;try{e=Wr?.getItem("debug")}catch{}return!e&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(e=globalThis.process.env.DEBUG),e}function Wu(){try{return localStorage}catch{}}function Yu(e){e.j=function(t){try{return JSON.stringify(t)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var Qi=ho({formatArgs:zu,save:Gu,load:Zu,useColors:Hu,setupFormatters:Yu,colors:qu,storage:Wr,log:$u});var St=Qi;St.formatters.b=e=>e==null?"undefined":j.baseEncode(e);St.formatters.t=e=>e==null?"undefined":le.baseEncode(e);St.formatters.m=e=>e==null?"undefined":fo.baseEncode(e);St.formatters.p=e=>e==null?"undefined":e.toString();St.formatters.c=e=>e==null?"undefined":e.toString();St.formatters.k=e=>e==null?"undefined":e.toString();St.formatters.a=e=>e==null?"undefined":e.toString();St.formatters.e=e=>e==null?"undefined":ts(e.stack)??ts(e.message)??e.toString();function Xu(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 de(e){let t=Xu(`${e}:trace`);return St.enabled(`${e}:trace`)&&St.names.map(r=>r.toString()).find(r=>r.includes(":trace"))!=null&&(t=St(`${e}:trace`)),Object.assign(St(e),{error:St(`${e}:error`),trace:t})}function ts(e){if(e!=null&&(e=e.trim(),e.length!==0))return e}var po={};wt(po,{base36:()=>kt,base36upper:()=>ju});var kt=fe({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),ju=fe({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ju=ns,es=128,Qu=127,tf=~Qu,ef=Math.pow(2,31);function ns(e,t,r){t=t||[],r=r||0;for(var n=r;e>=ef;)t[r++]=e&255|es,e/=128;for(;e&tf;)t[r++]=e&255|es,e>>>=7;return t[r]=e|0,ns.bytes=r-n+1,t}var rf=mo,nf=128,rs=127;function mo(e,n){var r=0,n=n||0,o=0,i=n,s,a=e.length;do{if(i>=a)throw mo.bytes=0,new RangeError("Could not decode varint");s=e[i++],r+=o<28?(s&rs)<<o:(s&rs)*Math.pow(2,o),o+=7}while(s>=nf);return mo.bytes=i-n,r}var of=Math.pow(2,7),sf=Math.pow(2,14),af=Math.pow(2,21),cf=Math.pow(2,28),uf=Math.pow(2,35),ff=Math.pow(2,42),lf=Math.pow(2,49),df=Math.pow(2,56),hf=Math.pow(2,63),pf=function(e){return e<of?1:e<sf?2:e<af?3:e<cf?4:e<uf?5:e<ff?6:e<lf?7:e<df?8:e<hf?9:10},mf={encode:Ju,decode:rf,encodingLength:pf},gf=mf,pr=gf;function mr(e,t=0){return[pr.decode(e,t),pr.decode.bytes]}function We(e,t,r=0){return pr.encode(e,t,r),t}function Ye(e){return pr.encodingLength(e)}function Pt(e,t){let r=t.byteLength,n=Ye(e),o=n+Ye(r),i=new Uint8Array(o+r);return We(e,i,0),We(r,i,n),i.set(t,o),new Xe(e,r,t,i)}function Jt(e){let t=jt(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 Xe(r,o,s,t)}function os(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Zi(e.bytes,r.bytes)}}var Xe=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function is(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return xf(r,go(e),t??j.encoder);default:return wf(r,go(e),t??le.encoder)}}var ss=new WeakMap;function go(e){let t=ss.get(e);if(t==null){let r=new Map;return ss.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!==gr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==bf)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=Pt(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&&os(t.multihash,n.multihash)}toString(t){return is(this,t)}toJSON(){return{"/":is(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??as(n,o,i.bytes))}else if(r[Ef]===!0){let{version:n,multihash:o,code:i}=r,s=Jt(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!==gr)throw new Error(`Version 0 CID must use dag-pb (code: ${gr}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=as(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,gr,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=jt(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 Xe(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,d]=mr(t.subarray(r));return r+=d,l},o=n(),i=gr;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(),f=r+u,c=f-s;return{version:o,codec:i,multihashCode:a,digestSize:u,multihashSize:c,size:f}}static parse(t,r){let[n,o]=yf(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 go(i).set(n,t),i}};function yf(e,t){switch(e[0]){case"Q":{let r=t??j;return[j.prefix,r.decode(`${j.prefix}${e}`)]}case j.prefix:{let r=t??j;return[j.prefix,r.decode(e)]}case le.prefix:{let r=t??le;return[le.prefix,r.decode(e)]}case kt.prefix:{let r=t??kt;return[kt.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 xf(e,t,r){let{prefix:n}=r;if(n!==j.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 wf(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 gr=112,bf=18;function as(e,t,r){let n=Ye(e),o=n+Ye(t),i=new Uint8Array(o+r.byteLength);return We(e,i,0),We(t,i,n),i.set(r,o),i}var Ef=Symbol.for("@ipld/js-cid/CID");var yo={};wt(yo,{identity:()=>Qt});var cs=0,Sf="identity",us=jt;function Af(e){return Pt(cs,us(e))}var Qt={code:cs,name:Sf,encode:us,digest:Af};function ot(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function fs(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function vf(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function je(e,...t){if(!vf(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 ls(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");fs(e.outputLen),fs(e.blockLen)}function Je(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 ds(e,t){je(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}var _e=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Xr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Ft(e,t){return e<<32-t|e>>>t}function hs(e){if(typeof e!="string")throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array(new TextEncoder().encode(e))}function yr(e){return typeof e=="string"&&(e=hs(e)),je(e),e}function xo(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];je(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 Qe=class{clone(){return this._cloneInto()}};function jr(e){let t=n=>e().update(yr(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function Jr(e=32){if(_e&&typeof _e.getRandomValues=="function")return _e.getRandomValues(new Uint8Array(e));if(_e&&typeof _e.randomBytes=="function")return _e.randomBytes(e);throw new Error("crypto.getRandomValues must be defined")}function Bf(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,f=n?0:4;e.setUint32(t+u,s,n),e.setUint32(t+f,a,n)}function ps(e,t,r){return e&t^~e&r}function ms(e,t,r){return e&t^e&r^t&r}var tr=class extends Qe{constructor(t,r,n,o){super(),this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=Xr(this.buffer)}update(t){Je(this);let{view:r,buffer:n,blockLen:o}=this;t=yr(t);let i=t.length;for(let s=0;s<i;){let a=Math.min(o-this.pos,i-s);if(a===o){let u=Xr(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){Je(this),ds(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;r[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>o-s&&(this.process(n,0),s=0);for(let l=s;l<o;l++)r[l]=0;Bf(n,o-8,BigInt(this.length*8),i),this.process(n,0);let a=Xr(t),u=this.outputLen;if(u%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=u/4,c=this.get();if(f>c.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<f;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.length=o,t.pos=a,t.finished=i,t.destroyed=s,o%r&&t.buffer.set(n),t}};var Qr=BigInt(4294967295),wo=BigInt(32);function gs(e,t=!1){return t?{h:Number(e&Qr),l:Number(e>>wo&Qr)}:{h:Number(e>>wo&Qr)|0,l:Number(e&Qr)|0}}function Tf(e,t=!1){let r=new Uint32Array(e.length),n=new Uint32Array(e.length);for(let o=0;o<e.length;o++){let{h:i,l:s}=gs(e[o],t);[r[o],n[o]]=[i,s]}return[r,n]}var If=(e,t)=>BigInt(e>>>0)<<wo|BigInt(t>>>0),Cf=(e,t,r)=>e>>>r,Uf=(e,t,r)=>e<<32-r|t>>>r,Rf=(e,t,r)=>e>>>r|t<<32-r,_f=(e,t,r)=>e<<32-r|t>>>r,Nf=(e,t,r)=>e<<64-r|t>>>r-32,Lf=(e,t,r)=>e>>>r-32|t<<64-r,Df=(e,t)=>t,kf=(e,t)=>e,Pf=(e,t,r)=>e<<r|t>>>32-r,Ff=(e,t,r)=>t<<r|e>>>32-r,Of=(e,t,r)=>t<<r-32|e>>>64-r,Mf=(e,t,r)=>e<<r-32|t>>>64-r;function Kf(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var Vf=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),qf=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,Hf=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),zf=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,$f=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Gf=(e,t,r,n,o,i)=>t+r+n+o+i+(e/2**32|0)|0;var Zf={fromBig:gs,split:Tf,toBig:If,shrSH:Cf,shrSL:Uf,rotrSH:Rf,rotrSL:_f,rotrBH:Nf,rotrBL:Lf,rotr32H:Df,rotr32L:kf,rotlSH:Pf,rotlSL:Ff,rotlBH:Of,rotlBL:Mf,add:Kf,add3L:Vf,add3H:qf,add4L:Hf,add4H:zf,add5H:Gf,add5L:$f},H=Zf;var[Wf,Yf]=H.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))),pe=new Uint32Array(80),me=new Uint32Array(80),bo=class extends tr{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:i,Cl:s,Dh:a,Dl:u,Eh:f,El:c,Fh:l,Fl:d,Gh:T,Gl:A,Hh:y,Hl:h}=this;return[t,r,n,o,i,s,a,u,f,c,l,d,T,A,y,h]}set(t,r,n,o,i,s,a,u,f,c,l,d,T,A,y,h){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=f|0,this.El=c|0,this.Fh=l|0,this.Fl=d|0,this.Gh=T|0,this.Gl=A|0,this.Hh=y|0,this.Hl=h|0}process(t,r){for(let x=0;x<16;x++,r+=4)pe[x]=t.getUint32(r),me[x]=t.getUint32(r+=4);for(let x=16;x<80;x++){let _=pe[x-15]|0,P=me[x-15]|0,k=H.rotrSH(_,P,1)^H.rotrSH(_,P,8)^H.shrSH(_,P,7),N=H.rotrSL(_,P,1)^H.rotrSL(_,P,8)^H.shrSL(_,P,7),w=pe[x-2]|0,b=me[x-2]|0,F=H.rotrSH(w,b,19)^H.rotrBH(w,b,61)^H.shrSH(w,b,6),L=H.rotrSL(w,b,19)^H.rotrBL(w,b,61)^H.shrSL(w,b,6),U=H.add4L(N,L,me[x-7],me[x-16]),V=H.add4H(U,k,F,pe[x-7],pe[x-16]);pe[x]=V|0,me[x]=U|0}let{Ah:n,Al:o,Bh:i,Bl:s,Ch:a,Cl:u,Dh:f,Dl:c,Eh:l,El:d,Fh:T,Fl:A,Gh:y,Gl:h,Hh:S,Hl:C}=this;for(let x=0;x<80;x++){let _=H.rotrSH(l,d,14)^H.rotrSH(l,d,18)^H.rotrBH(l,d,41),P=H.rotrSL(l,d,14)^H.rotrSL(l,d,18)^H.rotrBL(l,d,41),k=l&T^~l&y,N=d&A^~d&h,w=H.add5L(C,P,N,Yf[x],me[x]),b=H.add5H(w,S,_,k,Wf[x],pe[x]),F=w|0,L=H.rotrSH(n,o,28)^H.rotrBH(n,o,34)^H.rotrBH(n,o,39),U=H.rotrSL(n,o,28)^H.rotrBL(n,o,34)^H.rotrBL(n,o,39),V=n&i^n&a^i&a,v=o&s^o&u^s&u;S=y|0,C=h|0,y=T|0,h=A|0,T=l|0,A=d|0,{h:l,l:d}=H.add(f|0,c|0,b|0,F|0),f=a|0,c=u|0,a=i|0,u=s|0,i=n|0,s=o|0;let B=H.add3L(F,U,v);n=H.add3H(B,b,L,V),o=B|0}({h:n,l:o}=H.add(this.Ah|0,this.Al|0,n|0,o|0)),{h:i,l:s}=H.add(this.Bh|0,this.Bl|0,i|0,s|0),{h:a,l:u}=H.add(this.Ch|0,this.Cl|0,a|0,u|0),{h:f,l:c}=H.add(this.Dh|0,this.Dl|0,f|0,c|0),{h:l,l:d}=H.add(this.Eh|0,this.El|0,l|0,d|0),{h:T,l:A}=H.add(this.Fh|0,this.Fl|0,T|0,A|0),{h:y,l:h}=H.add(this.Gh|0,this.Gl|0,y|0,h|0),{h:S,l:C}=H.add(this.Hh|0,this.Hl|0,S|0,C|0),this.set(n,o,i,s,a,u,f,c,l,d,T,A,y,h,S,C)}roundClean(){pe.fill(0),me.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var ys=jr(()=>new bo);var rn={};wt(rn,{aInRange:()=>At,abool:()=>Ot,abytes:()=>er,bitGet:()=>el,bitLen:()=>vo,bitMask:()=>wr,bitSet:()=>rl,bytesToHex:()=>ee,bytesToNumberBE:()=>re,bytesToNumberLE:()=>ye,concatBytes:()=>ne,createHmacDrbg:()=>Bo,ensureBytes:()=>rt,equalBytes:()=>Qf,hexToBytes:()=>Le,hexToNumber:()=>Ao,inRange:()=>xr,isBytes:()=>ge,memoized:()=>ke,notImplemented:()=>ol,numberToBytesBE:()=>xe,numberToBytesLE:()=>De,numberToHexUnpadded:()=>Ne,numberToVarBytesBE:()=>Jf,utf8ToBytes:()=>tl,validateObject:()=>Gt});var tn=BigInt(0),en=BigInt(1),Xf=BigInt(2);function ge(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function er(e){if(!ge(e))throw new Error("Uint8Array expected")}function Ot(e,t){if(typeof t!="boolean")throw new Error(e+" boolean expected, got "+t)}var jf=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function ee(e){er(e);let t="";for(let r=0;r<e.length;r++)t+=jf[e[r]];return t}function Ne(e){let t=e.toString(16);return t.length&1?"0"+t:t}function Ao(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?tn:BigInt("0x"+e)}var te={_0:48,_9:57,A:65,F:70,a:97,f:102};function xs(e){if(e>=te._0&&e<=te._9)return e-te._0;if(e>=te.A&&e<=te.F)return e-(te.A-10);if(e>=te.a&&e<=te.f)return e-(te.a-10)}function Le(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof 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=xs(e.charCodeAt(i)),a=xs(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 re(e){return Ao(ee(e))}function ye(e){return er(e),Ao(ee(Uint8Array.from(e).reverse()))}function xe(e,t){return Le(e.toString(16).padStart(t*2,"0"))}function De(e,t){return xe(e,t).reverse()}function Jf(e){return Le(Ne(e))}function rt(e,t,r){let n;if(typeof t=="string")try{n=Le(t)}catch(i){throw new Error(e+" must be hex string or Uint8Array, cause: "+i)}else if(ge(t))n=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");let o=n.length;if(typeof r=="number"&&o!==r)throw new Error(e+" of length "+r+" expected, got "+o);return n}function ne(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];er(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 Qf(e,t){if(e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}function tl(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}var Eo=e=>typeof e=="bigint"&&tn<=e;function xr(e,t,r){return Eo(e)&&Eo(t)&&Eo(r)&&t<=e&&e<r}function At(e,t,r,n){if(!xr(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function vo(e){let t;for(t=0;e>tn;e>>=en,t+=1);return t}function el(e,t){return e>>BigInt(t)&en}function rl(e,t,r){return e|(r?en:tn)<<BigInt(t)}var wr=e=>(Xf<<BigInt(e-1))-en,So=e=>new Uint8Array(e),ws=e=>Uint8Array.from(e);function Bo(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=So(e),o=So(e),i=0,s=()=>{n.fill(1),o.fill(0),i=0},a=(...l)=>r(o,n,...l),u=(l=So())=>{o=a(ws([0]),l),n=a(),l.length!==0&&(o=a(ws([1]),l),n=a())},f=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let l=0,d=[];for(;l<t;){n=a();let T=n.slice();d.push(T),l+=n.length}return ne(...d)};return(l,d)=>{s(),u(l);let T;for(;!(T=d(f()));)u();return s(),T}}var nl={bigint:e=>typeof e=="bigint",function:e=>typeof e=="function",boolean:e=>typeof e=="boolean",string:e=>typeof e=="string",stringOrUint8Array:e=>typeof e=="string"||ge(e),isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,t)=>t.Fp.isValid(e),hash:e=>typeof e=="function"&&Number.isSafeInteger(e.outputLen)};function Gt(e,t,r={}){let n=(o,i,s)=>{let a=nl[i];if(typeof a!="function")throw new Error("invalid validator function");let u=e[o];if(!(s&&u===void 0)&&!a(u,e))throw new Error("param "+String(o)+" is invalid. Expected "+i+", got "+u)};for(let[o,i]of Object.entries(t))n(o,i,!1);for(let[o,i]of Object.entries(r))n(o,i,!0);return e}var ol=()=>{throw new Error("not implemented")};function ke(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 it=BigInt(0),Q=BigInt(1),Pe=BigInt(2),il=BigInt(3),To=BigInt(4),bs=BigInt(5),Es=BigInt(8),sl=BigInt(9),al=BigInt(16);function Y(e,t){let r=e%t;return r>=it?r:t+r}function cl(e,t,r){if(t<it)throw new Error("invalid exponent, negatives unsupported");if(r<=it)throw new Error("invalid modulus");if(r===Q)return it;let n=Q;for(;t>it;)t&Q&&(n=n*e%r),e=e*e%r,t>>=Q;return n}function tt(e,t,r){let n=e;for(;t-- >it;)n*=n,n%=r;return n}function nn(e,t){if(e===it)throw new Error("invert: expected non-zero number");if(t<=it)throw new Error("invert: expected positive modulus, got "+t);let r=Y(e,t),n=t,o=it,i=Q,s=Q,a=it;for(;r!==it;){let f=n/r,c=n%r,l=o-s*f,d=i-a*f;n=r,r=c,o=s,i=a,s=l,a=d}if(n!==Q)throw new Error("invert: does not exist");return Y(o,t)}function ul(e){let t=(e-Q)/Pe,r,n,o;for(r=e-Q,n=0;r%Pe===it;r/=Pe,n++);for(o=Pe;o<e&&cl(o,t,e)!==e-Q;o++)if(o>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){let s=(e+Q)/To;return function(u,f){let c=u.pow(f,s);if(!u.eql(u.sqr(c),f))throw new Error("Cannot find square root");return c}}let i=(r+Q)/Pe;return function(a,u){if(a.pow(u,t)===a.neg(a.ONE))throw new Error("Cannot find square root");let f=n,c=a.pow(a.mul(a.ONE,o),r),l=a.pow(u,i),d=a.pow(u,r);for(;!a.eql(d,a.ONE);){if(a.eql(d,a.ZERO))return a.ZERO;let T=1;for(let y=a.sqr(d);T<f&&!a.eql(y,a.ONE);T++)y=a.sqr(y);let A=a.pow(c,Q<<BigInt(f-T-1));c=a.sqr(A),l=a.mul(l,A),d=a.mul(d,c),f=T}return l}}function fl(e){if(e%To===il){let t=(e+Q)/To;return function(n,o){let i=n.pow(o,t);if(!n.eql(n.sqr(i),o))throw new Error("Cannot find square root");return i}}if(e%Es===bs){let t=(e-bs)/Es;return function(n,o){let i=n.mul(o,Pe),s=n.pow(i,t),a=n.mul(o,s),u=n.mul(n.mul(a,Pe),s),f=n.mul(a,n.sub(u,n.ONE));if(!n.eql(n.sqr(f),o))throw new Error("Cannot find square root");return f}}return e%al,ul(e)}var Ss=(e,t)=>(Y(e,t)&Q)===Q,ll=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Io(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},r=ll.reduce((n,o)=>(n[o]="function",n),t);return Gt(e,r)}function dl(e,t,r){if(r<it)throw new Error("invalid exponent, negatives unsupported");if(r===it)return e.ONE;if(r===Q)return t;let n=e.ONE,o=t;for(;r>it;)r&Q&&(n=e.mul(n,o)),o=e.sqr(o),r>>=Q;return n}function hl(e,t){let r=new Array(t.length),n=t.reduce((i,s,a)=>e.is0(s)?i:(r[a]=i,e.mul(i,s)),e.ONE),o=e.inv(n);return t.reduceRight((i,s,a)=>e.is0(s)?i:(r[a]=e.mul(i,r[a]),e.mul(i,s)),o),r}function Co(e,t){let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function we(e,t,r=!1,n={}){if(e<=it)throw new Error("invalid field: expected ORDER > 0, got "+e);let{nBitLength:o,nByteLength:i}=Co(e,t);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let s,a=Object.freeze({ORDER:e,isLE:r,BITS:o,BYTES:i,MASK:wr(o),ZERO:it,ONE:Q,create:u=>Y(u,e),isValid:u=>{if(typeof u!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof u);return it<=u&&u<e},is0:u=>u===it,isOdd:u=>(u&Q)===Q,neg:u=>Y(-u,e),eql:(u,f)=>u===f,sqr:u=>Y(u*u,e),add:(u,f)=>Y(u+f,e),sub:(u,f)=>Y(u-f,e),mul:(u,f)=>Y(u*f,e),pow:(u,f)=>dl(a,u,f),div:(u,f)=>Y(u*nn(f,e),e),sqrN:u=>u*u,addN:(u,f)=>u+f,subN:(u,f)=>u-f,mulN:(u,f)=>u*f,inv:u=>nn(u,e),sqrt:n.sqrt||(u=>(s||(s=fl(e)),s(a,u))),invertBatch:u=>hl(a,u),cmov:(u,f,c)=>c?f:u,toBytes:u=>r?De(u,i):xe(u,i),fromBytes:u=>{if(u.length!==i)throw new Error("Field.fromBytes: expected "+i+" bytes, got "+u.length);return r?ye(u):re(u)}});return Object.freeze(a)}function As(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 Uo(e){let t=As(e);return t+Math.ceil(t/2)}function vs(e,t,r=!1){let n=e.length,o=As(t),i=Uo(t);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=r?ye(e):re(e),a=Y(s,t-Q)+Q;return r?De(a,o):xe(a,o)}var Bs=BigInt(0),on=BigInt(1);function Ro(e,t){let r=t.negate();return e?r:t}function Ts(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function _o(e,t){Ts(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1);return{windows:r,windowSize:n}}function pl(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function ml(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((r,n)=>{if(!t.isValid(r))throw new Error("invalid scalar at index "+n)})}var No=new WeakMap,Is=new WeakMap;function Lo(e){return Is.get(e)||1}function sn(e,t){return{constTimeNegate:Ro,hasPrecomputes(r){return Lo(r)!==1},unsafeLadder(r,n,o=e.ZERO){let i=r;for(;n>Bs;)n&on&&(o=o.add(i)),i=i.double(),n>>=on;return o},precomputeWindow(r,n){let{windows:o,windowSize:i}=_o(n,t),s=[],a=r,u=a;for(let f=0;f<o;f++){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{windows:i,windowSize:s}=_o(r,t),a=e.ZERO,u=e.BASE,f=BigInt(2**r-1),c=2**r,l=BigInt(r);for(let d=0;d<i;d++){let T=d*s,A=Number(o&f);o>>=l,A>s&&(A-=c,o+=on);let y=T,h=T+Math.abs(A)-1,S=d%2!==0,C=A<0;A===0?u=u.add(Ro(S,n[y])):a=a.add(Ro(C,n[h]))}return{p:a,f:u}},wNAFUnsafe(r,n,o,i=e.ZERO){let{windows:s,windowSize:a}=_o(r,t),u=BigInt(2**r-1),f=2**r,c=BigInt(r);for(let l=0;l<s;l++){let d=l*a;if(o===Bs)break;let T=Number(o&u);if(o>>=c,T>a&&(T-=f,o+=on),T===0)continue;let A=n[d+Math.abs(T)-1];T<0&&(A=A.negate()),i=i.add(A)}return i},getPrecomputes(r,n,o){let i=No.get(n);return i||(i=this.precomputeWindow(n,r),r!==1&&No.set(n,o(i))),i},wNAFCached(r,n,o){let i=Lo(r);return this.wNAF(i,this.getPrecomputes(i,r,o),n)},wNAFCachedUnsafe(r,n,o,i){let s=Lo(r);return s===1?this.unsafeLadder(r,n,i):this.wNAFUnsafe(s,this.getPrecomputes(s,r,o),n,i)},setWindowSize(r,n){Ts(n,t),Is.set(r,n),No.delete(r)}}}function an(e,t,r,n){if(pl(r,e),ml(n,t),r.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let o=e.ZERO,i=vo(BigInt(r.length)),s=i>12?i-3:i>4?i-2:i?2:1,a=(1<<s)-1,u=new Array(a+1).fill(o),f=Math.floor((t.BITS-1)/s)*s,c=o;for(let l=f;l>=0;l-=s){u.fill(o);for(let T=0;T<n.length;T++){let A=n[T],y=Number(A>>BigInt(l)&BigInt(a));u[y]=u[y].add(r[T])}let d=o;for(let T=u.length-1,A=o;T>0;T--)A=A.add(u[T]),d=d.add(A);if(c=c.add(d),l!==0)for(let T=0;T<s;T++)c=c.double()}return c}function br(e){return Io(e.Fp),Gt(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Co(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}var Mt=BigInt(0),vt=BigInt(1),cn=BigInt(2),gl=BigInt(8),yl={zip215:!0};function xl(e){let t=br(e);return Gt(e,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function Cs(e){let t=xl(e),{Fp:r,n,prehash:o,hash:i,randomBytes:s,nByteLength:a,h:u}=t,f=cn<<BigInt(a*8)-vt,c=r.create,l=we(t.n,t.nBitLength),d=t.uvRatio||((g,p)=>{try{return{isValid:!0,value:r.sqrt(g*r.inv(p))}}catch{return{isValid:!1,value:Mt}}}),T=t.adjustScalarBytes||(g=>g),A=t.domain||((g,p,E)=>{if(Ot("phflag",E),p.length||E)throw new Error("Contexts/pre-hash are not supported");return g});function y(g,p){At("coordinate "+g,p,Mt,f)}function h(g){if(!(g instanceof x))throw new Error("ExtendedPoint expected")}let S=ke((g,p)=>{let{ex:E,ey:R,ez:O}=g,M=g.is0();p==null&&(p=M?gl:r.inv(O));let z=c(E*p),$=c(R*p),q=c(O*p);if(M)return{x:Mt,y:vt};if(q!==vt)throw new Error("invZ was invalid");return{x:z,y:$}}),C=ke(g=>{let{a:p,d:E}=t;if(g.is0())throw new Error("bad point: ZERO");let{ex:R,ey:O,ez:M,et:z}=g,$=c(R*R),q=c(O*O),Z=c(M*M),X=c(Z*Z),at=c($*p),ct=c(Z*c(at+q)),lt=c(X+c(E*c($*q)));if(ct!==lt)throw new Error("bad point: equation left != right (1)");let pt=c(R*O),Et=c(M*z);if(pt!==Et)throw new Error("bad point: equation left != right (2)");return!0});class x{constructor(p,E,R,O){this.ex=p,this.ey=E,this.ez=R,this.et=O,y("x",p),y("y",E),y("z",R),y("t",O),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(p){if(p instanceof x)throw new Error("extended point not allowed");let{x:E,y:R}=p||{};return y("x",E),y("y",R),new x(E,R,vt,c(E*R))}static normalizeZ(p){let E=r.invertBatch(p.map(R=>R.ez));return p.map((R,O)=>R.toAffine(E[O])).map(x.fromAffine)}static msm(p,E){return an(x,l,p,E)}_setWindowSize(p){k.setWindowSize(this,p)}assertValidity(){C(this)}equals(p){h(p);let{ex:E,ey:R,ez:O}=this,{ex:M,ey:z,ez:$}=p,q=c(E*$),Z=c(M*O),X=c(R*$),at=c(z*O);return q===Z&&X===at}is0(){return this.equals(x.ZERO)}negate(){return new x(c(-this.ex),this.ey,this.ez,c(-this.et))}double(){let{a:p}=t,{ex:E,ey:R,ez:O}=this,M=c(E*E),z=c(R*R),$=c(cn*c(O*O)),q=c(p*M),Z=E+R,X=c(c(Z*Z)-M-z),at=q+z,ct=at-$,lt=q-z,pt=c(X*ct),Et=c(at*lt),xt=c(X*lt),$t=c(ct*at);return new x(pt,Et,$t,xt)}add(p){h(p);let{a:E,d:R}=t,{ex:O,ey:M,ez:z,et:$}=this,{ex:q,ey:Z,ez:X,et:at}=p;if(E===BigInt(-1)){let Fi=c((M-O)*(Z+q)),Oi=c((M+O)*(Z-q)),ro=c(Oi-Fi);if(ro===Mt)return this.double();let Mi=c(z*cn*at),Ki=c($*cn*X),Vi=Ki+Mi,qi=Oi+Fi,Hi=Ki-Mi,fu=c(Vi*ro),lu=c(qi*Hi),du=c(Vi*Hi),hu=c(ro*qi);return new x(fu,lu,hu,du)}let ct=c(O*q),lt=c(M*Z),pt=c($*R*at),Et=c(z*X),xt=c((O+M)*(q+Z)-ct-lt),$t=Et-pt,Xt=Et+pt,dr=c(lt-E*ct),su=c(xt*$t),au=c(Xt*dr),cu=c(xt*dr),uu=c($t*Xt);return new x(su,au,uu,cu)}subtract(p){return this.add(p.negate())}wNAF(p){return k.wNAFCached(this,p,x.normalizeZ)}multiply(p){let E=p;At("scalar",E,vt,n);let{p:R,f:O}=this.wNAF(E);return x.normalizeZ([R,O])[0]}multiplyUnsafe(p,E=x.ZERO){let R=p;return At("scalar",R,Mt,n),R===Mt?P:this.is0()||R===vt?this:k.wNAFCachedUnsafe(this,R,x.normalizeZ,E)}isSmallOrder(){return this.multiplyUnsafe(u).is0()}isTorsionFree(){return k.unsafeLadder(this,n).is0()}toAffine(p){return S(this,p)}clearCofactor(){let{h:p}=t;return p===vt?this:this.multiplyUnsafe(p)}static fromHex(p,E=!1){let{d:R,a:O}=t,M=r.BYTES;p=rt("pointHex",p,M),Ot("zip215",E);let z=p.slice(),$=p[M-1];z[M-1]=$&-129;let q=ye(z),Z=E?f:r.ORDER;At("pointHex.y",q,Mt,Z);let X=c(q*q),at=c(X-vt),ct=c(R*X-O),{isValid:lt,value:pt}=d(at,ct);if(!lt)throw new Error("Point.fromHex: invalid y coordinate");let Et=(pt&vt)===vt,xt=($&128)!==0;if(!E&&pt===Mt&&xt)throw new Error("Point.fromHex: x=0 and x_0=1");return xt!==Et&&(pt=c(-pt)),x.fromAffine({x:pt,y:q})}static fromPrivateKey(p){return b(p).point}toRawBytes(){let{x:p,y:E}=this.toAffine(),R=De(E,r.BYTES);return R[R.length-1]|=p&vt?128:0,R}toHex(){return ee(this.toRawBytes())}}x.BASE=new x(t.Gx,t.Gy,vt,c(t.Gx*t.Gy)),x.ZERO=new x(Mt,vt,vt,Mt);let{BASE:_,ZERO:P}=x,k=sn(x,a*8);function N(g){return Y(g,n)}function w(g){return N(ye(g))}function b(g){let p=r.BYTES;g=rt("private key",g,p);let E=rt("hashed private key",i(g),2*p),R=T(E.slice(0,p)),O=E.slice(p,2*p),M=w(R),z=_.multiply(M),$=z.toRawBytes();return{head:R,prefix:O,scalar:M,point:z,pointBytes:$}}function F(g){return b(g).pointBytes}function L(g=new Uint8Array,...p){let E=ne(...p);return w(i(A(E,rt("context",g),!!o)))}function U(g,p,E={}){g=rt("message",g),o&&(g=o(g));let{prefix:R,scalar:O,pointBytes:M}=b(p),z=L(E.context,R,g),$=_.multiply(z).toRawBytes(),q=L(E.context,$,M,g),Z=N(z+q*O);At("signature.s",Z,Mt,n);let X=ne($,De(Z,r.BYTES));return rt("result",X,r.BYTES*2)}let V=yl;function v(g,p,E,R=V){let{context:O,zip215:M}=R,z=r.BYTES;g=rt("signature",g,2*z),p=rt("message",p),E=rt("publicKey",E,z),M!==void 0&&Ot("zip215",M),o&&(p=o(p));let $=ye(g.slice(z,2*z)),q,Z,X;try{q=x.fromHex(E,M),Z=x.fromHex(g.slice(0,z),M),X=_.multiplyUnsafe($)}catch{return!1}if(!M&&q.isSmallOrder())return!1;let at=L(O,Z.toRawBytes(),q.toRawBytes(),p);return Z.add(q.multiplyUnsafe(at)).subtract(X).clearCofactor().equals(x.ZERO)}return _._setWindowSize(8),{CURVE:t,getPublicKey:F,sign:U,verify:v,ExtendedPoint:x,utils:{getExtendedPublicKey:b,randomPrivateKey:()=>s(r.BYTES),precompute(g=8,p=x.BASE){return p._setWindowSize(g),p.multiply(BigInt(3)),p}}}}var Do=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Us=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),M0=BigInt(0),wl=BigInt(1),Rs=BigInt(2),K0=BigInt(3),bl=BigInt(5),El=BigInt(8);function Sl(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),i=Do,a=e*e%i*e%i,u=tt(a,Rs,i)*a%i,f=tt(u,wl,i)*e%i,c=tt(f,bl,i)*f%i,l=tt(c,t,i)*c%i,d=tt(l,r,i)*l%i,T=tt(d,n,i)*d%i,A=tt(T,o,i)*T%i,y=tt(A,o,i)*T%i,h=tt(y,t,i)*c%i;return{pow_p_5_8:tt(h,Rs,i)*e%i,b2:a}}function Al(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}function vl(e,t){let r=Do,n=Y(t*t*t,r),o=Y(n*n*t,r),i=Sl(e*o).pow_p_5_8,s=Y(e*n*i,r),a=Y(t*s*s,r),u=s,f=Y(s*Us,r),c=a===e,l=a===Y(-e,r),d=a===Y(-e*Us,r);return c&&(s=u),(l||d)&&(s=f),Ss(s,r)&&(s=Y(-s,r)),{isValid:c||l,value:s}}var Bl=we(Do,void 0,!0),Tl={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Bl,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:El,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:ys,randomBytes:Jr,adjustScalarBytes:Al,uvRatio:vl},_s=Cs(Tl);var un=32;function Ns(e,t,r){return _s.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}var fn=class{type="Ed25519";raw;constructor(t){this.raw=ko(t,un)}toMultihash(){return Qt.digest(rr(this))}toCID(){return J.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ot(this.raw,t.raw)}verify(t,r){return Ns(this.raw,r,t)}};function Po(e){return e=ko(e,un),new fn(e)}function ko(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new mt(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}function _t(e=0){return new Uint8Array(e)}function Bt(e=0){return new Uint8Array(e)}var Cl=Math.pow(2,7),Ul=Math.pow(2,14),Rl=Math.pow(2,21),Ds=Math.pow(2,28),ks=Math.pow(2,35),Ps=Math.pow(2,42),Fs=Math.pow(2,49),bt=128,be=127;function Er(e){if(e<Cl)return 1;if(e<Ul)return 2;if(e<Rl)return 3;if(e<Ds)return 4;if(e<ks)return 5;if(e<Ps)return 6;if(e<Fs)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Os(e,t,r=0){switch(Er(e)){case 8:t[r++]=e&255|bt,e/=128;case 7:t[r++]=e&255|bt,e/=128;case 6:t[r++]=e&255|bt,e/=128;case 5:t[r++]=e&255|bt,e/=128;case 4:t[r++]=e&255|bt,e>>>=7;case 3:t[r++]=e&255|bt,e>>>=7;case 2:t[r++]=e&255|bt,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function Ms(e,t){let r=e[t],n=0;if(n+=r&be,r<bt||(r=e[t+1],n+=(r&be)<<7,r<bt)||(r=e[t+2],n+=(r&be)<<14,r<bt)||(r=e[t+3],n+=(r&be)<<21,r<bt)||(r=e[t+4],n+=(r&be)*Ds,r<bt)||(r=e[t+5],n+=(r&be)*ks,r<bt)||(r=e[t+6],n+=(r&be)*Ps,r<bt)||(r=e[t+7],n+=(r&be)*Fs,r<bt))return n;throw new RangeError("Could not decode varint")}var Fo=new Float32Array([-0]),Ee=new Uint8Array(Fo.buffer);function Ks(e,t,r){Fo[0]=e,t[r]=Ee[0],t[r+1]=Ee[1],t[r+2]=Ee[2],t[r+3]=Ee[3]}function Vs(e,t){return Ee[0]=e[t],Ee[1]=e[t+1],Ee[2]=e[t+2],Ee[3]=e[t+3],Fo[0]}var Oo=new Float64Array([-0]),gt=new Uint8Array(Oo.buffer);function qs(e,t,r){Oo[0]=e,t[r]=gt[0],t[r+1]=gt[1],t[r+2]=gt[2],t[r+3]=gt[3],t[r+4]=gt[4],t[r+5]=gt[5],t[r+6]=gt[6],t[r+7]=gt[7]}function Hs(e,t){return gt[0]=e[t],gt[1]=e[t+1],gt[2]=e[t+2],gt[3]=e[t+3],gt[4]=e[t+4],gt[5]=e[t+5],gt[6]=e[t+6],gt[7]=e[t+7],Oo[0]}var _l=BigInt(Number.MAX_SAFE_INTEGER),Nl=BigInt(Number.MIN_SAFE_INTEGER),Tt=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 Fe;if(t<_l&&t>Nl)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>zs&&(o=0n,++n>zs&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return Fe;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):Fe}},Fe=new Tt(0,0);Fe.toBigInt=function(){return 0n};Fe.zzEncode=Fe.zzDecode=function(){return this};Fe.length=function(){return 1};var zs=4294967296n;function $s(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 Gs(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 Mo(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 ln(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var Ko=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 ln(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Kt(this,4);return ln(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Kt(this,4);let t=Vs(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Kt(this,4);let t=Hs(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 Gs(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 Tt(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=ln(this.buf,this.pos+=4),r=ln(this.buf,this.pos+=4);return new Tt(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=Ms(this.buf,this.pos);return this.pos+=Er(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 Vo(e){return new Ko(e instanceof Uint8Array?e:e.subarray())}function Se(e,t,r){let n=Vo(e);return t.decode(n,void 0,r)}var qo={};wt(qo,{base10:()=>Ll});var Ll=fe({prefix:"9",name:"base10",alphabet:"0123456789"});var Ho={};wt(Ho,{base16:()=>Dl,base16upper:()=>kl});var Dl=nt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),kl=nt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var zo={};wt(zo,{base2:()=>Pl});var Pl=nt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var $o={};wt($o,{base256emoji:()=>Vl});var Ws=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),Fl=Ws.reduce((e,t,r)=>(e[r]=t,e),[]),Ol=Ws.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Ml(e){return e.reduce((t,r)=>(t+=Fl[r],t),"")}function Kl(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Ol[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var Vl=Ze({prefix:"\u{1F680}",name:"base256emoji",encode:Ml,decode:Kl});var Go={};wt(Go,{base8:()=>ql});var ql=nt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Zo={};wt(Zo,{identity:()=>Hl});var Hl=Ze({prefix:"\0",name:"identity",encode:e=>Yi(e),decode:e=>Wi(e)});var Sp=new TextEncoder,Ap=new TextDecoder;var Xo={};wt(Xo,{sha256:()=>Sr,sha512:()=>Gl});function Yo({name:e,code:t,encode:r}){return new Wo(e,t,r)}var Wo=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?Pt(this.code,r):r.then(n=>Pt(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 Sr=Yo({name:"sha2-256",code:18,encode:Xs("SHA-256")}),Gl=Yo({name:"sha2-512",code:19,encode:Xs("SHA-512")});var jo={...Zo,...zo,...Go,...qo,...Ho,...co,...po,...uo,...lo,...$o},kp={...Xo,...yo};function Js(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var js=Js("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Jo=Js("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=Bt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Zl={utf8:js,"utf-8":js,hex:jo.base16,latin1:Jo,ascii:Jo,binary:Jo,...jo},dn=Zl;function W(e,t="utf8"){let r=dn[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function Qo(e){let t=e??8192,r=t>>>1,n,o=t;return function(s){if(s<1||s>r)return Bt(s);o+s>t&&(n=Bt(t),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var Oe=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function ti(){}var ri=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Wl=Qo();function Yl(e){return globalThis.Buffer!=null?Bt(e):Wl(e)}var vr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Oe(ti,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new Oe(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new ni((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(hn,10,Tt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=Tt.fromBigInt(t);return this._push(hn,r.length(),r)}uint64Number(t){return this._push(Os,Er(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=Tt.fromBigInt(t).zzEncode();return this._push(hn,r.length(),r)}sint64Number(t){let r=Tt.fromNumber(t).zzEncode();return this._push(hn,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(ei,1,t?1:0)}fixed32(t){return this._push(Ar,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=Tt.fromBigInt(t);return this._push(Ar,4,r.lo)._push(Ar,4,r.hi)}fixed64Number(t){let r=Tt.fromNumber(t);return this._push(Ar,4,r.lo)._push(Ar,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(Ks,4,t)}double(t){return this._push(qs,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(ei,1,0):this.uint32(r)._push(jl,r,t)}string(t){let r=$s(t);return r!==0?this.uint32(r)._push(Mo,r,t):this._push(ei,1,0)}fork(){return this.states=new ri(this),this.head=this.tail=new Oe(ti,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 Oe(ti,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=Yl(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function ei(e,t,r){t[r]=e&255}function Xl(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var ni=class extends Oe{next;constructor(t,r){super(Xl,t,r),this.next=void 0}};function hn(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 Ar(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 jl(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(vr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(Jl,t,e),this},vr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Ql,t,e),this});function Jl(e,t,r){t.set(e,r)}function Ql(e,t,r){e.length<40?Mo(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(W(e),r)}function oi(){return new vr}function Ae(e,t){let r=oi();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}var nr;(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"})(nr||(nr={}));function pn(e,t,r,n){return{name:e,type:t,encode:r,decode:n}}function Br(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 pn("enum",nr.VARINT,r,n)}function ve(e,t){return pn("message",nr.LENGTH_DELIMITED,e,t)}var st;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1"})(st||(st={}));var ii;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1"})(ii||(ii={}));(function(e){e.codec=()=>Br(ii)})(st||(st={}));var Zt;(function(e){let t;e.codec=()=>(t==null&&(t=ve((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),st.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=st.codec().decode(r);break}case 2:{i.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return i})),t),e.encode=r=>Ae(r,e.codec()),e.decode=(r,n)=>Se(r,e.codec(),n)})(Zt||(Zt={}));var si;(function(e){let t;e.codec=()=>(t==null&&(t=ve((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),st.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=st.codec().decode(r);break}case 2:{i.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return i})),t),e.encode=r=>Ae(r,e.codec()),e.decode=(r,n)=>Se(r,e.codec(),n)})(si||(si={}));var Cr={};wt(Cr,{MAX_RSA_KEY_SIZE:()=>li,generateRSAKeyPair:()=>ha,jwkToJWKKeyPair:()=>pa,jwkToPkcs1:()=>ld,jwkToPkix:()=>hi,jwkToRSAPrivateKey:()=>da,pkcs1ToJwk:()=>ua,pkcs1ToRSAPrivateKey:()=>la,pkixToJwk:()=>fa,pkixToRSAPublicKey:()=>pi});var td=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Be=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Te=new Uint32Array(64),ai=class extends tr{constructor(){super(64,32,8,!1),this.A=Be[0]|0,this.B=Be[1]|0,this.C=Be[2]|0,this.D=Be[3]|0,this.E=Be[4]|0,this.F=Be[5]|0,this.G=Be[6]|0,this.H=Be[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)Te[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let d=Te[l-15],T=Te[l-2],A=Ft(d,7)^Ft(d,18)^d>>>3,y=Ft(T,17)^Ft(T,19)^T>>>10;Te[l]=y+Te[l-7]+A+Te[l-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:u,G:f,H:c}=this;for(let l=0;l<64;l++){let d=Ft(a,6)^Ft(a,11)^Ft(a,25),T=c+d+ps(a,u,f)+td[l]+Te[l]|0,y=(Ft(n,2)^Ft(n,13)^Ft(n,22))+ms(n,o,i)|0;c=f,f=u,u=a,a=s+T|0,s=i,i=o,o=n,n=T+y|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,f=f+this.G|0,c=c+this.H|0,this.set(n,o,i,s,a,u,f,c)}roundClean(){Te.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var or=jr(()=>new ai);function et(e,t="utf8"){let r=dn[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}function Ie(e,t){t==null&&(t=e.reduce((o,i)=>o+i.length,0));let r=Bt(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var ea=Symbol.for("@achingbrain/uint8arraylist");function ta(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let o=r+n.byteLength;if(t<o)return{buf:n,index:t-r};r=o}throw new RangeError("index is out of bounds")}function mn(e){return!!e?.[ea]}var Vt=class e{bufs;length;[ea]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(mn(n))r+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...t){this.prependAll(t)}prependAll(t){let r=0;for(let n of t.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(mn(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(t){let r=ta(this.bufs,t);return r.buf[r.index]}set(t,r){let n=ta(this.bufs,t);n.buf[n.index]=r}write(t,r=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(r+n,t[n]);else if(mn(t))for(let n=0;n<t.length;n++)this.set(r+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,r){let{bufs:n,length:o}=this._subList(t,r);return Ie(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Ie(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 f=t>=a&&t<u,c=r>a&&r<=u;if(f&&c){if(t===a&&r===u){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(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(!mn(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,s=new Int32Array(i);for(let 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,f=n.byteLength-1,c;for(let l=r;l<=u;l+=c){c=0;for(let d=f;d>=0;d--){let T=this.get(l+d);if(n[d]!==T){c=Math.max(1,d-a[T]);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=Bt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=_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=Bt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=_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(!ot(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,i)=>o+i.byteLength,0)),n.length=r,n}};var ed=parseInt("11111",2),ui=parseInt("10000000",2),rd=parseInt("01111111",2),ra={2:nd,3:sd,5:id,6:od,16:ci,22:ci,48:ci};function Tr(e,t={offset:0}){let r=e[t.offset]&ed;if(t.offset++,ra[r]!=null)return ra[r](e,t);throw new Error("No decoder for tag "+r)}function gn(e,t){let r=0;if((e[t.offset]&ui)===ui){let n=e[t.offset]&rd,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 ci(e,t){gn(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Tr(e,t);if(n===null)break;r.push(n)}return r}function nd(e,t){let r=gn(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 od(e,t){let r=gn(e,t);return t.offset+=r,["oid-unimplemented"]}function id(e,t){return t.offset++,null}function sd(e,t){let r=gn(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return Tr(o,{offset:0})}function ad(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new Vt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function fi(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=ad(e.byteLength);return new Vt(Uint8Array.from([t.byteLength|ui]),t)}function Nt(e){let t=new Vt,r=parseInt("10000000",2);return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new Vt(Uint8Array.from([2]),fi(t),t)}function na(e){let t=Uint8Array.from([0]),r=new Vt(t,e);return new Vt(Uint8Array.from([3]),fi(r),r)}function yn(e){let t=new Vt;for(let r of e)t.append(r);return new Vt(Uint8Array.from([48]),fi(t),t)}var Ir=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},xn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var oa={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new xn("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 Ce=oa;async function ia(e){let t=await Ce.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),r=await cd(t);return{privateKey:r[0],publicKey:r[1]}}async function sa(e,t){let r=await Ce.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await Ce.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},r,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(n,0,n.byteLength)}async function aa(e,t,r){let n=await Ce.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return Ce.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,t,r instanceof Uint8Array?r:r.subarray())}async function cd(e){if(e.privateKey==null||e.publicKey==null)throw new mt("Private and public key are required");return Promise.all([Ce.get().subtle.exportKey("jwk",e.privateKey),Ce.get().subtle.exportKey("jwk",e.publicKey)])}function ca(e){if(e.kty!=="RSA")throw new mt("invalid key type");if(e.n==null)throw new mt("invalid key modulus");return W(e.n,"base64url").length*8}var ir=class{type="RSA";_key;_raw;_multihash;constructor(t,r){this._key=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Cr.jwkToPkix(this._key)),this._raw}toMultihash(){return this._multihash}toCID(){return J.createV1(114,this._multihash)}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ot(this.raw,t.raw)}verify(t,r){return aa(this._key,r,t)}},Ur=class{type="RSA";_key;_raw;publicKey;constructor(t,r){this._key=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Cr.jwkToPkcs1(this._key)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ot(this.raw,t.raw)}sign(t){return sa(this._key,t)}};var li=8192,di=18,ud=1062,fd=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function ua(e){let t=Tr(e);return{n:et(t[1],"base64url"),e:et(t[2],"base64url"),d:et(t[3],"base64url"),p:et(t[4],"base64url"),q:et(t[5],"base64url"),dp:et(t[6],"base64url"),dq:et(t[7],"base64url"),qi:et(t[8],"base64url"),kty:"RSA"}}function ld(e){if(e.n==null||e.e==null||e.d==null||e.p==null||e.q==null||e.dp==null||e.dq==null||e.qi==null)throw new mt("JWK was missing components");return yn([Nt(Uint8Array.from([0])),Nt(W(e.n,"base64url")),Nt(W(e.e,"base64url")),Nt(W(e.d,"base64url")),Nt(W(e.p,"base64url")),Nt(W(e.q,"base64url")),Nt(W(e.dp,"base64url")),Nt(W(e.dq,"base64url")),Nt(W(e.qi,"base64url"))]).subarray()}function fa(e){let t=Tr(e,{offset:0});return{kty:"RSA",n:et(t[1][0],"base64url"),e:et(t[1][1],"base64url")}}function hi(e){if(e.n==null||e.e==null)throw new mt("JWK was missing components");return yn([fd,na(yn([Nt(W(e.n,"base64url")),Nt(W(e.e,"base64url"))]))]).subarray()}function la(e){let t=ua(e);return da(t)}function pi(e,t){if(e.byteLength>=ud)throw new ze("Key size is too large");let r=fa(e);if(t==null){let n=or(Zt.encode({Type:st.RSA,Data:e}));t=Pt(di,n)}return new ir(r,t)}function da(e){if(ca(e)>li)throw new mt("Key size is too large");let t=pa(e),r=or(Zt.encode({Type:st.RSA,Data:hi(t.publicKey)})),n=Pt(di,r);return new Ur(t.privateKey,new ir(t.publicKey,n))}async function ha(e){if(e>li)throw new mt("Key size is too large");let t=await ia(e),r=or(Zt.encode({Type:st.RSA,Data:hi(t.publicKey)})),n=Pt(di,r);return new Ur(t.privateKey,new ir(t.publicKey,n))}function pa(e){if(e==null)throw new mt("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}var wn=class extends Qe{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,ls(t);let n=yr(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),i.fill(0)}update(t){return Je(this),this.iHash.update(t),this}digestInto(t){Je(this),je(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}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},mi=(e,t,r)=>new wn(e,t).update(r).digest();mi.create=(e,t)=>new wn(e,t);function ma(e){e.lowS!==void 0&&Ot("lowS",e.lowS),e.prehash!==void 0&&Ot("prehash",e.prehash)}function dd(e){let t=br(e);Gt(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:r,Fp:n,a:o}=t;if(r){if(!n.eql(o,n.ZERO))throw new Error("invalid endomorphism, can only be defined for Koblitz curves that have a=0");if(typeof r!="object"||typeof r.beta!="bigint"||typeof r.splitScalar!="function")throw new Error("invalid endomorphism, expected beta: bigint and splitScalar: function")}return Object.freeze({...t})}var{bytesToNumberBE:hd,hexToBytes:pd}=rn,gi=class extends Error{constructor(t=""){super(t)}},oe={Err:gi,_tlv:{encode:(e,t)=>{let{Err:r}=oe;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=Ne(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let i=n>127?Ne(o.length/2|128):"";return Ne(e)+i+o+t},decode(e,t){let{Err:r}=oe,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 f=t.subarray(n,n+u);if(f.length!==u)throw new r("tlv.decode: length bytes not complete");if(f[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let c of f)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}=oe;if(e<ie)throw new t("integer: negative integers are not allowed");let r=Ne(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}=oe;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 hd(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=oe,o=typeof e=="string"?pd(e):e;er(o);let{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:f,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(f)}},hexFromSig(e){let{_tlv:t,_int:r}=oe,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),i=n+o;return t.encode(48,i)}},ie=BigInt(0),ut=BigInt(1),ng=BigInt(2),ga=BigInt(3),og=BigInt(4);function md(e){let t=dd(e),{Fp:r}=t,n=we(t.n,t.nBitLength),o=t.toBytes||((y,h,S)=>{let C=h.toAffine();return ne(Uint8Array.from([4]),r.toBytes(C.x),r.toBytes(C.y))}),i=t.fromBytes||(y=>{let h=y.subarray(1),S=r.fromBytes(h.subarray(0,r.BYTES)),C=r.fromBytes(h.subarray(r.BYTES,2*r.BYTES));return{x:S,y:C}});function s(y){let{a:h,b:S}=t,C=r.sqr(y),x=r.mul(C,y);return r.add(r.add(x,r.mul(y,h)),S)}if(!r.eql(r.sqr(t.Gy),s(t.Gx)))throw new Error("bad generator point: equation left != right");function a(y){return xr(y,ut,t.n)}function u(y){let{allowedPrivateKeyLengths:h,nByteLength:S,wrapPrivateKey:C,n:x}=t;if(h&&typeof y!="bigint"){if(ge(y)&&(y=ee(y)),typeof y!="string"||!h.includes(y.length))throw new Error("invalid private key");y=y.padStart(S*2,"0")}let _;try{_=typeof y=="bigint"?y:re(rt("private key",y,S))}catch{throw new Error("invalid private key, expected hex or "+S+" bytes, got "+typeof y)}return C&&(_=Y(_,x)),At("private key",_,ut,x),_}function f(y){if(!(y instanceof d))throw new Error("ProjectivePoint expected")}let c=ke((y,h)=>{let{px:S,py:C,pz:x}=y;if(r.eql(x,r.ONE))return{x:S,y:C};let _=y.is0();h==null&&(h=_?r.ONE:r.inv(x));let P=r.mul(S,h),k=r.mul(C,h),N=r.mul(x,h);if(_)return{x:r.ZERO,y:r.ZERO};if(!r.eql(N,r.ONE))throw new Error("invZ was invalid");return{x:P,y:k}}),l=ke(y=>{if(y.is0()){if(t.allowInfinityPoint&&!r.is0(y.py))return;throw new Error("bad point: ZERO")}let{x:h,y:S}=y.toAffine();if(!r.isValid(h)||!r.isValid(S))throw new Error("bad point: x or y not FE");let C=r.sqr(S),x=s(h);if(!r.eql(C,x))throw new Error("bad point: equation left != right");if(!y.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class d{constructor(h,S,C){if(this.px=h,this.py=S,this.pz=C,h==null||!r.isValid(h))throw new Error("x required");if(S==null||!r.isValid(S))throw new Error("y required");if(C==null||!r.isValid(C))throw new Error("z required");Object.freeze(this)}static fromAffine(h){let{x:S,y:C}=h||{};if(!h||!r.isValid(S)||!r.isValid(C))throw new Error("invalid affine point");if(h instanceof d)throw new Error("projective point not allowed");let x=_=>r.eql(_,r.ZERO);return x(S)&&x(C)?d.ZERO:new d(S,C,r.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){let S=r.invertBatch(h.map(C=>C.pz));return h.map((C,x)=>C.toAffine(S[x])).map(d.fromAffine)}static fromHex(h){let S=d.fromAffine(i(rt("pointHex",h)));return S.assertValidity(),S}static fromPrivateKey(h){return d.BASE.multiply(u(h))}static msm(h,S){return an(d,n,h,S)}_setWindowSize(h){A.setWindowSize(this,h)}assertValidity(){l(this)}hasEvenY(){let{y:h}=this.toAffine();if(r.isOdd)return!r.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){f(h);let{px:S,py:C,pz:x}=this,{px:_,py:P,pz:k}=h,N=r.eql(r.mul(S,k),r.mul(_,x)),w=r.eql(r.mul(C,k),r.mul(P,x));return N&&w}negate(){return new d(this.px,r.neg(this.py),this.pz)}double(){let{a:h,b:S}=t,C=r.mul(S,ga),{px:x,py:_,pz:P}=this,k=r.ZERO,N=r.ZERO,w=r.ZERO,b=r.mul(x,x),F=r.mul(_,_),L=r.mul(P,P),U=r.mul(x,_);return U=r.add(U,U),w=r.mul(x,P),w=r.add(w,w),k=r.mul(h,w),N=r.mul(C,L),N=r.add(k,N),k=r.sub(F,N),N=r.add(F,N),N=r.mul(k,N),k=r.mul(U,k),w=r.mul(C,w),L=r.mul(h,L),U=r.sub(b,L),U=r.mul(h,U),U=r.add(U,w),w=r.add(b,b),b=r.add(w,b),b=r.add(b,L),b=r.mul(b,U),N=r.add(N,b),L=r.mul(_,P),L=r.add(L,L),b=r.mul(L,U),k=r.sub(k,b),w=r.mul(L,F),w=r.add(w,w),w=r.add(w,w),new d(k,N,w)}add(h){f(h);let{px:S,py:C,pz:x}=this,{px:_,py:P,pz:k}=h,N=r.ZERO,w=r.ZERO,b=r.ZERO,F=t.a,L=r.mul(t.b,ga),U=r.mul(S,_),V=r.mul(C,P),v=r.mul(x,k),B=r.add(S,C),g=r.add(_,P);B=r.mul(B,g),g=r.add(U,V),B=r.sub(B,g),g=r.add(S,x);let p=r.add(_,k);return g=r.mul(g,p),p=r.add(U,v),g=r.sub(g,p),p=r.add(C,x),N=r.add(P,k),p=r.mul(p,N),N=r.add(V,v),p=r.sub(p,N),b=r.mul(F,g),N=r.mul(L,v),b=r.add(N,b),N=r.sub(V,b),b=r.add(V,b),w=r.mul(N,b),V=r.add(U,U),V=r.add(V,U),v=r.mul(F,v),g=r.mul(L,g),V=r.add(V,v),v=r.sub(U,v),v=r.mul(F,v),g=r.add(g,v),U=r.mul(V,g),w=r.add(w,U),U=r.mul(p,g),N=r.mul(B,N),N=r.sub(N,U),U=r.mul(B,V),b=r.mul(p,b),b=r.add(b,U),new d(N,w,b)}subtract(h){return this.add(h.negate())}is0(){return this.equals(d.ZERO)}wNAF(h){return A.wNAFCached(this,h,d.normalizeZ)}multiplyUnsafe(h){let{endo:S,n:C}=t;At("scalar",h,ie,C);let x=d.ZERO;if(h===ie)return x;if(this.is0()||h===ut)return this;if(!S||A.hasPrecomputes(this))return A.wNAFCachedUnsafe(this,h,d.normalizeZ);let{k1neg:_,k1:P,k2neg:k,k2:N}=S.splitScalar(h),w=x,b=x,F=this;for(;P>ie||N>ie;)P&ut&&(w=w.add(F)),N&ut&&(b=b.add(F)),F=F.double(),P>>=ut,N>>=ut;return _&&(w=w.negate()),k&&(b=b.negate()),b=new d(r.mul(b.px,S.beta),b.py,b.pz),w.add(b)}multiply(h){let{endo:S,n:C}=t;At("scalar",h,ut,C);let x,_;if(S){let{k1neg:P,k1:k,k2neg:N,k2:w}=S.splitScalar(h),{p:b,f:F}=this.wNAF(k),{p:L,f:U}=this.wNAF(w);b=A.constTimeNegate(P,b),L=A.constTimeNegate(N,L),L=new d(r.mul(L.px,S.beta),L.py,L.pz),x=b.add(L),_=F.add(U)}else{let{p:P,f:k}=this.wNAF(h);x=P,_=k}return d.normalizeZ([x,_])[0]}multiplyAndAddUnsafe(h,S,C){let x=d.BASE,_=(k,N)=>N===ie||N===ut||!k.equals(x)?k.multiplyUnsafe(N):k.multiply(N),P=_(this,S).add(_(h,C));return P.is0()?void 0:P}toAffine(h){return c(this,h)}isTorsionFree(){let{h,isTorsionFree:S}=t;if(h===ut)return!0;if(S)return S(d,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:S}=t;return h===ut?this:S?S(d,this):this.multiplyUnsafe(t.h)}toRawBytes(h=!0){return Ot("isCompressed",h),this.assertValidity(),o(d,this,h)}toHex(h=!0){return Ot("isCompressed",h),ee(this.toRawBytes(h))}}d.BASE=new d(t.Gx,t.Gy,r.ONE),d.ZERO=new d(r.ZERO,r.ONE,r.ZERO);let T=t.nBitLength,A=sn(d,t.endo?Math.ceil(T/2):T);return{CURVE:t,ProjectivePoint:d,normPrivateKeyToScalar:u,weierstrassEquation:s,isWithinCurveOrder:a}}function gd(e){let t=br(e);return Gt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function ya(e){let t=gd(e),{Fp:r,n}=t,o=r.BYTES+1,i=2*r.BYTES+1;function s(v){return Y(v,n)}function a(v){return nn(v,n)}let{ProjectivePoint:u,normPrivateKeyToScalar:f,weierstrassEquation:c,isWithinCurveOrder:l}=md({...t,toBytes(v,B,g){let p=B.toAffine(),E=r.toBytes(p.x),R=ne;return Ot("isCompressed",g),g?R(Uint8Array.from([B.hasEvenY()?2:3]),E):R(Uint8Array.from([4]),E,r.toBytes(p.y))},fromBytes(v){let B=v.length,g=v[0],p=v.subarray(1);if(B===o&&(g===2||g===3)){let E=re(p);if(!xr(E,ut,r.ORDER))throw new Error("Point is not on curve");let R=c(E),O;try{O=r.sqrt(R)}catch($){let q=$ instanceof Error?": "+$.message:"";throw new Error("Point is not on curve"+q)}let M=(O&ut)===ut;return(g&1)===1!==M&&(O=r.neg(O)),{x:E,y:O}}else if(B===i&&g===4){let E=r.fromBytes(p.subarray(0,r.BYTES)),R=r.fromBytes(p.subarray(r.BYTES,2*r.BYTES));return{x:E,y:R}}else{let E=o,R=i;throw new Error("invalid Point, expected length of "+E+", or uncompressed "+R+", got "+B)}}}),d=v=>ee(xe(v,t.nByteLength));function T(v){let B=n>>ut;return v>B}function A(v){return T(v)?s(-v):v}let y=(v,B,g)=>re(v.slice(B,g));class h{constructor(B,g,p){this.r=B,this.s=g,this.recovery=p,this.assertValidity()}static fromCompact(B){let g=t.nByteLength;return B=rt("compactSignature",B,g*2),new h(y(B,0,g),y(B,g,2*g))}static fromDER(B){let{r:g,s:p}=oe.toSig(rt("DER",B));return new h(g,p)}assertValidity(){At("r",this.r,ut,n),At("s",this.s,ut,n)}addRecoveryBit(B){return new h(this.r,this.s,B)}recoverPublicKey(B){let{r:g,s:p,recovery:E}=this,R=k(rt("msgHash",B));if(E==null||![0,1,2,3].includes(E))throw new Error("recovery id invalid");let O=E===2||E===3?g+t.n:g;if(O>=r.ORDER)throw new Error("recovery id 2 or 3 invalid");let M=(E&1)===0?"02":"03",z=u.fromHex(M+d(O)),$=a(O),q=s(-R*$),Z=s(p*$),X=u.BASE.multiplyAndAddUnsafe(z,q,Z);if(!X)throw new Error("point at infinify");return X.assertValidity(),X}hasHighS(){return T(this.s)}normalizeS(){return this.hasHighS()?new h(this.r,s(-this.s),this.recovery):this}toDERRawBytes(){return Le(this.toDERHex())}toDERHex(){return oe.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Le(this.toCompactHex())}toCompactHex(){return d(this.r)+d(this.s)}}let S={isValidPrivateKey(v){try{return f(v),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{let v=Uo(t.n);return vs(t.randomBytes(v),t.n)},precompute(v=8,B=u.BASE){return B._setWindowSize(v),B.multiply(BigInt(3)),B}};function C(v,B=!0){return u.fromPrivateKey(v).toRawBytes(B)}function x(v){let B=ge(v),g=typeof v=="string",p=(B||g)&&v.length;return B?p===o||p===i:g?p===2*o||p===2*i:v instanceof u}function _(v,B,g=!0){if(x(v))throw new Error("first arg must be private key");if(!x(B))throw new Error("second arg must be public key");return u.fromHex(B).multiply(f(v)).toRawBytes(g)}let P=t.bits2int||function(v){if(v.length>8192)throw new Error("input is too large");let B=re(v),g=v.length*8-t.nBitLength;return g>0?B>>BigInt(g):B},k=t.bits2int_modN||function(v){return s(P(v))},N=wr(t.nBitLength);function w(v){return At("num < 2^"+t.nBitLength,v,ie,N),xe(v,t.nByteLength)}function b(v,B,g=F){if(["recovered","canonical"].some(ct=>ct in g))throw new Error("sign() legacy options not supported");let{hash:p,randomBytes:E}=t,{lowS:R,prehash:O,extraEntropy:M}=g;R==null&&(R=!0),v=rt("msgHash",v),ma(g),O&&(v=rt("prehashed msgHash",p(v)));let z=k(v),$=f(B),q=[w($),w(z)];if(M!=null&&M!==!1){let ct=M===!0?E(r.BYTES):M;q.push(rt("extraEntropy",ct))}let Z=ne(...q),X=z;function at(ct){let lt=P(ct);if(!l(lt))return;let pt=a(lt),Et=u.BASE.multiply(lt).toAffine(),xt=s(Et.x);if(xt===ie)return;let $t=s(pt*s(X+xt*$));if($t===ie)return;let Xt=(Et.x===xt?0:2)|Number(Et.y&ut),dr=$t;return R&&T($t)&&(dr=A($t),Xt^=1),new h(xt,dr,Xt)}return{seed:Z,k2sig:at}}let F={lowS:t.lowS,prehash:!1},L={lowS:t.lowS,prehash:!1};function U(v,B,g=F){let{seed:p,k2sig:E}=b(v,B,g),R=t;return Bo(R.hash.outputLen,R.nByteLength,R.hmac)(p,E)}u.BASE._setWindowSize(8);function V(v,B,g,p=L){let E=v;B=rt("msgHash",B),g=rt("publicKey",g);let{lowS:R,prehash:O,format:M}=p;if(ma(p),"strict"in p)throw new Error("options.strict was renamed to lowS");if(M!==void 0&&M!=="compact"&&M!=="der")throw new Error("format must be compact or der");let z=typeof E=="string"||ge(E),$=!z&&!M&&typeof E=="object"&&E!==null&&typeof E.r=="bigint"&&typeof E.s=="bigint";if(!z&&!$)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let q,Z;try{if($&&(q=new h(E.r,E.s)),z){try{M!=="compact"&&(q=h.fromDER(E))}catch(Xt){if(!(Xt instanceof oe.Err))throw Xt}!q&&M!=="der"&&(q=h.fromCompact(E))}Z=u.fromHex(g)}catch{return!1}if(!q||R&&q.hasHighS())return!1;O&&(B=t.hash(B));let{r:X,s:at}=q,ct=k(B),lt=a(at),pt=s(ct*lt),Et=s(X*lt),xt=u.BASE.multiplyAndAddUnsafe(Z,pt,Et)?.toAffine();return xt?s(xt.x)===X:!1}return{CURVE:t,getPublicKey:C,getSharedSecret:_,sign:U,verify:V,ProjectivePoint:u,Signature:h,utils:S}}function yd(e){return{hash:e,hmac:(t,...r)=>mi(e,t,xo(...r)),randomBytes:Jr}}function xa(e,t){let r=n=>ya({...e,...yd(n)});return{...r(t),create:r}}var Ea=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),wa=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),xd=BigInt(1),yi=BigInt(2),ba=(e,t)=>(e+t/yi)/t;function wd(e){let t=Ea,r=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),u=BigInt(88),f=e*e*e%t,c=f*f*e%t,l=tt(c,r,t)*c%t,d=tt(l,r,t)*c%t,T=tt(d,yi,t)*f%t,A=tt(T,o,t)*T%t,y=tt(A,i,t)*A%t,h=tt(y,a,t)*y%t,S=tt(h,u,t)*h%t,C=tt(S,a,t)*y%t,x=tt(C,r,t)*c%t,_=tt(x,s,t)*A%t,P=tt(_,n,t)*f%t,k=tt(P,yi,t);if(!xi.eql(xi.sqr(k),e))throw new Error("Cannot find square root");return k}var xi=we(Ea,void 0,void 0,{sqrt:wd}),Me=xa({a:BigInt(0),b:BigInt(7),Fp:xi,n:wa,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{let t=wa,r=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-xd*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=r,s=BigInt("0x100000000000000000000000000000000"),a=ba(i*e,t),u=ba(-n*e,t),f=Y(e-a*r-u*o,t),c=Y(-a*n-u*i,t),l=f>s,d=c>s;if(l&&(f=t-f),d&&(c=t-c),f>s||c>s)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:l,k1:f,k2neg:d,k2:c}}}},or),hg=BigInt(0);var pg=Me.ProjectivePoint;function Sa(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}function Aa(e,t,r){let n=Sr.digest(r instanceof Uint8Array?r:r.subarray());if(Sa(n))return n.then(({digest:o})=>Me.verify(t,o,e)).catch(o=>{throw new Ir(String(o))});try{return Me.verify(t,n.digest,e)}catch(o){throw new Ir(String(o))}}var bn=class{type="secp256k1";raw;_key;constructor(t){this._key=Ba(t),this.raw=va(this._key)}toMultihash(){return Qt.digest(rr(this))}toCID(){return J.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ot(this.raw,t.raw)}verify(t,r){return Aa(this._key,r,t)}};function wi(e){return new bn(e)}function va(e){return Me.ProjectivePoint.fromHex(e).toRawBytes(!0)}function Ba(e){try{return Me.ProjectivePoint.fromHex(e),e}catch(t){throw new ze(String(t))}}function Ta(e,t){let{Type:r,Data:n}=Zt.decode(e),o=n??new Uint8Array;switch(r){case st.RSA:return pi(o,t);case st.Ed25519:return Po(o);case st.secp256k1:return wi(o);default:throw new Ge}}function En(e){let{Type:t,Data:r}=Zt.decode(e.digest),n=r??new Uint8Array;switch(t){case st.Ed25519:return Po(n);case st.secp256k1:return wi(n);default:throw new Ge}}function rr(e){return Zt.encode({Type:st[e.type],Data:e.raw})}var Ia=Symbol.for("nodejs.util.inspect.custom"),bd=114,Rr=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()})`}[no]=!0;toString(){return this.string==null&&(this.string=j.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return J.createV1(bd,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return ot(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return ot(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Ia](){return`PeerId(${this.toString()})`}},Sn=class extends Rr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},An=class extends Rr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},vn=class extends Rr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Ed=2336,_r=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Qt.digest(W(this.url))}[Ia](){return`PeerId(${this.url})`}[no]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return J.createV1(Ed,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=et(t)),t.toString()===this.toString())}};var Sd=114,Ca=2336;function Bn(e,t){let r;if(e.charAt(0)==="1"||e.charAt(0)==="Q")r=Jt(j.decode(`z${e}`));else{if(e.startsWith("k51qzi5uqu5")||e.startsWith("kzwfwjn5ji4")||e.startsWith("k2k4r8")||e.startsWith("bafz"))return bi(J.parse(e));if(t==null)throw new mt('Please pass a multibase decoder for strings that do not start with "1" or "Q"');r=Jt(t.decode(e))}return Ua(r)}function Ua(e){if(vd(e))return new Sn({multihash:e});if(Ad(e))try{let t=En(e);if(t.type==="Ed25519")return new An({multihash:e,publicKey:t});if(t.type==="secp256k1")return new vn({multihash:e,publicKey:t})}catch{let r=et(e.digest);return new _r(new URL(r))}throw new $e("Supplied PeerID Multihash is invalid")}function bi(e){if(e?.multihash==null||e.version==null||e.version===1&&e.code!==Sd&&e.code!==Ca)throw new $r("Supplied PeerID CID is invalid");if(e.code===Ca){let t=et(e.multihash.digest);return new _r(new URL(t))}return Ua(e.multihash)}function Ad(e){return e.code===Qt.code}function vd(e){return e.code===Sr.code}var se="/",Ra=new TextEncoder().encode(se),Tn=Ra[0],Nr=class e{_buf;constructor(t,r){if(typeof t=="string")this._buf=W(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]!==Tn)throw new Error("Invalid key")}toString(t="utf8"){return et(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=Ra),this._buf[0]!==Tn){let t=new Uint8Array(this._buf.byteLength+1);t.fill(Tn,0,1),t.set(this._buf,1),this._buf=t}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===Tn;)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 Bd(this.baseNamespace())}name(){return Td(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(),...Id(t.map(r=>r.namespaces()))])}};function Bd(e){let t=e.split(":");return t.length<2?"":t.slice(0,-1).join(":")}function Td(e){let t=e.split(":");return t[t.length-1]}function Id(e){return[].concat(...e)}var qc=zr(In(),1);var Cn=class extends Error{static name="SignatureCreationError";constructor(t="Record signature creation failed"){super(t),this.name="SignatureCreationError"}},qt=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"}},Ke=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"}},Lr=class extends Error{static name="InvalidValueError";constructor(t="Value must be a valid content path starting with /"){super(t),this.name="InvalidValueError"}},_n=class extends Error{static name="InvalidRecordDataError";constructor(t="Invalid record data"){super(t),this.name="InvalidRecordDataError"}},Dr=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=()=>Br(r)}(t=e.ValidityType||(e.ValidityType={}));let n;e.codec=()=>(n==null&&(n=ve((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 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=>Ae(o,e.codec()),e.decode=(o,i)=>Se(o,e.codec(),i)})(dt||(dt={}));var Cd=["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 _a(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(Rd(e))return"Buffer";let r=_d(e);return r||"Object"}function Rd(e){return e&&e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer.call(null,e)}function _d(e){let t=Object.prototype.toString.call(e).slice(8,-1);if(Ud.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 D=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,Ld=new TextEncoder;function Nn(e){return sr&&globalThis.Buffer.isBuffer(e)}function Si(e){return e instanceof Uint8Array?Nn(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e:Uint8Array.from(e)}var ka=sr?(e,t,r)=>r-t>64?globalThis.Buffer.from(e.subarray(t,r)).toString("utf8"):La(e,t,r):(e,t,r)=>r-t>64?Nd.decode(e.subarray(t,r)):La(e,t,r),Pa=sr?e=>e.length>64?globalThis.Buffer.from(e):Na(e):e=>e.length>64?Ld.encode(e):Na(e),Wt=e=>Uint8Array.from(e),ar=sr?(e,t,r)=>Nn(e)?new Uint8Array(e.subarray(t,r)):e.slice(t,r):(e,t,r)=>e.slice(t,r),Fa=sr?(e,t)=>(e=e.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),Si(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},Oa=sr?e=>globalThis.Buffer.allocUnsafe(e):e=>new Uint8Array(e);function Ma(e,t){if(Nn(e)&&Nn(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 Na(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 La(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,f,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],f=e[t+3],(a&192)===128&&(u&192)===128&&(f&192)===128&&(c=(o&15)<<18|(a&63)<<12|(u&63)<<6|f&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 Dd(n)}var Da=4096;function Dd(e){let t=e.length;if(t<=Da)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=Da));return r}var kd=256,kr=class{constructor(t=kd){this.chunkSize=t,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(t){let r=this.chunks[this.chunks.length-1];if(this.cursor+t.length<=this.maxCursor+1){let o=r.length-(this.maxCursor-this.cursor)-1;r.set(t,o)}else{if(r){let o=r.length-(this.maxCursor-this.cursor)-1;o<r.length&&(this.chunks[this.chunks.length-1]=r.subarray(0,o),this.maxCursor=this.cursor-1)}t.length<64&&t.length<this.chunkSize?(r=Oa(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=Fa(this.chunks,this.cursor);return t&&this.reset(),r}};var K="CBOR decode error:",Ai="CBOR encode error:",Pr=[];Pr[23]=1;Pr[24]=2;Pr[25]=3;Pr[26]=5;Pr[27]=9;function ae(e,t,r){if(e.length-t<r)throw new Error(`${K} not enough data for type`)}var ft=[24,256,65536,4294967296,BigInt("18446744073709551616")];function It(e,t,r){ae(e,t,1);let n=e[t];if(r.strict===!0&&n<ft[0])throw new Error(`${K} integer encoded in more bytes than necessary (strict decode)`);return n}function Ct(e,t,r){ae(e,t,2);let n=e[t]<<8|e[t+1];if(r.strict===!0&&n<ft[1])throw new Error(`${K} integer encoded in more bytes than necessary (strict decode)`);return n}function Ut(e,t,r){ae(e,t,4);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];if(r.strict===!0&&n<ft[2])throw new Error(`${K} integer encoded in more bytes than necessary (strict decode)`);return n}function Rt(e,t,r){ae(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<ft[3])throw new Error(`${K} 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(`${K} integers outside of the safe integer range are not supported`)}function Ka(e,t,r,n){return new D(m.uint,It(e,t+1,n),2)}function Va(e,t,r,n){return new D(m.uint,Ct(e,t+1,n),3)}function qa(e,t,r,n){return new D(m.uint,Ut(e,t+1,n),5)}function Ha(e,t,r,n){return new D(m.uint,Rt(e,t+1,n),9)}function Lt(e,t){return ht(e,0,t.value)}function ht(e,t,r){if(r<ft[0]){let n=Number(r);e.push([t|n])}else if(r<ft[1]){let n=Number(r);e.push([t|24,n])}else if(r<ft[2]){let n=Number(r);e.push([t|25,n>>>8,n&255])}else if(r<ft[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<ft[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(`${K} encountered BigInt larger than allowable range`)}}Lt.encodedSize=function(t){return ht.encodedSize(t.value)};ht.encodedSize=function(t){return t<ft[0]?1:t<ft[1]?2:t<ft[2]?3:t<ft[3]?5:9};Lt.compareTokens=function(t,r){return t.value<r.value?-1:t.value>r.value?1:0};function za(e,t,r,n){return new D(m.negint,-1-It(e,t+1,n),2)}function $a(e,t,r,n){return new D(m.negint,-1-Ct(e,t+1,n),3)}function Ga(e,t,r,n){return new D(m.negint,-1-Ut(e,t+1,n),5)}var vi=BigInt(-1),Za=BigInt(1);function Wa(e,t,r,n){let o=Rt(e,t+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new D(m.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${K} integers outside of the safe integer range are not supported`);return new D(m.negint,vi-BigInt(o),9)}function Ln(e,t){let r=t.value,n=typeof r=="bigint"?r*vi-Za:r*-1-1;ht(e,t.type.majorEncoded,n)}Ln.encodedSize=function(t){let r=t.value,n=typeof r=="bigint"?r*vi-Za:r*-1-1;return n<ft[0]?1:n<ft[1]?2:n<ft[2]?3:n<ft[3]?5:9};Ln.compareTokens=function(t,r){return t.value<r.value?1:t.value>r.value?-1:0};function Fr(e,t,r,n){ae(e,t,r+n);let o=ar(e,t+r,t+r+n);return new D(m.bytes,o,r+n)}function Ya(e,t,r,n){return Fr(e,t,1,r)}function Xa(e,t,r,n){return Fr(e,t,2,It(e,t+1,n))}function ja(e,t,r,n){return Fr(e,t,3,Ct(e,t+1,n))}function Ja(e,t,r,n){return Fr(e,t,5,Ut(e,t+1,n))}function Qa(e,t,r,n){let o=Rt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${K} 64-bit integer bytes lengths not supported`);return Fr(e,t,9,o)}function Dn(e){return e.encodedBytes===void 0&&(e.encodedBytes=e.type===m.string?Pa(e.value):e.value),e.encodedBytes}function cr(e,t){let r=Dn(t);ht(e,t.type.majorEncoded,r.length),e.push(r)}cr.encodedSize=function(t){let r=Dn(t);return ht.encodedSize(r.length)+r.length};cr.compareTokens=function(t,r){return Fd(Dn(t),Dn(r))};function Fd(e,t){return e.length<t.length?-1:e.length>t.length?1:Ma(e,t)}function Or(e,t,r,n,o){let i=r+n;ae(e,t,i);let s=new D(m.string,ka(e,t+r,t+i),i);return o.retainStringBytes===!0&&(s.byteValue=ar(e,t+r,t+i)),s}function tc(e,t,r,n){return Or(e,t,1,r,n)}function ec(e,t,r,n){return Or(e,t,2,It(e,t+1,n),n)}function rc(e,t,r,n){return Or(e,t,3,Ct(e,t+1,n),n)}function nc(e,t,r,n){return Or(e,t,5,Ut(e,t+1,n),n)}function oc(e,t,r,n){let o=Rt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${K} 64-bit integer string lengths not supported`);return Or(e,t,9,o,n)}var ic=cr;function ur(e,t,r,n){return new D(m.array,n,r)}function sc(e,t,r,n){return ur(e,t,1,r)}function ac(e,t,r,n){return ur(e,t,2,It(e,t+1,n))}function cc(e,t,r,n){return ur(e,t,3,Ct(e,t+1,n))}function uc(e,t,r,n){return ur(e,t,5,Ut(e,t+1,n))}function fc(e,t,r,n){let o=Rt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${K} 64-bit integer array lengths not supported`);return ur(e,t,9,o)}function lc(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${K} indefinite length items not allowed`);return ur(e,t,1,1/0)}function kn(e,t){ht(e,m.array.majorEncoded,t.value)}kn.compareTokens=Lt.compareTokens;kn.encodedSize=function(t){return ht.encodedSize(t.value)};function fr(e,t,r,n){return new D(m.map,n,r)}function dc(e,t,r,n){return fr(e,t,1,r)}function hc(e,t,r,n){return fr(e,t,2,It(e,t+1,n))}function pc(e,t,r,n){return fr(e,t,3,Ct(e,t+1,n))}function mc(e,t,r,n){return fr(e,t,5,Ut(e,t+1,n))}function gc(e,t,r,n){let o=Rt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${K} 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(`${K} indefinite length items not allowed`);return fr(e,t,1,1/0)}function Pn(e,t){ht(e,m.map.majorEncoded,t.value)}Pn.compareTokens=Lt.compareTokens;Pn.encodedSize=function(t){return ht.encodedSize(t.value)};function xc(e,t,r,n){return new D(m.tag,r,1)}function wc(e,t,r,n){return new D(m.tag,It(e,t+1,n),2)}function bc(e,t,r,n){return new D(m.tag,Ct(e,t+1,n),3)}function Ec(e,t,r,n){return new D(m.tag,Ut(e,t+1,n),5)}function Sc(e,t,r,n){return new D(m.tag,Rt(e,t+1,n),9)}function Fn(e,t){ht(e,m.tag.majorEncoded,t.value)}Fn.compareTokens=Lt.compareTokens;Fn.encodedSize=function(t){return ht.encodedSize(t.value)};var Hd=20,zd=21,$d=22,Gd=23;function Ac(e,t,r,n){if(n.allowUndefined===!1)throw new Error(`${K} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new D(m.null,null,1):new D(m.undefined,void 0,1)}function vc(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${K} indefinite length items not allowed`);return new D(m.break,void 0,1)}function Bi(e,t,r){if(r){if(r.allowNaN===!1&&Number.isNaN(e))throw new Error(`${K} NaN values are not supported`);if(r.allowInfinity===!1&&(e===1/0||e===-1/0))throw new Error(`${K} Infinity values are not supported`)}return new D(m.float,e,t)}function Bc(e,t,r,n){return Bi(Ti(e,t+1),3,n)}function Tc(e,t,r,n){return Bi(Ii(e,t+1),5,n)}function Ic(e,t,r,n){return Bi(_c(e,t+1),9,n)}function On(e,t,r){let n=t.value;if(n===!1)e.push([m.float.majorEncoded|Hd]);else if(n===!0)e.push([m.float.majorEncoded|zd]);else if(n===null)e.push([m.float.majorEncoded|$d]);else if(n===void 0)e.push([m.float.majorEncoded|Gd]);else{let o,i=!1;(!r||r.float64!==!0)&&(Uc(n),o=Ti(Ht,1),n===o||Number.isNaN(n)?(Ht[0]=249,e.push(Ht.slice(0,3)),i=!0):(Rc(n),o=Ii(Ht,1),n===o&&(Ht[0]=250,e.push(Ht.slice(0,5)),i=!0))),i||(Zd(n),o=_c(Ht,1),Ht[0]=251,e.push(Ht.slice(0,9)))}}On.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){Uc(n);let o=Ti(Ht,1);if(n===o||Number.isNaN(n))return 3;if(Rc(n),o=Ii(Ht,1),n===o)return 5}return 9};var Cc=new ArrayBuffer(9),Dt=new DataView(Cc,1),Ht=new Uint8Array(Cc,0);function Uc(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 Ti(e,t){if(e.length-t<2)throw new Error(`${K} 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 Rc(e){Dt.setFloat32(0,e,!1)}function Ii(e,t){if(e.length-t<4)throw new Error(`${K} 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 _c(e,t){if(e.length-t<8)throw new Error(`${K} not enough data for float64`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,8).getFloat64(0,!1)}On.compareTokens=Lt.compareTokens;function G(e,t,r){throw new Error(`${K} encountered invalid minor (${r}) for major ${e[t]>>>5}`)}function Mn(e){return()=>{throw new Error(`${K} ${e}`)}}var I=[];for(let e=0;e<=23;e++)I[e]=G;I[24]=Ka;I[25]=Va;I[26]=qa;I[27]=Ha;I[28]=G;I[29]=G;I[30]=G;I[31]=G;for(let e=32;e<=55;e++)I[e]=G;I[56]=za;I[57]=$a;I[58]=Ga;I[59]=Wa;I[60]=G;I[61]=G;I[62]=G;I[63]=G;for(let e=64;e<=87;e++)I[e]=Ya;I[88]=Xa;I[89]=ja;I[90]=Ja;I[91]=Qa;I[92]=G;I[93]=G;I[94]=G;I[95]=Mn("indefinite length bytes/strings are not supported");for(let e=96;e<=119;e++)I[e]=tc;I[120]=ec;I[121]=rc;I[122]=nc;I[123]=oc;I[124]=G;I[125]=G;I[126]=G;I[127]=Mn("indefinite length bytes/strings are not supported");for(let e=128;e<=151;e++)I[e]=sc;I[152]=ac;I[153]=cc;I[154]=uc;I[155]=fc;I[156]=G;I[157]=G;I[158]=G;I[159]=lc;for(let e=160;e<=183;e++)I[e]=dc;I[184]=hc;I[185]=pc;I[186]=mc;I[187]=gc;I[188]=G;I[189]=G;I[190]=G;I[191]=yc;for(let e=192;e<=215;e++)I[e]=xc;I[216]=wc;I[217]=bc;I[218]=Ec;I[219]=Sc;I[220]=G;I[221]=G;I[222]=G;I[223]=G;for(let e=224;e<=243;e++)I[e]=Mn("simple values are not supported");I[244]=G;I[245]=G;I[246]=G;I[247]=Ac;I[248]=Mn("simple values are not supported");I[249]=Bc;I[250]=Tc;I[251]=Ic;I[252]=G;I[253]=G;I[254]=G;I[255]=vc;var zt=[];for(let e=0;e<24;e++)zt[e]=new D(m.uint,e,1);for(let e=-1;e>=-24;e--)zt[31-e]=new D(m.negint,e,1);zt[64]=new D(m.bytes,new Uint8Array(0),1);zt[96]=new D(m.string,"",1);zt[128]=new D(m.array,0,1);zt[160]=new D(m.map,0,1);zt[244]=new D(m.false,!1,1);zt[245]=new D(m.true,!0,1);zt[246]=new D(m.null,null,1);function Nc(e){switch(e.type){case m.false:return Wt([244]);case m.true:return Wt([245]);case m.null:return Wt([246]);case m.bytes:return e.value.length?void 0:Wt([64]);case m.string:return e.value===""?Wt([96]):void 0;case m.array:return e.value===0?Wt([128]):void 0;case m.map:return e.value===0?Wt([160]):void 0;case m.uint:return e.value<24?Wt([Number(e.value)]):void 0;case m.negint:if(e.value>=-24)return Wt([31-Number(e.value)])}}var Yd={float64:!1,mapSorter:Jd,quickEncodeToken:Nc};function Xd(){let e=[];return e[m.uint.major]=Lt,e[m.negint.major]=Ln,e[m.bytes.major]=cr,e[m.string.major]=ic,e[m.array.major]=kn,e[m.map.major]=Pn,e[m.tag.major]=Fn,e[m.float.major]=On,e}var Lc=Xd(),Ci=new kr,Vn=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(`${Ai} object contains circular references`);return new e(r,t)}},Ue={null:new D(m.null,null),undefined:new D(m.undefined,void 0),true:new D(m.true,!0),false:new D(m.false,!1),emptyArray:new D(m.array,0),emptyMap:new D(m.map,0)},Re={number(e,t,r,n){return!Number.isInteger(e)||!Number.isSafeInteger(e)?new D(m.float,e):e>=0?new D(m.uint,e):new D(m.negint,e)},bigint(e,t,r,n){return e>=BigInt(0)?new D(m.uint,e):new D(m.negint,e)},Uint8Array(e,t,r,n){return new D(m.bytes,e)},string(e,t,r,n){return new D(m.string,e)},boolean(e,t,r,n){return e?Ue.true:Ue.false},null(e,t,r,n){return Ue.null},undefined(e,t,r,n){return Ue.undefined},ArrayBuffer(e,t,r,n){return new D(m.bytes,new Uint8Array(e))},DataView(e,t,r,n){return new D(m.bytes,new Uint8Array(e.buffer,e.byteOffset,e.byteLength))},Array(e,t,r,n){if(!e.length)return r.addBreakTokens===!0?[Ue.emptyArray,new D(m.break)]:Ue.emptyArray;n=Vn.createCheck(n,e);let o=[],i=0;for(let s of e)o[i++]=Kn(s,r,n);return r.addBreakTokens?[new D(m.array,e.length),o,new D(m.break)]:[new D(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?[Ue.emptyMap,new D(m.break)]:Ue.emptyMap;n=Vn.createCheck(n,e);let a=[],u=0;for(let f of i)a[u++]=[Kn(f,r,n),Kn(o?e.get(f):e[f],r,n)];return jd(a,r),r.addBreakTokens?[new D(m.map,s),a,new D(m.break)]:[new D(m.map,s),a]}};Re.Map=Re.Object;Re.Buffer=Re.Uint8Array;for(let e of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))Re[`${e}Array`]=Re.DataView;function Kn(e,t={},r){let n=_a(e),o=t&&t.typeEncoders&&t.typeEncoders[n]||Re[n];if(typeof o=="function"){let s=o(e,n,t,r);if(s!=null)return s}let i=Re[n];if(!i)throw new Error(`${Ai} unsupported type: ${n}`);return i(e,n,t,r)}function jd(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=Lc[o].compareTokens(r,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function Dc(e,t,r,n){if(Array.isArray(t))for(let o of t)Dc(e,o,r,n);else r[t.type.major](e,t,n)}function Qd(e,t,r){let n=Kn(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 kr(s);if(i(a,n,r),a.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return Si(a.chunks[0])}}return Ci.reset(),Dc(Ci,n,t,r),Ci.toBytes(!0)}function Ui(e,t){return t=Object.assign({},Yd,t),Qd(e,Lc,t)}var th={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},qn=class{constructor(t,r={}){this._pos=0,this.data=t,this.options=r}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let t=this.data[this._pos],r=zt[t];if(r===void 0){let n=I[t];if(!n)throw new Error(`${K} 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}},Mr=Symbol.for("DONE"),Hn=Symbol.for("BREAK");function eh(e,t,r){let n=[];for(let o=0;o<e.value;o++){let i=lr(t,r);if(i===Hn){if(e.value===1/0)break;throw new Error(`${K} got unexpected break to lengthed array`)}if(i===Mr)throw new Error(`${K} 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=lr(t,r);if(a===Hn){if(e.value===1/0)break;throw new Error(`${K} got unexpected break to lengthed map`)}if(a===Mr)throw new Error(`${K} found map but not enough entries (got ${s} [no key], expected ${e.value})`);if(n!==!0&&typeof a!="string")throw new Error(`${K} non-string keys not supported (got ${typeof a})`);if(r.rejectDuplicateMapKeys===!0&&(n&&i.has(a)||!n&&a in o))throw new Error(`${K} found repeat map key "${a}"`);let u=lr(t,r);if(u===Mr)throw new Error(`${K} 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 lr(e,t){if(e.done())return Mr;let r=e.next();if(r.type===m.break)return Hn;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=lr(e,t);return t.tags[r.value](n)}throw new Error(`${K} tag not supported (${r.value})`)}throw new Error("unsupported")}function kc(e,t){if(!(e instanceof Uint8Array))throw new Error(`${K} data to decode must be a Uint8Array`);t=Object.assign({},th,t);let r=t.tokenizer||new qn(e,t),n=lr(r,t);if(n===Mr)throw new Error(`${K} did not find any content to decode`);if(n===Hn)throw new Error(`${K} got unexpected break`);return[n,e.subarray(r.pos())]}function Ri(e,t){let[r,n]=kc(e,t);if(n.length>0)throw new Error(`${K} too many terminals, data makes no sense`);return r}var oh=de("ipns:utils"),Pc=W("/ipns/"),ih=114,sh=0,ah=18;function Kr(e){let t;if(e.pubKey!=null)try{t=Ta(e.pubKey)}catch(r){throw oh.error(r),r}if(t!=null)return t}function Fc(e,t,r){let n=W(t);return Ie([e,r,n])}function $n(e){let t=W("ipns-signature:");return Ie([t,e])}function Gn(e){return"signatureV1"in e?dt.encode({value:W(e.value),signatureV1:e.signatureV1,validityType:e.validityType,validity:W(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 qt("Missing data or signatureV2");let r=Kc(t.data),n=ch(r.Value),o=et(r.Validity);if(t.value!=null&&t.signatureV1!=null)return uh(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 qe(e){return Ie([Pc,e.bytes])}function Oc(e){let t=Jt(e.slice(Pc.length));if(!zn(t,sh)&&!zn(t,ah))throw new $e("Multihash in IPNS key was not identity or sha2-256");return t}function Mc(e,t,r,n,o){let i;if(t===dt.ValidityType.EOL)i=0;else throw new Ke("The validity type is unsupported");return Ui({Value:e,Validity:r,ValidityType:i,Sequence:n,TTL:o})}function Kc(e){let t=Ri(e);if(t.ValidityType===0)t.ValidityType=dt.ValidityType.EOL;else throw new Ke("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=et(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 Lr("Value must be a valid content path starting with /")}function Vc(e){if(e!=null){let t=dh(e);if(t!=null)return t.code===ih?`/ipns/${t.toString(kt)}`:`/ipfs/${t.toV1().toString()}`;if(fh(e))return`/ipns/${kt.encode(e.bytes)}`;let r=e.toString().trim();if(r.startsWith("/")&&r.length>1)return r}throw new Lr("Value must be a valid content path starting with /")}function uh(e){if(e.data==null)throw new _n("Record data is missing");let t=Kc(e.data);if(!ot(t.Value,e.value??new Uint8Array(0)))throw new qt('Field "value" did not match between protobuf and CBOR');if(!ot(t.Validity,e.validity??new Uint8Array(0)))throw new qt('Field "validity" did not match between protobuf and CBOR');if(t.ValidityType!==e.validityType)throw new qt('Field "validityType" did not match between protobuf and CBOR');if(t.Sequence!==e.sequence)throw new qt('Field "sequence" did not match between protobuf and CBOR');if(t.TTL!==e.ttl)throw new qt('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 J.parse(e)}catch{}return J.asCID(e)}function zn(e,t){return e.code===t}var hh=de("ipns"),Hc=60*60*1e9,ph="/ipns/",Mx=ph.length,zc={v1Compatible:!0,ttlNs:Hc};async function $c(e,t,r,n,o=zc){let i=new qc.default(Date.now()+Number(n)),s=dt.ValidityType.EOL,a=BigInt(o.ttlNs??Hc);return mh(e,t,r,s,i.toString(),a,o)}var mh=async(e,t,r,n,o,i,s=zc)=>{r=BigInt(r);let a=W(o),u=Vc(t),f=W(u),c=Mc(f,n,a,r,i),l=$n(c),d=await e.sign(l),T;if(e.type==="RSA"&&(T=rr(e.publicKey)),s.v1Compatible===!0){let A=await gh(e,f,n,a),y={value:u,signatureV1:A,validity:o,validityType:n,sequence:r,ttl:i,signatureV2:d,data:c};return T!=null&&(y.pubKey=T),y}else{let A={value:u,validity:o,validityType:n,sequence:r,ttl:i,signatureV2:d,data:c};return T!=null&&(A.pubKey=T),A}},gh=async(e,t,r,n)=>{try{let o=Fc(t,r,n);return await e.sign(o)}catch(o){throw hh.error("record signature creation failed",o),new Cn("Record signature creation failed")}};var _i=zr(In(),1);function Zn(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=_i.default.fromString(n.record.validity).toDate(),u=_i.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 Gc=zr(In(),1);var Wn=de("ipns:validator"),yh=1024*10,xh=async(e,t)=>{let r=Yt(t),n;try{let o=$n(r.data);n=await e.verify(o,r.signatureV2)}catch{n=!1}if(!n)throw Wn.error("record signature verification failed"),new qt("Record signature verification failed");if(r.validityType===dt.ValidityType.EOL){if(Gc.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 Ke("The validity type is unsupported");Wn("ipns record for %s is valid",r.value)};async function Vr(e,t){if(t.byteLength>yh)throw new Rn("The record is too large");let r=Oc(e),n;zn(r,0)&&(n=En(r));let o=Yt(t),i=Kr(o)??n;if(i==null)throw new Dr("Could not extract public key from IPNS record or routing key");let s=qe(i.toMultihash());if(!ot(s,e))throw new Dr("Embedded public key did not match routing key");await xh(i,t)}var yt=class extends Event{type;detail;constructor(t,r){super(t),this.type=t,this.detail=r}};var Eh=zr(Wc(),1);var ce;(function(e){e[e.A=1]="A",e[e.CNAME=5]="CNAME",e[e.TXT=16]="TXT",e[e.AAAA=28]="AAAA"})(ce||(ce={}));var Yn=class extends Error{static name="DNSLinkNotFoundError";constructor(t="DNSLink not found"){super(t),this.name="DNSLinkNotFoundError"}},Xn=class extends Error{static name="RecordsFailedValidationError";constructor(t="Records failed validation"){super(t),this.name="RecordsFailedValidationError"}},jn=class extends Error{static name="UnsupportedMultibasePrefixError";constructor(t="Unsupported multibase prefix"){super(t),this.name="UnsupportedMultibasePrefixError"}},Jn=class extends Error{static name="UnsupportedMultihashCodecError";constructor(t="Unsupported multihash codec"){super(t),this.name="UnsupportedMultihashCodecError"}},Qn=class extends Error{static name="InvalidValueError";constructor(t="Invalid value"){super(t),this.name="InvalidValueError"}};var Sh=32;async function Yc(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:[ce.TXT]}))?.Answer??[]).sort((f,c)=>f.data.localeCompare(c.data));n("found %d TXT records for %s",s.length,e);for(let f of s)try{let c=f.data;if(c.startsWith('"')&&c.endsWith('"')&&(c=c.substring(1,c.length-1)),!c.startsWith("dnslink="))continue;n("%s TXT %s",f.name,c),c=c.replace("dnslink=","");let[,l,d,...T]=c.split("/");if(l==="ipfs")try{return{value:`/ipfs/${J.parse(d)}${T.length>0?`/${T.join("/")}`:""}`,answer:f}}catch{}else if(l==="ipns"){try{let A;return d.charAt(0)==="1"||d.charAt(0)==="Q"?A=Bn(d):A=bi(J.parse(d)),{value:`/ipns/${A}${T.length>0?`/${T.join("/")}`:""}`,answer:f}}catch{}return await to(d,t-1,r,n,o)}else{if(l==="dnslink")return await to(d,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,f.data,c)}n("no DNSLink records found for %s, falling back to CNAME",e);let u=((await r.query(e,{...o,types:[ce.CNAME]}))?.Answer??[]).sort((f,c)=>f.data.localeCompare(c.data));n("found %d CNAME records for %s",u.length,e);for(let f of u)try{return await to(f.data,t-1,r,n,o)}catch(c){n.error("domain %s cname %s had no DNSLink records",e,f.data,c)}throw new Yn(`No DNSLink records found for domain: ${e}`)}async function to(e,t,r,n,o={}){if(t===0)throw new Error("recursion limit exceeded");e.startsWith("_dnslink.")||(e=`_dnslink.${e}`);try{return await Yc(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}`,Yc(e,t,r,n,o)}}async function Xc(e,t,r,n={}){return to(e,n.maxRecursiveDepth??Sh,t,r,n)}var Ni=class{routing;constructor(t){this.routing=t}async put(t,r,n={}){try{await this.routing.put(t,r,n)}catch(o){n.onProgress?.(new yt("ipns:routing:helia:error",o))}}async get(t,r={}){try{return await this.routing.get(t,r)}catch(n){r.onProgress?.(new yt("ipns:routing:helia:error",n))}throw new Error("Not found")}};function jc(e){return new Ni(e)}var qr;(function(e){let t;e.codec=()=>(t==null&&(t=ve((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=>Ae(r,e.codec()),e.decode=(r,n)=>Se(r,e.codec(),n)})(qr||(qr={}));function Jc(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 Qc(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),f=parseInt(r[7].slice(0,-6),10);return new Date(Date.UTC(n,o,i,s,a,u,f))}var He=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 qr.encode(this.prepareSerialize())}prepareSerialize(){return{key:this.key,value:this.value,timeReceived:Jc(this.timeReceived)}}static deserialize(t){let r=qr.decode(t);return new e(r.key,r.value,new Date(r.timeReceived))}static fromDeserialized(t){let r=Qc(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 tu;(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"})(tu||(tu={}));function eo(e){return new Nr("/dht/record/"+et(e,"base32"),!1)}function eu(e){return{async put(t,r,n={}){try{let o=eo(t);try{let s=await e.get(o),a=He.deserialize(s);if(ot(a.value,r))return}catch(s){if(s.name!=="NotFoundError")throw s}let i=new He(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=eo(t);r.onProgress?.(new yt("ipns:routing:datastore:get"));let o=await e.get(n,r),i=He.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=eo(t);return e.has(n,r)},async delete(t,r){let n=eo(t);return e.delete(n,r)}}}var Li="/ipns/";function Di(e,t){return e.code===t}var ue=de("helia:ipns"),ou=60*1e3,iu=60*ou,Th=48*iu,ki=23*iu,ru=BigInt(ou)*5000000n,nu={[kt.prefix]:kt,[j.prefix]:j},Pi=class{routers;localStore;timeout;dns;log;constructor(t,r=[]){this.routers=[jc(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=qe(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:ru,a=await $c(t,r,o,n.lifetime??Th,{...n,ttlNs:s}),u=Gn(a);return await this.localStore.put(i,u,n),n.offline!==!0&&await Promise.all(this.routers.map(async f=>{await f.put(i,u,n)})),a}catch(o){throw n.onProgress?.(new yt("ipns:publish:error",o)),o}}async resolve(t,r={}){let n=Gi(t)?t.toMultihash():t,o=qe(n),i=await this.#e(o,r);return{...await this.#t(i.value,r),record:i}}async resolveDNSLink(t,r={}){let n=await Xc(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=ki-i;s<0&&(s=t.interval??ki),setTimeout(()=>{r().catch(a=>{ue.error("error republishing",a)})},s)}this.timeout=setTimeout(()=>{r().catch(n=>{ue.error("error republishing",n)})},t.interval??ki)}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=j.decode(`z${i}`);else if(nu[s]!=null)a=nu[s].decode(i);else throw new jn(`Unsupported multibase prefix "${s}"`);let u;try{u=Jt(a)}catch{u=J.decode(a).multihash}if(!Di(u,0)&&!Di(u,18))throw new Jn(`Unsupported multihash codec "${u.code}"`);let{cid:f}=await this.resolve(u,r),c=n.slice(3).join("/");return{cid:f,path:c}}else if(o==="ipfs"){let i=J.parse(n[2]),s=n.slice(3).join("/");return{cid:i,path:s}}}catch(o){ue.error("error parsing ipfs path",o)}throw ue.error("invalid ipfs path %s",t),new Qn("Invalid value")}async#e(t,r={}){let n=[];if(await this.localStore.has(t,r))if(ue("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 Vr(t,a),this.log("record was valid");let f=Yt(a),c=Number((f.ttl??ru)/1000000n);if(u.getTime()+c>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 ue("ignoring local cache due to nocache=true option");if(r.offline===!0)throw new hr("Record was not present in the cache or has expired");ue("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(f){ue.error("error finding IPNS record",f);return}try{await Vr(t,u),n.push(u)}catch(f){i++,ue.error("error finding IPNS record",f)}})),n.length===0)throw i>0?new Xn(`${i>1?`${i} records`:"Record"} found for routing key ${i>1?"were":"was"} invalid`):new hr("Could not find record for routing key");let s=n[Zn(t,n)];return await this.localStore.put(t,s,r),Yt(s)}async republishRecord(t,r,n={}){let o;try{if(o=Kr(r)?.toMultihash(),o==null)if(typeof t=="string"){t.startsWith(Li)&&(t=t.slice(Li.length));try{o=Bn(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=qe(o),s=Gn(r);await Vr(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 Ih(e,{routers:t=[]}={}){return new Pi(e,t)}return wu(Ch);})();
4
4
  /*! Bundled license information:
5
5
 
6
6
  @noble/hashes/esm/utils.js: