@helia/dnslink 1.1.2 → 1.1.3-c3d41c1f

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,5 +1,5 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.HeliaDnslink = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var HeliaDnslink=(()=>{var js=Object.create;var He=Object.defineProperty;var Gs=Object.getOwnPropertyDescriptor;var Xs=Object.getOwnPropertyNames;var Ws=Object.getPrototypeOf,Qs=Object.prototype.hasOwnProperty;var Js=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),it=(r,t)=>{for(var e in t)He(r,e,{get:t[e],enumerable:!0})},Zn=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Xs(t))!Qs.call(r,o)&&o!==e&&He(r,o,{get:()=>t[o],enumerable:!(n=Gs(t,o))||n.enumerable});return r};var ti=(r,t,e)=>(e=r!=null?js(Ws(r)):{},Zn(t||!r||!r.__esModule?He(e,"default",{value:r,enumerable:!0}):e,r)),ei=r=>Zn(He({},"__esModule",{value:!0}),r);var po=Js((Pf,lo)=>{lo.exports=function(r){if(!r)throw Error("hashlru must have a max value, of type number, greater than 0");var t=0,e=Object.create(null),n=Object.create(null);function o(s,i){e[s]=i,t++,t>=r&&(t=0,n=e,e=Object.create(null))}return{has:function(s){return e[s]!==void 0||n[s]!==void 0},remove:function(s){e[s]!==void 0&&(e[s]=void 0),n[s]!==void 0&&(n[s]=void 0)},get:function(s){var i=e[s];if(i!==void 0)return i;if((i=n[s])!==void 0)return o(s,i),i},set:function(s,i){e[s]!==void 0?e[s]=i:o(s,i)},clear:function(){e=Object.create(null),n=Object.create(null)}}}});var _a={};it(_a,{dnsLink:()=>Da});var Ir={};it(Ir,{base10:()=>ai});var Na=new Uint8Array(0);function zn(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function wt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function $n(r){return new TextEncoder().encode(r)}function Yn(r){return new TextDecoder().decode(r)}function ri(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var a=r.length,c=r.charAt(0),f=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function h(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var B=0,A=0,y=0,v=m.length;y!==v&&m[y]===0;)y++,B++;for(var b=(v-y)*u+1>>>0,I=new Uint8Array(b);y!==v;){for(var U=m[y],k=0,M=b-1;(U!==0||k<A)&&M!==-1;M--,k++)U+=256*I[M]>>>0,I[M]=U%a>>>0,U=U/a>>>0;if(U!==0)throw new Error("Non-zero carry");A=k,y++}for(var x=b-A;x!==b&&I[x]===0;)x++;for(var g=c.repeat(B);x<b;++x)g+=r.charAt(I[x]);return g}function w(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var B=0;if(m[B]!==" "){for(var A=0,y=0;m[B]===c;)A++,B++;for(var v=(m.length-B)*f+1>>>0,b=new Uint8Array(v);m[B];){var I=e[m.charCodeAt(B)];if(I===255)return;for(var U=0,k=v-1;(I!==0||U<y)&&k!==-1;k--,U++)I+=a*b[k]>>>0,b[k]=I%256>>>0,I=I/256>>>0;if(I!==0)throw new Error("Non-zero carry");y=U,B++}if(m[B]!==" "){for(var M=v-y;M!==v&&b[M]===0;)M++;for(var x=new Uint8Array(A+(v-M)),g=A;M!==v;)x[g++]=b[M++];return x}}}function E(m){var B=w(m);if(B)return B;throw new Error(`Non-${t} character`)}return{encode:h,decodeUnsafe:w,decode:E}}var ni=ri,oi=ni,Gn=oi;var Sr=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Ar=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.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 Xn(this,t)}},vr=class{decoders;constructor(t){this.decoders=t}or(t){return Xn(this,t)}decode(t){let e=t[0],n=this.decoders[e];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 Xn(r,t){return new vr({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Br=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new Sr(t,e,n),this.decoder=new Ar(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function jt({name:r,prefix:t,encode:e,decode:n}){return new Br(r,t,e,n)}function _t({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Gn(e,r);return jt({prefix:t,name:r,encode:n,decode:s=>wt(o(s))})}function si(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,a=0,c=0;for(let f=0;f<o;++f){let u=t[r[f]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|u,i+=e,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function ii(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function ci(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function $({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=ci(n);return jt({prefix:t,name:r,encode(s){return ii(s,n,e)},decode(s){return si(s,o,e,r)}})}var ai=_t({prefix:"9",name:"base10",alphabet:"0123456789"});var Lr={};it(Lr,{base16:()=>fi,base16upper:()=>ui});var fi=$({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),ui=$({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Dr={};it(Dr,{base2:()=>hi});var hi=$({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var _r={};it(_r,{base256emoji:()=>yi});var Wn=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}"),li=Wn.reduce((r,t,e)=>(r[e]=t,r),[]),di=Wn.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function pi(r){return r.reduce((t,e)=>(t+=li[e],t),"")}function mi(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=di[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var yi=jt({prefix:"\u{1F680}",name:"base256emoji",encode:pi,decode:mi});var Tr={};it(Tr,{base32:()=>Gt,base32hex:()=>wi,base32hexpad:()=>Si,base32hexpadupper:()=>Ai,base32hexupper:()=>Ei,base32pad:()=>gi,base32padupper:()=>xi,base32upper:()=>bi,base32z:()=>vi});var Gt=$({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),bi=$({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),gi=$({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),xi=$({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),wi=$({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ei=$({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Si=$({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Ai=$({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),vi=$({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Rr={};it(Rr,{base36:()=>me,base36upper:()=>Bi});var me=_t({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Bi=_t({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Cr={};it(Cr,{base58btc:()=>j,base58flickr:()=>Ii});var j=_t({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ii=_t({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ur={};it(Ur,{base64:()=>Li,base64pad:()=>Di,base64url:()=>_i,base64urlpad:()=>Ti});var Li=$({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Di=$({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),_i=$({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ti=$({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Nr={};it(Nr,{base8:()=>Ri});var Ri=$({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Kr={};it(Kr,{identity:()=>Ci});var Ci=jt({prefix:"\0",name:"identity",encode:r=>Yn(r),decode:r=>$n(r)});var Xa=new TextEncoder,Wa=new TextDecoder;var kr={};it(kr,{identity:()=>ht});var Ki=to,Qn=128,Oi=127,ki=~Oi,Mi=Math.pow(2,31);function to(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Mi;)t[e++]=r&255|Qn,r/=128;for(;r&ki;)t[e++]=r&255|Qn,r>>>=7;return t[e]=r|0,to.bytes=e-n+1,t}var Pi=Or,Hi=128,Jn=127;function Or(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Or.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&Jn)<<o:(i&Jn)*Math.pow(2,o),o+=7}while(i>=Hi);return Or.bytes=s-n,e}var qi=Math.pow(2,7),Vi=Math.pow(2,14),Fi=Math.pow(2,21),Zi=Math.pow(2,28),zi=Math.pow(2,35),$i=Math.pow(2,42),Yi=Math.pow(2,49),ji=Math.pow(2,56),Gi=Math.pow(2,63),Xi=function(r){return r<qi?1:r<Vi?2:r<Fi?3:r<Zi?4:r<zi?5:r<$i?6:r<Yi?7:r<ji?8:r<Gi?9:10},Wi={encode:Ki,decode:Pi,encodingLength:Xi},Qi=Wi,ye=Qi;function be(r,t=0){return[ye.decode(r,t),ye.decode.bytes]}function Xt(r,t,e=0){return ye.encode(r,t,e),t}function Wt(r){return ye.encodingLength(r)}function Jt(r,t){let e=t.byteLength,n=Wt(r),o=n+Wt(e),s=new Uint8Array(o+e);return Xt(r,s,0),Xt(e,s,n),s.set(t,o),new Qt(r,e,t,s)}function ge(r){let t=wt(r),[e,n]=be(t),[o,s]=be(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Qt(e,o,i,t)}function eo(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&zn(r.bytes,e.bytes)}}var Qt=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};var ro=0,Ji="identity",no=wt;function tc(r,t){if(t?.truncate!=null&&t.truncate!==r.byteLength){if(t.truncate<0||t.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t.truncate)}return Jt(ro,no(r))}var ht={code:ro,name:Ji,encode:no,digest:tc};var Hr={};it(Hr,{sha256:()=>xe,sha512:()=>rc});var ec=20;function Pr({name:r,code:t,encode:e,minDigestLength:n,maxDigestLength:o}){return new Mr(r,t,e,n,o)}var Mr=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,e,n,o,s){this.name=t,this.code=e,this.encode=n,this.minDigestLength=o??ec,this.maxDigestLength=s}digest(t,e){if(e?.truncate!=null){if(e.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&e.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?oo(n,this.code,e?.truncate):n.then(o=>oo(o,this.code,e?.truncate))}else throw Error("Unknown type, must be binary type")}};function oo(r,t,e){if(e!=null&&e!==r.byteLength){if(e>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e)}return Jt(t,r)}function io(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var xe=Pr({name:"sha2-256",code:18,encode:io("SHA-256")}),rc=Pr({name:"sha2-512",code:19,encode:io("SHA-512")});function co(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return oc(e,qr(r),t??j.encoder);default:return sc(e,qr(r),t??Gt.encoder)}}var ao=new WeakMap;function qr(r){let t=ao.get(r);if(t==null){let e=new Map;return ao.set(r,e),e}return t}var Q=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,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:e}=this;if(t!==we)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==ic)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}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:e}=this.multihash,n=Jt(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&eo(t.multihash,n.multihash)}toString(t){return co(this,t)}toJSON(){return{"/":co(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 e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:s,bytes:i}=e;return new r(n,o,s,i??fo(n,o,s.bytes))}else if(e[cc]===!0){let{version:n,multihash:o,code:s}=e,i=ge(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="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(e!==we)throw new Error(`Version 0 CID must use dag-pb (code: ${we}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=fo(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,we,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=wt(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new Qt(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[h,w]=be(t.subarray(e));return e+=w,h},o=n(),s=we;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),c=n(),f=e+c,u=f-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:u,size:f}}static parse(t,e){let[n,o]=nc(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return qr(s).set(n,t),s}};function nc(r,t){switch(r[0]){case"Q":{let e=t??j;return[j.prefix,e.decode(`${j.prefix}${r}`)]}case j.prefix:{let e=t??j;return[j.prefix,e.decode(r)]}case Gt.prefix:{let e=t??Gt;return[Gt.prefix,e.decode(r)]}case me.prefix:{let e=t??me;return[me.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function oc(r,t,e){let{prefix:n}=e;if(n!==j.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function sc(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var we=112,ic=18;function fo(r,t,e){let n=Wt(r),o=n+Wt(t),s=new Uint8Array(o+e.byteLength);return Xt(r,s,0),Xt(t,s,n),s.set(e,o),s}var cc=Symbol.for("@ipld/js-cid/CID");var Vr={...Kr,...Dr,...Nr,...Ir,...Lr,...Tr,...Rr,...Cr,...Ur,..._r},wf={...Hr,...kr};function Et(r=0){return new Uint8Array(r)}function ct(r=0){return new Uint8Array(r)}function ho(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var uo=ho("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Fr=ho("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=ct(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),ac={utf8:uo,"utf-8":uo,hex:Vr.base16,latin1:Fr,ascii:Fr,binary:Fr,...Vr},Ve=ac;function ot(r,t="utf8"){let e=Ve[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var lc=ti(po(),1);var xt;(function(r){r[r.A=1]="A",r[r.CNAME=5]="CNAME",r[r.TXT=16]="TXT",r[r.AAAA=28]="AAAA"})(xt||(xt={}));var mo=32;var ee=class extends Map{#r=0;#t=new Map;#e=new Map;#o;#i;#s;constructor(t={}){if(super(),!(t.maxSize&&t.maxSize>0))throw new TypeError("`maxSize` must be a number greater than 0");if(typeof t.maxAge=="number"&&t.maxAge===0)throw new TypeError("`maxAge` must be a number greater than 0");this.#o=t.maxSize,this.#i=t.maxAge||Number.POSITIVE_INFINITY,this.#s=t.onEviction}get __oldCache(){return this.#e}#c(t){if(typeof this.#s=="function")for(let[e,n]of t)this.#s(e,n.value)}#n(t,e){return typeof e.expiry=="number"&&e.expiry<=Date.now()?(typeof this.#s=="function"&&this.#s(t,e.value),this.delete(t)):!1}#l(t,e){if(this.#n(t,e)===!1)return e.value}#f(t,e){return e.expiry?this.#l(t,e):e.value}#u(t,e){let n=e.get(t);return this.#f(t,n)}#h(t,e){this.#t.set(t,e),this.#r++,this.#r>=this.#o&&(this.#r=0,this.#c(this.#e),this.#e=this.#t,this.#t=new Map)}#d(t,e){this.#e.delete(t),this.#h(t,e)}*#a(){for(let t of this.#e){let[e,n]=t;this.#t.has(e)||this.#n(e,n)===!1&&(yield t)}for(let t of this.#t){let[e,n]=t;this.#n(e,n)===!1&&(yield t)}}get(t){if(this.#t.has(t)){let e=this.#t.get(t);return this.#f(t,e)}if(this.#e.has(t)){let e=this.#e.get(t);if(this.#n(t,e)===!1)return this.#d(t,e),e.value}}set(t,e,{maxAge:n=this.#i}={}){let o=typeof n=="number"&&n!==Number.POSITIVE_INFINITY?Date.now()+n:void 0;return this.#t.has(t)?this.#t.set(t,{value:e,expiry:o}):this.#h(t,{value:e,expiry:o}),this}has(t){return this.#t.has(t)?!this.#n(t,this.#t.get(t)):this.#e.has(t)?!this.#n(t,this.#e.get(t)):!1}peek(t){if(this.#t.has(t))return this.#u(t,this.#t);if(this.#e.has(t))return this.#u(t,this.#e)}expiresIn(t){let e=this.#t.get(t)??this.#e.get(t);if(e)return e.expiry?e.expiry-Date.now():Number.POSITIVE_INFINITY}delete(t){let e=this.#t.delete(t);return e&&this.#r--,this.#e.delete(t)||e}clear(){this.#t.clear(),this.#e.clear(),this.#r=0}resize(t){if(!(t&&t>0))throw new TypeError("`maxSize` must be a number greater than 0");let e=[...this.#a()],n=e.length-t;n<0?(this.#t=new Map(e),this.#e=new Map,this.#r=e.length):(n>0&&this.#c(e.slice(0,n)),this.#e=new Map(e.slice(n)),this.#t=new Map,this.#r=0),this.#o=t}evict(t=1){let e=Number(t);if(!e||e<=0)return;let n=[...this.#a()],o=Math.trunc(Math.min(e,Math.max(n.length-1,0)));o<=0||(this.#c(n.slice(0,o)),this.#e=new Map(n.slice(o)),this.#t=new Map,this.#r=0)}*keys(){for(let[t]of this)yield t}*values(){for(let[,t]of this)yield t}*[Symbol.iterator](){for(let t of this.#t){let[e,n]=t;this.#n(e,n)===!1&&(yield[e,n.value])}for(let t of this.#e){let[e,n]=t;this.#t.has(e)||this.#n(e,n)===!1&&(yield[e,n.value])}}*entriesDescending(){let t=[...this.#t];for(let e=t.length-1;e>=0;--e){let n=t[e],[o,s]=n;this.#n(o,s)===!1&&(yield[o,s.value])}t=[...this.#e];for(let e=t.length-1;e>=0;--e){let n=t[e],[o,s]=n;this.#t.has(o)||this.#n(o,s)===!1&&(yield[o,s.value])}}*entriesAscending(){for(let[t,e]of this.#a())yield[t,e.value]}get size(){if(!this.#r)return this.#e.size;let t=0;for(let e of this.#e.keys())this.#t.has(e)||t++;return Math.min(this.#r+t,this.#o)}get maxSize(){return this.#o}get maxAge(){return this.#i}entries(){return this.entriesAscending()}forEach(t,e=this){for(let[n,o]of this.entriesAscending())t.call(e,o,n,this)}get[Symbol.toStringTag](){return"QuickLRU"}toString(){return`QuickLRU(${this.size}/${this.maxSize})`}[Symbol.for("nodejs.util.inspect.custom")](){return this.toString()}};var Fe=class extends Error{static name="DNSLinkNotFoundError";constructor(t="DNSLink not found"){super(t),this.name="DNSLinkNotFoundError"}},re=class extends Error{static name="InvalidNamespaceError";constructor(t="Invalid namespace"){super(t),this.name="InvalidNamespaceError"}};var yo=(r,t)=>{let[,e,n,...o]=r.split("/");if(e!=="ipfs")throw new re(`Namespace ${e} was not "ipfs"`);return{namespace:"ipfs",cid:Q.parse(n),path:o.length>0?`/${o.join("/")}`:"",answer:t}};var yt=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 ze=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 Ee=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Zr=Symbol.for("@libp2p/peer-id");function lt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Ye(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=ct(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var go=Symbol.for("@achingbrain/uint8arraylist");function bo(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function je(r){return!!r?.[go]}var at=class r{bufs;length;[go]=!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 e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(je(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(je(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=bo(this.bufs,t);return e.buf[e.index]}set(t,e){let n=bo(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(je(t))for(let n=0;n<t.length;n++)this.set(e+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,e){let{bufs:n,length:o}=this._subList(t,e);return Ye(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:Ye(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=[...n],s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let f=t>=a&&t<c,u=e>a&&e<=c;if(f&&u){if(t===a&&e===c){n.push(i);break}let h=t-a;n.push(i.subarray(h,h+(e-t)));break}if(f){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(u){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!je(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(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let h=0;h<s;h++)i[h]=-1;for(let h=0;h<o;h++)i[n[h]]=h;let a=i,c=this.byteLength-n.byteLength,f=n.byteLength-1,u;for(let h=e;h<=c;h+=u){u=0;for(let w=f;w>=0;w--){let E=this.get(h+w);if(n[w]!==E){u=Math.max(1,w-a[E]);break}}if(u===0)return h}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=ct(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=Et(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=Et(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=Et(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=ct(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=Et(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=Et(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=Et(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=Et(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=Et(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!lt(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};function Tt(r,t="utf8"){let e=Ve[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}var dc=parseInt("11111",2),zr=parseInt("10000000",2),pc=parseInt("01111111",2),xo={0:Se,1:Se,2:mc,3:gc,4:xc,5:bc,6:yc,16:Se,22:Se,48:Se};function $r(r,t={offset:0}){let e=r[t.offset]&dc;if(t.offset++,xo[e]!=null)return xo[e](r,t);throw new Error("No decoder for tag "+e)}function Ae(r,t){let e=0;if((r[t.offset]&zr)===zr){let n=r[t.offset]&pc,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=r[t.offset].toString(16).padStart(2,"0");e=parseInt(o,16)}else e=r[t.offset],t.offset++;return e}function Se(r,t){Ae(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=$r(r,t);if(n===null)break;e.push(n)}return e}function mc(r,t){let e=Ae(r,t),n=t.offset,o=t.offset+e,s=[];for(let i=n;i<o;i++)i===n&&r[i]===0||s.push(r[i]);return t.offset+=e,Uint8Array.from(s)}function yc(r,t){let e=Ae(r,t),n=t.offset+e,o=r[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let f=r[t.offset];if(t.offset++,c.push(f&127),f<128){c.reverse();let u=0;for(let h=0;h<c.length;h++)u+=c[h]<<h*7;a+=`.${u}`,c=[]}}return a}function bc(r,t){return t.offset++,null}function gc(r,t){let e=Ae(r,t),n=r[t.offset];t.offset++;let o=r.subarray(t.offset,t.offset+e-1);if(t.offset+=e,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function xc(r,t){let e=Ae(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function wc(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new at;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function Yr(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=wc(r.byteLength);return new at(Uint8Array.from([t.byteLength|zr]),t)}function wo(r){let t=new at,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new at(Uint8Array.from([2]),Yr(t),t)}function Eo(r){let t=Uint8Array.from([0]),e=new at(t,r);return new at(Uint8Array.from([3]),Yr(e),e)}function Ge(r,t=48){let e=new at;for(let n of r)e.append(n);return new at(Uint8Array.from([t]),Yr(e),e)}async function So(r,t,e,n){let o=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,e.subarray());return n?.signal?.throwIfAborted(),s}var Ec=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Sc=Uint8Array.from([6,5,43,129,4,0,34]),Ac=Uint8Array.from([6,5,43,129,4,0,35]),vc={ext:!0,kty:"EC",crv:"P-256"},Bc={ext:!0,kty:"EC",crv:"P-384"},Ic={ext:!0,kty:"EC",crv:"P-521"},jr=32,Gr=48,Xr=66;function Ao(r){let t=$r(r);return vo(t)}function vo(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===jr*2+1)return n=ot(t.subarray(e,e+jr),"base64url"),o=ot(t.subarray(e+jr),"base64url"),new ne({...vc,key_ops:["verify"],x:n,y:o});if(t.byteLength===Gr*2+1)return n=ot(t.subarray(e,e+Gr),"base64url"),o=ot(t.subarray(e+Gr),"base64url"),new ne({...Bc,key_ops:["verify"],x:n,y:o});if(t.byteLength===Xr*2+1)return n=ot(t.subarray(e,e+Xr),"base64url"),o=ot(t.subarray(e+Xr),"base64url"),new ne({...Ic,key_ops:["verify"],x:n,y:o});throw new yt(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Bo(r){return Ge([wo(Uint8Array.from([1])),Ge([Lc(r.crv)],160),Ge([Eo(new at(Uint8Array.from([4]),Tt(r.x??"","base64url"),Tt(r.y??"","base64url")))],161)]).subarray()}function Lc(r){if(r==="P-256")return Ec;if(r==="P-384")return Sc;if(r==="P-521")return Ac;throw new yt(`Invalid curve ${r}`)}var ne=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Bo(this.jwk)),this._raw}toMultihash(){return ht.digest(oe(this))}toCID(){return Q.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}async verify(t,e,n){return So(this.jwk,e,t,n)}};function Pt(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function bt(r,t=""){if(!Number.isSafeInteger(r)||r<0){let e=t&&`"${t}" `;throw new Error(`${e}expected integer >= 0, got ${r}`)}}function O(r,t,e=""){let n=Pt(r),o=r?.length,s=t!==void 0;if(!n||s&&o!==t){let i=e&&`"${e}" `,a=s?` of length ${t}`:"",c=n?`length=${o}`:`type=${typeof r}`;throw new Error(i+"expected Uint8Array"+a+", got "+c)}return r}function Xe(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash must wrapped by utils.createHasher");bt(r.outputLen),bt(r.blockLen)}function se(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function Lo(r,t){O(r,void 0,"digestInto() output");let e=t.outputLen;if(r.length<e)throw new Error('"digestInto() output" expected to be of length >='+e)}function At(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function We(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function dt(r,t){return r<<32-t|r>>>t}var Do=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Dc=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function vt(r){if(O(r),Do)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=Dc[r[e]];return t}var St={_0:48,_9:57,A:65,F:70,a:97,f:102};function Io(r){if(r>=St._0&&r<=St._9)return r-St._0;if(r>=St.A&&r<=St.F)return r-(St.A-10);if(r>=St.a&&r<=St.f)return r-(St.a-10)}function Bt(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(Do)return Uint8Array.fromHex(r);let t=r.length,e=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,s=0;o<e;o++,s+=2){let i=Io(r.charCodeAt(s)),a=Io(r.charCodeAt(s+1));if(i===void 0||a===void 0){let c=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function st(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];O(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}function Wr(r,t={}){let e=(o,s)=>r(s).update(o).digest(),n=r(void 0);return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=o=>r(o),Object.assign(e,t),Object.freeze(e)}function ie(r=32){let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return t.getRandomValues(new Uint8Array(r))}var Qr=r=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,r])});function _o(r,t,e){return r&t^~r&e}function To(r,t,e){return r&t^r&e^t&e}var ve=class{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,e,n,o){this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=We(this.buffer)}update(t){se(this),O(t);let{view:e,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=We(t);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){se(this),Lo(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,At(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let h=i;h<o;h++)e[h]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let a=We(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let f=c/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<f;h++)a.setUint32(4*h,u[h],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:e,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},It=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var J=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Qe=BigInt(4294967295),Ro=BigInt(32);function _c(r,t=!1){return t?{h:Number(r&Qe),l:Number(r>>Ro&Qe)}:{h:Number(r>>Ro&Qe)|0,l:Number(r&Qe)|0}}function Co(r,t=!1){let e=r.length,n=new Uint32Array(e),o=new Uint32Array(e);for(let s=0;s<e;s++){let{h:i,l:a}=_c(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var Jr=(r,t,e)=>r>>>e,tn=(r,t,e)=>r<<32-e|t>>>e,Ht=(r,t,e)=>r>>>e|t<<32-e,qt=(r,t,e)=>r<<32-e|t>>>e,Be=(r,t,e)=>r<<64-e|t>>>e-32,Ie=(r,t,e)=>r>>>e-32|t<<64-e;function gt(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var Uo=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),No=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Ko=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Oo=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,ko=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Mo=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var Rc=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Rt=new Uint32Array(64),en=class extends ve{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,e,n,o,s,i,a,c]}set(t,e,n,o,s,i,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,e){for(let h=0;h<16;h++,e+=4)Rt[h]=t.getUint32(e,!1);for(let h=16;h<64;h++){let w=Rt[h-15],E=Rt[h-2],m=dt(w,7)^dt(w,18)^w>>>3,B=dt(E,17)^dt(E,19)^E>>>10;Rt[h]=B+Rt[h-7]+m+Rt[h-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:f,H:u}=this;for(let h=0;h<64;h++){let w=dt(a,6)^dt(a,11)^dt(a,25),E=u+w+_o(a,c,f)+Rc[h]+Rt[h]|0,B=(dt(n,2)^dt(n,13)^dt(n,22))+To(n,o,s)|0;u=f,f=c,c=a,a=i+E|0,i=s,s=o,o=n,n=E+B|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(n,o,s,i,a,c,f,u)}roundClean(){At(Rt)}destroy(){this.set(0,0,0,0,0,0,0,0),At(this.buffer)}},rn=class extends en{A=It[0]|0;B=It[1]|0;C=It[2]|0;D=It[3]|0;E=It[4]|0;F=It[5]|0;G=It[6]|0;H=It[7]|0;constructor(){super(32)}};var Po=Co(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),Cc=Po[0],Uc=Po[1],Ct=new Uint32Array(80),Ut=new Uint32Array(80),nn=class extends ve{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:f,El:u,Fh:h,Fl:w,Gh:E,Gl:m,Hh:B,Hl:A}=this;return[t,e,n,o,s,i,a,c,f,u,h,w,E,m,B,A]}set(t,e,n,o,s,i,a,c,f,u,h,w,E,m,B,A){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=u|0,this.Fh=h|0,this.Fl=w|0,this.Gh=E|0,this.Gl=m|0,this.Hh=B|0,this.Hl=A|0}process(t,e){for(let b=0;b<16;b++,e+=4)Ct[b]=t.getUint32(e),Ut[b]=t.getUint32(e+=4);for(let b=16;b<80;b++){let I=Ct[b-15]|0,U=Ut[b-15]|0,k=Ht(I,U,1)^Ht(I,U,8)^Jr(I,U,7),M=qt(I,U,1)^qt(I,U,8)^tn(I,U,7),x=Ct[b-2]|0,g=Ut[b-2]|0,N=Ht(x,g,19)^Be(x,g,61)^Jr(x,g,6),P=qt(x,g,19)^Ie(x,g,61)^tn(x,g,6),T=Ko(M,P,Ut[b-7],Ut[b-16]),d=Oo(T,k,N,Ct[b-7],Ct[b-16]);Ct[b]=d|0,Ut[b]=T|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:f,Dl:u,Eh:h,El:w,Fh:E,Fl:m,Gh:B,Gl:A,Hh:y,Hl:v}=this;for(let b=0;b<80;b++){let I=Ht(h,w,14)^Ht(h,w,18)^Be(h,w,41),U=qt(h,w,14)^qt(h,w,18)^Ie(h,w,41),k=h&E^~h&B,M=w&m^~w&A,x=ko(v,U,M,Uc[b],Ut[b]),g=Mo(x,y,I,k,Cc[b],Ct[b]),N=x|0,P=Ht(n,o,28)^Be(n,o,34)^Be(n,o,39),T=qt(n,o,28)^Ie(n,o,34)^Ie(n,o,39),d=n&s^n&a^s&a,p=o&i^o&c^i&c;y=B|0,v=A|0,B=E|0,A=m|0,E=h|0,m=w|0,{h,l:w}=gt(f|0,u|0,g|0,N|0),f=a|0,u=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let l=Uo(N,T,p);n=No(l,g,P,d),o=l|0}({h:n,l:o}=gt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=gt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=gt(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=gt(this.Dh|0,this.Dl|0,f|0,u|0),{h,l:w}=gt(this.Eh|0,this.El|0,h|0,w|0),{h:E,l:m}=gt(this.Fh|0,this.Fl|0,E|0,m|0),{h:B,l:A}=gt(this.Gh|0,this.Gl|0,B|0,A|0),{h:y,l:v}=gt(this.Hh|0,this.Hl|0,y|0,v|0),this.set(n,o,s,i,a,c,f,u,h,w,E,m,B,A,y,v)}roundClean(){At(Ct,Ut)}destroy(){At(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},on=class extends nn{Ah=J[0]|0;Al=J[1]|0;Bh=J[2]|0;Bl=J[3]|0;Ch=J[4]|0;Cl=J[5]|0;Dh=J[6]|0;Dl=J[7]|0;Eh=J[8]|0;El=J[9]|0;Fh=J[10]|0;Fl=J[11]|0;Gh=J[12]|0;Gl=J[13]|0;Hh=J[14]|0;Hl=J[15]|0;constructor(){super(64)}};var Ho=Wr(()=>new rn,Qr(1));var qo=Wr(()=>new on,Qr(3));var cn=BigInt(0),sn=BigInt(1);function Lt(r,t=""){if(typeof r!="boolean"){let e=t&&`"${t}" `;throw new Error(e+"expected boolean, got type="+typeof r)}return r}function Vo(r){if(typeof r=="bigint"){if(!Je(r))throw new Error("positive bigint expected, got "+r)}else bt(r);return r}function Le(r){let t=Vo(r).toString(16);return t.length&1?"0"+t:t}function Fo(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?cn:BigInt("0x"+r)}function ce(r){return Fo(vt(r))}function Vt(r){return Fo(vt(er(O(r)).reverse()))}function tr(r,t){bt(t),r=Vo(r);let e=Bt(r.toString(16).padStart(t*2,"0"));if(e.length!==t)throw new Error("number too large");return e}function an(r,t){return tr(r,t).reverse()}function er(r){return Uint8Array.from(r)}var Je=r=>typeof r=="bigint"&&cn<=r;function Nc(r,t,e){return Je(r)&&Je(t)&&Je(e)&&t<=r&&r<e}function De(r,t,e,n){if(!Nc(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function fn(r){let t;for(t=0;r>cn;r>>=sn,t+=1);return t}var _e=r=>(sn<<BigInt(r))-sn;function Zo(r,t,e){if(bt(r,"hashLen"),bt(t,"qByteLen"),typeof e!="function")throw new Error("hmacFn must be a function");let n=A=>new Uint8Array(A),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(r),f=n(r),u=0,h=()=>{c.fill(1),f.fill(0),u=0},w=(...A)=>e(f,st(c,...A)),E=(A=o)=>{f=w(s,A),c=w(),A.length!==0&&(f=w(i,A),c=w())},m=()=>{if(u++>=a)throw new Error("drbg: tried max amount of iterations");let A=0,y=[];for(;A<t;){c=w();let v=c.slice();y.push(v),A+=c.length}return st(...y)};return(A,y)=>{h(),E(A);let v;for(;!(v=y(m()));)E();return h(),v}}function Nt(r,t={},e={}){if(!r||typeof r!="object")throw new Error("expected valid options object");function n(s,i,a){let c=r[s];if(a&&c===void 0)return;let f=typeof c;if(f!==i||c===null)throw new Error(`param "${s}" is invalid: expected ${i}, got ${f}`)}let o=(s,i)=>Object.entries(s).forEach(([a,c])=>n(a,c,i));o(t,!1),o(e,!0)}function ae(r){let t=new WeakMap;return(e,...n)=>{let o=t.get(e);if(o!==void 0)return o;let s=r(e,...n);return t.set(e,s),s}}var rt=BigInt(0),G=BigInt(1),Ft=BigInt(2),Yo=BigInt(3),jo=BigInt(4),Go=BigInt(5),Kc=BigInt(7),Xo=BigInt(8),Oc=BigInt(9),Wo=BigInt(16);function Y(r,t){let e=r%t;return e>=rt?e:t+e}function V(r,t,e){let n=r;for(;t-- >rt;)n*=n,n%=e;return n}function zo(r,t){if(r===rt)throw new Error("invert: expected non-zero number");if(t<=rt)throw new Error("invert: expected positive modulus, got "+t);let e=Y(r,t),n=t,o=rt,s=G,i=G,a=rt;for(;e!==rt;){let f=n/e,u=n%e,h=o-i*f,w=s-a*f;n=e,e=u,o=i,s=a,i=h,a=w}if(n!==G)throw new Error("invert: does not exist");return Y(o,t)}function hn(r,t,e){if(!r.eql(r.sqr(t),e))throw new Error("Cannot find square root")}function Qo(r,t){let e=(r.ORDER+G)/jo,n=r.pow(t,e);return hn(r,n,t),n}function kc(r,t){let e=(r.ORDER-Go)/Xo,n=r.mul(t,Ft),o=r.pow(n,e),s=r.mul(t,o),i=r.mul(r.mul(s,Ft),o),a=r.mul(s,r.sub(i,r.ONE));return hn(r,a,t),a}function Mc(r){let t=fe(r),e=Jo(r),n=e(t,t.neg(t.ONE)),o=e(t,n),s=e(t,t.neg(n)),i=(r+Kc)/Wo;return(a,c)=>{let f=a.pow(c,i),u=a.mul(f,n),h=a.mul(f,o),w=a.mul(f,s),E=a.eql(a.sqr(u),c),m=a.eql(a.sqr(h),c);f=a.cmov(f,u,E),u=a.cmov(w,h,m);let B=a.eql(a.sqr(u),c),A=a.cmov(f,u,B);return hn(a,A,c),A}}function Jo(r){if(r<Yo)throw new Error("sqrt is not defined for small field");let t=r-G,e=0;for(;t%Ft===rt;)t/=Ft,e++;let n=Ft,o=fe(r);for(;$o(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return Qo;let s=o.pow(n,t),i=(t+G)/Ft;return function(c,f){if(c.is0(f))return f;if($o(c,f)!==1)throw new Error("Cannot find square root");let u=e,h=c.mul(c.ONE,s),w=c.pow(f,t),E=c.pow(f,i);for(;!c.eql(w,c.ONE);){if(c.is0(w))return c.ZERO;let m=1,B=c.sqr(w);for(;!c.eql(B,c.ONE);)if(m++,B=c.sqr(B),m===u)throw new Error("Cannot find square root");let A=G<<BigInt(u-m-1),y=c.pow(h,A);u=m,h=c.sqr(y),w=c.mul(w,h),E=c.mul(E,y)}return E}}function Pc(r){return r%jo===Yo?Qo:r%Xo===Go?kc:r%Wo===Oc?Mc(r):Jo(r)}var ts=(r,t)=>(Y(r,t)&G)===G,Hc=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ln(r){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},e=Hc.reduce((n,o)=>(n[o]="function",n),t);return Nt(r,e),r}function qc(r,t,e){if(e<rt)throw new Error("invalid exponent, negatives unsupported");if(e===rt)return r.ONE;if(e===G)return t;let n=r.ONE,o=t;for(;e>rt;)e&G&&(n=r.mul(n,o)),o=r.sqr(o),e>>=G;return n}function Te(r,t,e=!1){let n=new Array(t.length).fill(e?r.ZERO:void 0),o=t.reduce((i,a,c)=>r.is0(a)?i:(n[c]=i,r.mul(i,a)),r.ONE),s=r.inv(o);return t.reduceRight((i,a,c)=>r.is0(a)?i:(n[c]=r.mul(i,n[c]),r.mul(i,a)),s),n}function $o(r,t){let e=(r.ORDER-G)/Ft,n=r.pow(t,e),o=r.eql(n,r.ONE),s=r.eql(n,r.ZERO),i=r.eql(n,r.neg(r.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function Vc(r,t){t!==void 0&&bt(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}var un=class{ORDER;BITS;BYTES;isLE;ZERO=rt;ONE=G;_lengths;_sqrt;_mod;constructor(t,e={}){if(t<=rt)throw new Error("invalid field: expected ORDER > 0, got "+t);let n;this.isLE=!1,e!=null&&typeof e=="object"&&(typeof e.BITS=="number"&&(n=e.BITS),typeof e.sqrt=="function"&&(this.sqrt=e.sqrt),typeof e.isLE=="boolean"&&(this.isLE=e.isLE),e.allowedLengths&&(this._lengths=e.allowedLengths?.slice()),typeof e.modFromBytes=="boolean"&&(this._mod=e.modFromBytes));let{nBitLength:o,nByteLength:s}=Vc(t,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=o,this.BYTES=s,this._sqrt=void 0,Object.preventExtensions(this)}create(t){return Y(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof t);return rt<=t&&t<this.ORDER}is0(t){return t===rt}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&G)===G}neg(t){return Y(-t,this.ORDER)}eql(t,e){return t===e}sqr(t){return Y(t*t,this.ORDER)}add(t,e){return Y(t+e,this.ORDER)}sub(t,e){return Y(t-e,this.ORDER)}mul(t,e){return Y(t*e,this.ORDER)}pow(t,e){return qc(this,t,e)}div(t,e){return Y(t*zo(e,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,e){return t+e}subN(t,e){return t-e}mulN(t,e){return t*e}inv(t){return zo(t,this.ORDER)}sqrt(t){return this._sqrt||(this._sqrt=Pc(this.ORDER)),this._sqrt(this,t)}toBytes(t){return this.isLE?an(t,this.BYTES):tr(t,this.BYTES)}fromBytes(t,e=!1){O(t);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(!n.includes(t.length)||t.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let f=new Uint8Array(o);f.set(t,s?0:f.length-t.length),t=f}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let c=s?Vt(t):ce(t);if(a&&(c=Y(c,i)),!e&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return Te(this,t)}cmov(t,e,n){return n?e:t}};function fe(r,t={}){return new un(r,t)}function es(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let t=r.toString(2).length;return Math.ceil(t/8)}function dn(r){let t=es(r);return t+Math.ceil(t/2)}function pn(r,t,e=!1){O(r);let n=r.length,o=es(t),s=dn(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?Vt(r):ce(r),a=Y(i,t-G)+G;return e?an(a,o):tr(a,o)}var ue=BigInt(0),Zt=BigInt(1);function Re(r,t){let e=t.negate();return r?e:t}function zt(r,t){let e=Te(r.Fp,t.map(n=>n.Z));return t.map((n,o)=>r.fromAffine(n.toAffine(e[o])))}function ss(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function mn(r,t){ss(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=_e(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function rs(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,a=Number(r&o),c=r>>i;a>n&&(a-=s,c+=Zt);let f=t*n,u=f+Math.abs(a)-1,h=a===0,w=a<0,E=t%2!==0;return{nextN:c,offset:u,isZero:h,isNeg:w,isNegF:E,offsetF:f}}var yn=new WeakMap,is=new WeakMap;function bn(r){return is.get(r)||1}function ns(r){if(r!==ue)throw new Error("invalid wNAF")}var he=class{BASE;ZERO;Fn;bits;constructor(t,e){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=e}_unsafeLadder(t,e,n=this.ZERO){let o=t;for(;e>ue;)e&Zt&&(n=n.add(o)),o=o.double(),e>>=Zt;return n}precomputeWindow(t,e){let{windows:n,windowSize:o}=mn(e,this.bits),s=[],i=t,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let f=1;f<o;f++)a=a.add(i),s.push(a);i=a.double()}return s}wNAF(t,e,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=mn(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:f,isZero:u,isNeg:h,isNegF:w,offsetF:E}=rs(n,a,i);n=c,u?s=s.add(Re(w,e[E])):o=o.add(Re(h,e[f]))}return ns(n),{p:o,f:s}}wNAFUnsafe(t,e,n,o=this.ZERO){let s=mn(t,this.bits);for(let i=0;i<s.windows&&n!==ue;i++){let{nextN:a,offset:c,isZero:f,isNeg:u}=rs(n,i,s);if(n=a,!f){let h=e[c];o=o.add(u?h.negate():h)}}return ns(n),o}getPrecomputes(t,e,n){let o=yn.get(e);return o||(o=this.precomputeWindow(e,t),t!==1&&(typeof n=="function"&&(o=n(o)),yn.set(e,o))),o}cached(t,e,n){let o=bn(t);return this.wNAF(o,this.getPrecomputes(o,t,n),e)}unsafe(t,e,n,o){let s=bn(t);return s===1?this._unsafeLadder(t,e,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),e,o)}createCache(t,e){ss(e,this.bits),is.set(t,e),yn.delete(t)}hasCache(t){return bn(t)!==1}};function cs(r,t,e,n){let o=t,s=r.ZERO,i=r.ZERO;for(;e>ue||n>ue;)e&Zt&&(s=s.add(o)),n&Zt&&(i=i.add(o)),o=o.double(),e>>=Zt,n>>=Zt;return{p1:s,p2:i}}function os(r,t,e){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return ln(t),t}else return fe(r,{isLE:e})}function rr(r,t,e={},n){if(n===void 0&&(n=r==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${r} CURVE object`);for(let c of["p","n","h"]){let f=t[c];if(!(typeof f=="bigint"&&f>ue))throw new Error(`CURVE.${c} must be positive bigint`)}let o=os(t.p,e.Fp,n),s=os(t.n,e.Fn,n),a=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}function nr(r,t){return function(n){let o=r(n);return{secretKey:o,publicKey:t(o)}}}var Kt=BigInt(0),X=BigInt(1),gn=BigInt(2),Fc=BigInt(8);function Zc(r,t,e,n){let o=r.sqr(e),s=r.sqr(n),i=r.add(r.mul(t.a,o),s),a=r.add(r.ONE,r.mul(t.d,r.mul(o,s)));return r.eql(i,a)}function as(r,t={}){let e=rr("edwards",r,t,t.FpFnLE),{Fp:n,Fn:o}=e,s=e.CURVE,{h:i}=s;Nt(t,{},{uvRatio:"function"});let a=gn<<BigInt(o.BYTES*8)-X,c=A=>n.create(A),f=t.uvRatio||((A,y)=>{try{return{isValid:!0,value:n.sqrt(n.div(A,y))}}catch{return{isValid:!1,value:Kt}}});if(!Zc(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function u(A,y,v=!1){let b=v?X:Kt;return De("coordinate "+A,y,b,a),y}function h(A){if(!(A instanceof m))throw new Error("EdwardsPoint expected")}let w=ae((A,y)=>{let{X:v,Y:b,Z:I}=A,U=A.is0();y==null&&(y=U?Fc:n.inv(I));let k=c(v*y),M=c(b*y),x=n.mul(I,y);if(U)return{x:Kt,y:X};if(x!==X)throw new Error("invZ was invalid");return{x:k,y:M}}),E=ae(A=>{let{a:y,d:v}=s;if(A.is0())throw new Error("bad point: ZERO");let{X:b,Y:I,Z:U,T:k}=A,M=c(b*b),x=c(I*I),g=c(U*U),N=c(g*g),P=c(M*y),T=c(g*c(P+x)),d=c(N+c(v*c(M*x)));if(T!==d)throw new Error("bad point: equation left != right (1)");let p=c(b*I),l=c(U*k);if(p!==l)throw new Error("bad point: equation left != right (2)");return!0});class m{static BASE=new m(s.Gx,s.Gy,X,c(s.Gx*s.Gy));static ZERO=new m(Kt,X,X,Kt);static Fp=n;static Fn=o;X;Y;Z;T;constructor(y,v,b,I){this.X=u("x",y),this.Y=u("y",v),this.Z=u("z",b,!0),this.T=u("t",I),Object.freeze(this)}static CURVE(){return s}static fromAffine(y){if(y instanceof m)throw new Error("extended point not allowed");let{x:v,y:b}=y||{};return u("x",v),u("y",b),new m(v,b,X,c(v*b))}static fromBytes(y,v=!1){let b=n.BYTES,{a:I,d:U}=s;y=er(O(y,b,"point")),Lt(v,"zip215");let k=er(y),M=y[b-1];k[b-1]=M&-129;let x=Vt(k),g=v?a:n.ORDER;De("point.y",x,Kt,g);let N=c(x*x),P=c(N-X),T=c(U*N-I),{isValid:d,value:p}=f(P,T);if(!d)throw new Error("bad point: invalid y coordinate");let l=(p&X)===X,S=(M&128)!==0;if(!v&&p===Kt&&S)throw new Error("bad point: x=0 and x_0=1");return S!==l&&(p=c(-p)),m.fromAffine({x:p,y:x})}static fromHex(y,v=!1){return m.fromBytes(Bt(y),v)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=8,v=!0){return B.createCache(this,y),v||this.multiply(gn),this}assertValidity(){E(this)}equals(y){h(y);let{X:v,Y:b,Z:I}=this,{X:U,Y:k,Z:M}=y,x=c(v*M),g=c(U*I),N=c(b*M),P=c(k*I);return x===g&&N===P}is0(){return this.equals(m.ZERO)}negate(){return new m(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:y}=s,{X:v,Y:b,Z:I}=this,U=c(v*v),k=c(b*b),M=c(gn*c(I*I)),x=c(y*U),g=v+b,N=c(c(g*g)-U-k),P=x+k,T=P-M,d=x-k,p=c(N*T),l=c(P*d),S=c(N*d),L=c(T*P);return new m(p,l,L,S)}add(y){h(y);let{a:v,d:b}=s,{X:I,Y:U,Z:k,T:M}=this,{X:x,Y:g,Z:N,T:P}=y,T=c(I*x),d=c(U*g),p=c(M*b*P),l=c(k*N),S=c((I+U)*(x+g)-T-d),L=l-p,_=l+p,R=c(d-v*T),D=c(S*L),C=c(_*R),K=c(S*R),F=c(L*_);return new m(D,C,F,K)}subtract(y){return this.add(y.negate())}multiply(y){if(!o.isValidNot0(y))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:v,f:b}=B.cached(this,y,I=>zt(m,I));return zt(m,[v,b])[0]}multiplyUnsafe(y,v=m.ZERO){if(!o.isValid(y))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return y===Kt?m.ZERO:this.is0()||y===X?this:B.unsafe(this,y,b=>zt(m,b),v)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return B.unsafe(this,s.n).is0()}toAffine(y){return w(this,y)}clearCofactor(){return i===X?this:this.multiplyUnsafe(i)}toBytes(){let{x:y,y:v}=this.toAffine(),b=n.toBytes(v);return b[b.length-1]|=y&X?128:0,b}toHex(){return vt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let B=new he(m,o.BITS);return m.BASE.precompute(8),m}function fs(r,t,e={}){if(typeof t!="function")throw new Error('"hash" function param is required');Nt(e,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=e,{BASE:o,Fp:s,Fn:i}=r,a=e.randomBytes||ie,c=e.adjustScalarBytes||(x=>x),f=e.domain||((x,g,N)=>{if(Lt(N,"phflag"),g.length||N)throw new Error("Contexts/pre-hash are not supported");return x});function u(x){return i.create(Vt(x))}function h(x){let g=b.secretKey;O(x,b.secretKey,"secretKey");let N=O(t(x),2*g,"hashedSecretKey"),P=c(N.slice(0,g)),T=N.slice(g,2*g),d=u(P);return{head:P,prefix:T,scalar:d}}function w(x){let{head:g,prefix:N,scalar:P}=h(x),T=o.multiply(P),d=T.toBytes();return{head:g,prefix:N,scalar:P,point:T,pointBytes:d}}function E(x){return w(x).pointBytes}function m(x=Uint8Array.of(),...g){let N=st(...g);return u(t(f(N,O(x,void 0,"context"),!!n)))}function B(x,g,N={}){x=O(x,void 0,"message"),n&&(x=n(x));let{prefix:P,scalar:T,pointBytes:d}=w(g),p=m(N.context,P,x),l=o.multiply(p).toBytes(),S=m(N.context,l,d,x),L=i.create(p+S*T);if(!i.isValid(L))throw new Error("sign failed: invalid s");let _=st(l,i.toBytes(L));return O(_,b.signature,"result")}let A={zip215:!0};function y(x,g,N,P=A){let{context:T,zip215:d}=P,p=b.signature;x=O(x,p,"signature"),g=O(g,void 0,"message"),N=O(N,b.publicKey,"publicKey"),d!==void 0&&Lt(d,"zip215"),n&&(g=n(g));let l=p/2,S=x.subarray(0,l),L=Vt(x.subarray(l,p)),_,R,D;try{_=r.fromBytes(N,d),R=r.fromBytes(S,d),D=o.multiplyUnsafe(L)}catch{return!1}if(!d&&_.isSmallOrder())return!1;let C=m(T,R.toBytes(),_.toBytes(),g);return R.add(_.multiplyUnsafe(C)).subtract(D).clearCofactor().is0()}let v=s.BYTES,b={secretKey:v,publicKey:v,signature:2*v,seed:v};function I(x=a(b.seed)){return O(x,b.seed,"seed")}function U(x){return Pt(x)&&x.length===i.BYTES}function k(x,g){try{return!!r.fromBytes(x,g)}catch{return!1}}let M={getExtendedPublicKey:w,randomSecretKey:I,isValidSecretKey:U,isValidPublicKey:k,toMontgomery(x){let{y:g}=r.fromBytes(x),N=b.publicKey,P=N===32;if(!P&&N!==57)throw new Error("only defined for 25519 and 448");let T=P?s.div(X+g,X-g):s.div(g-X,g+X);return s.toBytes(T)},toMontgomerySecret(x){let g=b.secretKey;O(x,g);let N=t(x.subarray(0,g));return c(N).subarray(0,g)}};return Object.freeze({keygen:nr(I,E),getPublicKey:E,sign:B,verify:y,utils:M,Point:r,lengths:b})}var zc=BigInt(1),us=BigInt(2);var $c=BigInt(5),Yc=BigInt(8),xn=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),jc={p:xn,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Yc,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Gc(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=xn,a=r*r%s*r%s,c=V(a,us,s)*a%s,f=V(c,zc,s)*r%s,u=V(f,$c,s)*f%s,h=V(u,t,s)*u%s,w=V(h,e,s)*h%s,E=V(w,n,s)*w%s,m=V(E,o,s)*E%s,B=V(m,o,s)*E%s,A=V(B,t,s)*u%s;return{pow_p_5_8:V(A,us,s)*r%s,b2:a}}function Xc(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var hs=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Wc(r,t){let e=xn,n=Y(t*t*t,e),o=Y(n*n*t,e),s=Gc(r*o).pow_p_5_8,i=Y(r*n*s,e),a=Y(t*i*i,e),c=i,f=Y(i*hs,e),u=a===r,h=a===Y(-r,e),w=a===Y(-r*hs,e);return u&&(i=c),(h||w)&&(i=f),ts(i,e)&&(i=Y(-i,e)),{isValid:u||h,value:i}}var Qc=as(jc,{uvRatio:Wc});function Jc(r){return fs(Qc,qo,Object.assign({adjustScalarBytes:Xc},r))}var ls=Jc({});var Ce=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},or=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var ds={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new or("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 sr=ds;var ir=32;var wn,ta=(async()=>{try{return await sr.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function ea(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await sr.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await sr.get().subtle.verify({name:"Ed25519"},n,t,e instanceof Uint8Array?e:e.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function ra(r,t,e){return ls.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function ps(r,t,e){return wn==null&&(wn=await ta),wn?ea(r,t,e):ra(r,t,e)}function cr(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var ar=class{type="Ed25519";raw;constructor(t){this.raw=En(t,ir)}toMultihash(){return ht.digest(oe(this))}toCID(){return Q.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let o=ps(this.raw,e,t);return cr(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function ys(r){return r=En(r,ir),new ar(r)}function En(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new yt(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var oa=Math.pow(2,7),sa=Math.pow(2,14),ia=Math.pow(2,21),bs=Math.pow(2,28),gs=Math.pow(2,35),xs=Math.pow(2,42),ws=Math.pow(2,49),nt=128,Ot=127;function Ue(r){if(r<oa)return 1;if(r<sa)return 2;if(r<ia)return 3;if(r<bs)return 4;if(r<gs)return 5;if(r<xs)return 6;if(r<ws)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Es(r,t,e=0){switch(Ue(r)){case 8:t[e++]=r&255|nt,r/=128;case 7:t[e++]=r&255|nt,r/=128;case 6:t[e++]=r&255|nt,r/=128;case 5:t[e++]=r&255|nt,r/=128;case 4:t[e++]=r&255|nt,r>>>=7;case 3:t[e++]=r&255|nt,r>>>=7;case 2:t[e++]=r&255|nt,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Ss(r,t){let e=r[t],n=0;if(n+=e&Ot,e<nt||(e=r[t+1],n+=(e&Ot)<<7,e<nt)||(e=r[t+2],n+=(e&Ot)<<14,e<nt)||(e=r[t+3],n+=(e&Ot)<<21,e<nt)||(e=r[t+4],n+=(e&Ot)*bs,e<nt)||(e=r[t+5],n+=(e&Ot)*gs,e<nt)||(e=r[t+6],n+=(e&Ot)*xs,e<nt)||(e=r[t+7],n+=(e&Ot)*ws,e<nt))return n;throw new RangeError("Could not decode varint")}var Sn=new Float32Array([-0]),kt=new Uint8Array(Sn.buffer);function As(r,t,e){Sn[0]=r,t[e]=kt[0],t[e+1]=kt[1],t[e+2]=kt[2],t[e+3]=kt[3]}function vs(r,t){return kt[0]=r[t],kt[1]=r[t+1],kt[2]=r[t+2],kt[3]=r[t+3],Sn[0]}var An=new Float64Array([-0]),et=new Uint8Array(An.buffer);function Bs(r,t,e){An[0]=r,t[e]=et[0],t[e+1]=et[1],t[e+2]=et[2],t[e+3]=et[3],t[e+4]=et[4],t[e+5]=et[5],t[e+6]=et[6],t[e+7]=et[7]}function Is(r,t){return et[0]=r[t],et[1]=r[t+1],et[2]=r[t+2],et[3]=r[t+3],et[4]=r[t+4],et[5]=r[t+5],et[6]=r[t+6],et[7]=r[t+7],An[0]}var ca=BigInt(Number.MAX_SAFE_INTEGER),aa=BigInt(Number.MIN_SAFE_INTEGER),ft=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+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 e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(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,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return $t;if(t<ca&&t>aa)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>Ls&&(o=0n,++n>Ls&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return $t;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):$t}},$t=new ft(0,0);$t.toBigInt=function(){return 0n};$t.zzEncode=$t.zzDecode=function(){return this};$t.length=function(){return 1};var Ls=4294967296n;function Ds(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function _s(r,t,e){if(e-t<1)return"";let o,s=[],i=0,a;for(;t<e;)a=r[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function vn(r,t,e){let n=e,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function pt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function fr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Bn=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,pt(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 pt(this,4);return fr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw pt(this,4);return fr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw pt(this,4);let t=vs(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw pt(this,4);let t=Is(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw pt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return _s(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw pt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw pt(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 ft(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*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;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw pt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw pt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw pt(this,8);let t=fr(this.buf,this.pos+=4),e=fr(this.buf,this.pos+=4);return new ft(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Ss(this.buf,this.pos);return this.pos+=Ue(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 In(r){return new Bn(r instanceof Uint8Array?r:r.subarray())}function ur(r,t,e){let n=In(r);return t.decode(n,void 0,e)}function Ln(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return ct(i);o+i>t&&(n=ct(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Yt=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Dn(){}var Tn=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},fa=Ln();function ua(r){return globalThis.Buffer!=null?ct(r):fa(r)}var Ke=class{len;head;tail;states;constructor(){this.len=0,this.head=new Yt(Dn,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new Yt(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Rn((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(hr,10,ft.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=ft.fromBigInt(t);return this._push(hr,e.length(),e)}uint64Number(t){return this._push(Es,Ue(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 e=ft.fromBigInt(t).zzEncode();return this._push(hr,e.length(),e)}sint64Number(t){let e=ft.fromNumber(t).zzEncode();return this._push(hr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(_n,1,t?1:0)}fixed32(t){return this._push(Ne,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=ft.fromBigInt(t);return this._push(Ne,4,e.lo)._push(Ne,4,e.hi)}fixed64Number(t){let e=ft.fromNumber(t);return this._push(Ne,4,e.lo)._push(Ne,4,e.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(As,4,t)}double(t){return this._push(Bs,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(_n,1,0):this.uint32(e)._push(la,e,t)}string(t){let e=Ds(t);return e!==0?this.uint32(e)._push(vn,e,t):this._push(_n,1,0)}fork(){return this.states=new Tn(this),this.head=this.tail=new Yt(Dn,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 Yt(Dn,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=ua(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function _n(r,t,e){t[e]=r&255}function ha(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Rn=class extends Yt{next;constructor(t,e){super(ha,t,e),this.next=void 0}};function hr(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function Ne(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function la(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Ke.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(da,t,r),this},Ke.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(pa,t,r),this});function da(r,t,e){t.set(r,e)}function pa(r,t,e){r.length<40?vn(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(Tt(r),e)}function Cn(){return new Ke}function lr(r,t){let e=Cn();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var le;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(le||(le={}));function dr(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Un(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(s,i){let a=t(s);i.int32(a)},n=function(s){let i=s.int32();return t(i)};return dr("enum",le.VARINT,e,n)}function pr(r,t){return dr("message",le.LENGTH_DELIMITED,r,t)}var ut;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(ut||(ut={}));var Nn;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(Nn||(Nn={}));(function(r){r.codec=()=>Un(Nn)})(ut||(ut={}));var Oe;(function(r){let t;r.codec=()=>(t==null&&(t=pr((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),ut.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=ut.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>lr(e,r.codec()),r.decode=(e,n)=>ur(e,r.codec(),n)})(Oe||(Oe={}));var Kn;(function(r){let t;r.codec=()=>(t==null&&(t=pr((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),ut.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=ut.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>lr(e,r.codec()),r.decode=(e,n)=>ur(e,r.codec(),n)})(Kn||(Kn={}));var mr=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(t,e){if(Xe(t),O(e,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(e.length>n?t.create().update(e).digest():e);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=t.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),At(o)}update(t){return se(this),this.iHash.update(t),this}digestInto(t){se(this),O(t,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:e,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},On=(r,t,e)=>new mr(r,t).update(e).digest();On.create=(r,t)=>new mr(r,t);var Rs=(r,t)=>(r+(r>=0?t:-t)/Cs)/t;function ya(r,t,e){let[[n,o],[s,i]]=t,a=Rs(i*r,e),c=Rs(-o*r,e),f=r-a*n-c*s,u=-a*o-c*i,h=f<Dt,w=u<Dt;h&&(f=-f),w&&(u=-u);let E=_e(Math.ceil(fn(e)/2))+de;if(f<Dt||f>=E||u<Dt||u>=E)throw new Error("splitScalar (endomorphism): failed, k="+r);return{k1neg:h,k1:f,k2neg:w,k2:u}}function Mn(r){if(!["compact","recovered","der"].includes(r))throw new Error('Signature format must be "compact", "recovered", or "der"');return r}function kn(r,t){let e={};for(let n of Object.keys(t))e[n]=r[n]===void 0?t[n]:r[n];return Lt(e.lowS,"lowS"),Lt(e.prehash,"prehash"),e.format!==void 0&&Mn(e.format),e}var Pn=class extends Error{constructor(t=""){super(t)}},Mt={Err:Pn,_tlv:{encode:(r,t)=>{let{Err:e}=Mt;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,o=Le(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?Le(o.length/2|128):"";return Le(r)+s+o+t},decode(r,t){let{Err:e}=Mt,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new e("tlv.decode(long): indefinite length not supported");if(c>4)throw new e("tlv.decode(long): byte length is too big");let f=t.subarray(n,n+c);if(f.length!==c)throw new e("tlv.decode: length bytes not complete");if(f[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let u of f)i=i<<8|u;if(n+=c,i<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=Mt;if(r<Dt)throw new t("integer: negative integers are not allowed");let e=Le(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return e},decode(r){let{Err:t}=Mt;if(r[0]&128)throw new t("invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return ce(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Mt,o=O(r,void 0,"signature"),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:f,l:u}=n.decode(2,c);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(f)}},hexFromSig(r){let{_tlv:t,_int:e}=Mt,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}},Dt=BigInt(0),de=BigInt(1),Cs=BigInt(2),yr=BigInt(3),ba=BigInt(4);function Us(r,t={}){let e=rr("weierstrass",r,t),{Fp:n,Fn:o}=e,s=e.CURVE,{h:i,n:a}=s;Nt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c}=t;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let f=Ks(n,o);function u(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function h(T,d,p){let{x:l,y:S}=d.toAffine(),L=n.toBytes(l);if(Lt(p,"isCompressed"),p){u();let _=!n.isOdd(S);return st(Ns(_),L)}else return st(Uint8Array.of(4),L,n.toBytes(S))}function w(T){O(T,void 0,"Point");let{publicKey:d,publicKeyUncompressed:p}=f,l=T.length,S=T[0],L=T.subarray(1);if(l===d&&(S===2||S===3)){let _=n.fromBytes(L);if(!n.isValid(_))throw new Error("bad point: is not on curve, wrong x");let R=B(_),D;try{D=n.sqrt(R)}catch(F){let q=F instanceof Error?": "+F.message:"";throw new Error("bad point: is not on curve, sqrt error"+q)}u();let C=n.isOdd(D);return(S&1)===1!==C&&(D=n.neg(D)),{x:_,y:D}}else if(l===p&&S===4){let _=n.BYTES,R=n.fromBytes(L.subarray(0,_)),D=n.fromBytes(L.subarray(_,_*2));if(!A(R,D))throw new Error("bad point: is not on curve");return{x:R,y:D}}else throw new Error(`bad point: got length ${l}, expected compressed=${d} or uncompressed=${p}`)}let E=t.toBytes||h,m=t.fromBytes||w;function B(T){let d=n.sqr(T),p=n.mul(d,T);return n.add(n.add(p,n.mul(T,s.a)),s.b)}function A(T,d){let p=n.sqr(d),l=B(T);return n.eql(p,l)}if(!A(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let y=n.mul(n.pow(s.a,yr),ba),v=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(y,v)))throw new Error("bad curve params: a or b");function b(T,d,p=!1){if(!n.isValid(d)||p&&n.is0(d))throw new Error(`bad point coordinate ${T}`);return d}function I(T){if(!(T instanceof g))throw new Error("Weierstrass Point expected")}function U(T){if(!c||!c.basises)throw new Error("no endo");return ya(T,c.basises,o.ORDER)}let k=ae((T,d)=>{let{X:p,Y:l,Z:S}=T;if(n.eql(S,n.ONE))return{x:p,y:l};let L=T.is0();d==null&&(d=L?n.ONE:n.inv(S));let _=n.mul(p,d),R=n.mul(l,d),D=n.mul(S,d);if(L)return{x:n.ZERO,y:n.ZERO};if(!n.eql(D,n.ONE))throw new Error("invZ was invalid");return{x:_,y:R}}),M=ae(T=>{if(T.is0()){if(t.allowInfinityPoint&&!n.is0(T.Y))return;throw new Error("bad point: ZERO")}let{x:d,y:p}=T.toAffine();if(!n.isValid(d)||!n.isValid(p))throw new Error("bad point: x or y not field elements");if(!A(d,p))throw new Error("bad point: equation left != right");if(!T.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function x(T,d,p,l,S){return p=new g(n.mul(p.X,T),p.Y,p.Z),d=Re(l,d),p=Re(S,p),d.add(p)}class g{static BASE=new g(s.Gx,s.Gy,n.ONE);static ZERO=new g(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(d,p,l){this.X=b("x",d),this.Y=b("y",p,!0),this.Z=b("z",l),Object.freeze(this)}static CURVE(){return s}static fromAffine(d){let{x:p,y:l}=d||{};if(!d||!n.isValid(p)||!n.isValid(l))throw new Error("invalid affine point");if(d instanceof g)throw new Error("projective point not allowed");return n.is0(p)&&n.is0(l)?g.ZERO:new g(p,l,n.ONE)}static fromBytes(d){let p=g.fromAffine(m(O(d,void 0,"point")));return p.assertValidity(),p}static fromHex(d){return g.fromBytes(Bt(d))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(d=8,p=!0){return P.createCache(this,d),p||this.multiply(yr),this}assertValidity(){M(this)}hasEvenY(){let{y:d}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(d)}equals(d){I(d);let{X:p,Y:l,Z:S}=this,{X:L,Y:_,Z:R}=d,D=n.eql(n.mul(p,R),n.mul(L,S)),C=n.eql(n.mul(l,R),n.mul(_,S));return D&&C}negate(){return new g(this.X,n.neg(this.Y),this.Z)}double(){let{a:d,b:p}=s,l=n.mul(p,yr),{X:S,Y:L,Z:_}=this,R=n.ZERO,D=n.ZERO,C=n.ZERO,K=n.mul(S,S),F=n.mul(L,L),q=n.mul(_,_),H=n.mul(S,L);return H=n.add(H,H),C=n.mul(S,_),C=n.add(C,C),R=n.mul(d,C),D=n.mul(l,q),D=n.add(R,D),R=n.sub(F,D),D=n.add(F,D),D=n.mul(R,D),R=n.mul(H,R),C=n.mul(l,C),q=n.mul(d,q),H=n.sub(K,q),H=n.mul(d,H),H=n.add(H,C),C=n.add(K,K),K=n.add(C,K),K=n.add(K,q),K=n.mul(K,H),D=n.add(D,K),q=n.mul(L,_),q=n.add(q,q),K=n.mul(q,H),R=n.sub(R,K),C=n.mul(q,F),C=n.add(C,C),C=n.add(C,C),new g(R,D,C)}add(d){I(d);let{X:p,Y:l,Z:S}=this,{X:L,Y:_,Z:R}=d,D=n.ZERO,C=n.ZERO,K=n.ZERO,F=s.a,q=n.mul(s.b,yr),H=n.mul(p,L),Z=n.mul(l,_),W=n.mul(S,R),mt=n.add(p,l),z=n.add(L,_);mt=n.mul(mt,z),z=n.add(H,Z),mt=n.sub(mt,z),z=n.add(p,S);let tt=n.add(L,R);return z=n.mul(z,tt),tt=n.add(H,W),z=n.sub(z,tt),tt=n.add(l,S),D=n.add(_,R),tt=n.mul(tt,D),D=n.add(Z,W),tt=n.sub(tt,D),K=n.mul(F,z),D=n.mul(q,W),K=n.add(D,K),D=n.sub(Z,K),K=n.add(Z,K),C=n.mul(D,K),Z=n.add(H,H),Z=n.add(Z,H),W=n.mul(F,W),z=n.mul(q,z),Z=n.add(Z,W),W=n.sub(H,W),W=n.mul(F,W),z=n.add(z,W),H=n.mul(Z,z),C=n.add(C,H),H=n.mul(tt,z),D=n.mul(mt,D),D=n.sub(D,H),H=n.mul(mt,Z),K=n.mul(tt,K),K=n.add(K,H),new g(D,C,K)}subtract(d){return this.add(d.negate())}is0(){return this.equals(g.ZERO)}multiply(d){let{endo:p}=t;if(!o.isValidNot0(d))throw new Error("invalid scalar: out of range");let l,S,L=_=>P.cached(this,_,R=>zt(g,R));if(p){let{k1neg:_,k1:R,k2neg:D,k2:C}=U(d),{p:K,f:F}=L(R),{p:q,f:H}=L(C);S=F.add(H),l=x(p.beta,K,q,_,D)}else{let{p:_,f:R}=L(d);l=_,S=R}return zt(g,[l,S])[0]}multiplyUnsafe(d){let{endo:p}=t,l=this;if(!o.isValid(d))throw new Error("invalid scalar: out of range");if(d===Dt||l.is0())return g.ZERO;if(d===de)return l;if(P.hasCache(this))return this.multiply(d);if(p){let{k1neg:S,k1:L,k2neg:_,k2:R}=U(d),{p1:D,p2:C}=cs(g,l,L,R);return x(p.beta,D,C,S,_)}else return P.unsafe(l,d)}toAffine(d){return k(this,d)}isTorsionFree(){let{isTorsionFree:d}=t;return i===de?!0:d?d(g,this):P.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:d}=t;return i===de?this:d?d(g,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(d=!0){return Lt(d,"isCompressed"),this.assertValidity(),E(g,this,d)}toHex(d=!0){return vt(this.toBytes(d))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let N=o.BITS,P=new he(g,t.endo?Math.ceil(N/2):N);return g.BASE.precompute(8),g}function Ns(r){return Uint8Array.of(r?2:3)}function Ks(r,t){return{secretKey:t.BYTES,publicKey:1+r.BYTES,publicKeyUncompressed:1+2*r.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function ga(r,t={}){let{Fn:e}=r,n=t.randomBytes||ie,o=Object.assign(Ks(r.Fp,e),{seed:dn(e.ORDER)});function s(E){try{let m=e.fromBytes(E);return e.isValidNot0(m)}catch{return!1}}function i(E,m){let{publicKey:B,publicKeyUncompressed:A}=o;try{let y=E.length;return m===!0&&y!==B||m===!1&&y!==A?!1:!!r.fromBytes(E)}catch{return!1}}function a(E=n(o.seed)){return pn(O(E,o.seed,"seed"),e.ORDER)}function c(E,m=!0){return r.BASE.multiply(e.fromBytes(E)).toBytes(m)}function f(E){let{secretKey:m,publicKey:B,publicKeyUncompressed:A}=o;if(!Pt(E)||"_lengths"in e&&e._lengths||m===B)return;let y=O(E,void 0,"key").length;return y===B||y===A}function u(E,m,B=!0){if(f(E)===!0)throw new Error("first arg must be private key");if(f(m)===!1)throw new Error("second arg must be public key");let A=e.fromBytes(E);return r.fromBytes(m).multiply(A).toBytes(B)}let h={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},w=nr(a,c);return Object.freeze({getPublicKey:c,getSharedSecret:u,keygen:w,Point:r,utils:h,lengths:o})}function Os(r,t,e={}){Xe(t),Nt(e,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),e=Object.assign({},e);let n=e.randomBytes||ie,o=e.hmac||((p,l)=>On(t,p,l)),{Fp:s,Fn:i}=r,{ORDER:a,BITS:c}=i,{keygen:f,getPublicKey:u,getSharedSecret:h,utils:w,lengths:E}=ga(r,e),m={prehash:!0,lowS:typeof e.lowS=="boolean"?e.lowS:!0,format:"compact",extraEntropy:!1},B=a*Cs<s.ORDER;function A(p){let l=a>>de;return p>l}function y(p,l){if(!i.isValidNot0(l))throw new Error(`invalid signature ${p}: out of range 1..Point.Fn.ORDER`);return l}function v(){if(B)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function b(p,l){Mn(l);let S=E.signature,L=l==="compact"?S:l==="recovered"?S+1:void 0;return O(p,L)}class I{r;s;recovery;constructor(l,S,L){if(this.r=y("r",l),this.s=y("s",S),L!=null){if(v(),![0,1,2,3].includes(L))throw new Error("invalid recovery id");this.recovery=L}Object.freeze(this)}static fromBytes(l,S=m.format){b(l,S);let L;if(S==="der"){let{r:C,s:K}=Mt.toSig(O(l));return new I(C,K)}S==="recovered"&&(L=l[0],S="compact",l=l.subarray(1));let _=E.signature/2,R=l.subarray(0,_),D=l.subarray(_,_*2);return new I(i.fromBytes(R),i.fromBytes(D),L)}static fromHex(l,S){return this.fromBytes(Bt(l),S)}assertRecovery(){let{recovery:l}=this;if(l==null)throw new Error("invalid recovery id: must be present");return l}addRecoveryBit(l){return new I(this.r,this.s,l)}recoverPublicKey(l){let{r:S,s:L}=this,_=this.assertRecovery(),R=_===2||_===3?S+a:S;if(!s.isValid(R))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let D=s.toBytes(R),C=r.fromBytes(st(Ns((_&1)===0),D)),K=i.inv(R),F=k(O(l,void 0,"msgHash")),q=i.create(-F*K),H=i.create(L*K),Z=r.BASE.multiplyUnsafe(q).add(C.multiplyUnsafe(H));if(Z.is0())throw new Error("invalid recovery: point at infinify");return Z.assertValidity(),Z}hasHighS(){return A(this.s)}toBytes(l=m.format){if(Mn(l),l==="der")return Bt(Mt.hexFromSig(this));let{r:S,s:L}=this,_=i.toBytes(S),R=i.toBytes(L);return l==="recovered"?(v(),st(Uint8Array.of(this.assertRecovery()),_,R)):st(_,R)}toHex(l){return vt(this.toBytes(l))}}let U=e.bits2int||function(l){if(l.length>8192)throw new Error("input is too large");let S=ce(l),L=l.length*8-c;return L>0?S>>BigInt(L):S},k=e.bits2int_modN||function(l){return i.create(U(l))},M=_e(c);function x(p){return De("num < 2^"+c,p,Dt,M),i.toBytes(p)}function g(p,l){return O(p,void 0,"message"),l?O(t(p),void 0,"prehashed message"):p}function N(p,l,S){let{lowS:L,prehash:_,extraEntropy:R}=kn(S,m);p=g(p,_);let D=k(p),C=i.fromBytes(l);if(!i.isValidNot0(C))throw new Error("invalid private key");let K=[x(C),x(D)];if(R!=null&&R!==!1){let Z=R===!0?n(E.secretKey):R;K.push(O(Z,void 0,"extraEntropy"))}let F=st(...K),q=D;function H(Z){let W=U(Z);if(!i.isValidNot0(W))return;let mt=i.inv(W),z=r.BASE.multiply(W).toAffine(),tt=i.create(z.x);if(tt===Dt)return;let Pe=i.create(mt*i.create(q+tt*C));if(Pe===Dt)return;let Vn=(z.x===tt?0:2)|Number(z.y&de),Fn=Pe;return L&&A(Pe)&&(Fn=i.neg(Pe),Vn^=1),new I(tt,Fn,B?void 0:Vn)}return{seed:F,k2sig:H}}function P(p,l,S={}){let{seed:L,k2sig:_}=N(p,l,S);return Zo(t.outputLen,i.BYTES,o)(L,_).toBytes(S.format)}function T(p,l,S,L={}){let{lowS:_,prehash:R,format:D}=kn(L,m);if(S=O(S,void 0,"publicKey"),l=g(l,R),!Pt(p)){let C=p instanceof I?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+C)}b(p,D);try{let C=I.fromBytes(p,D),K=r.fromBytes(S);if(_&&C.hasHighS())return!1;let{r:F,s:q}=C,H=k(l),Z=i.inv(q),W=i.create(H*Z),mt=i.create(F*Z),z=r.BASE.multiplyUnsafe(W).add(K.multiplyUnsafe(mt));return z.is0()?!1:i.create(z.x)===F}catch{return!1}}function d(p,l,S={}){let{prehash:L}=kn(S,m);return l=g(l,L),I.fromBytes(p,"recovered").recoverPublicKey(l).toBytes()}return Object.freeze({keygen:f,getPublicKey:u,getSharedSecret:h,utils:w,lengths:E,Point:r,sign:P,verify:T,recoverPublicKey:d,Signature:I,hash:t})}var qn={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},xa={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var ks=BigInt(2);function wa(r){let t=qn.p,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),f=r*r*r%t,u=f*f*r%t,h=V(u,e,t)*u%t,w=V(h,e,t)*u%t,E=V(w,ks,t)*f%t,m=V(E,o,t)*E%t,B=V(m,s,t)*m%t,A=V(B,a,t)*B%t,y=V(A,c,t)*A%t,v=V(y,a,t)*B%t,b=V(v,e,t)*u%t,I=V(b,i,t)*m%t,U=V(I,n,t)*f%t,k=V(U,ks,t);if(!Hn.eql(Hn.sqr(k),r))throw new Error("Cannot find square root");return k}var Hn=fe(qn.p,{sqrt:wa}),Ea=Us(qn,{Fp:Hn,endo:xa}),pe=Os(Ea,Ho);function Ms(r,t,e,n){let o=xe.digest(e instanceof Uint8Array?e:e.subarray());if(cr(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),pe.verify(t,s,r,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new Ce(String(s))});try{return n?.signal?.throwIfAborted(),pe.verify(t,o.digest,r,{prehash:!1,format:"der"})}catch(s){throw new Ce(String(s))}}var br=class{type="secp256k1";raw;_key;constructor(t){this._key=Hs(t),this.raw=Ps(this._key)}toMultihash(){return ht.digest(oe(this))}toCID(){return Q.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}verify(t,e,n){return Ms(this._key,e,t,n)}};function qs(r){return new br(r)}function Ps(r){return pe.Point.fromBytes(r).toBytes()}function Hs(r){try{return pe.Point.fromBytes(r),r}catch(t){throw new Ze(String(t))}}function Vs(r){let{Type:t,Data:e}=Oe.decode(r.digest),n=e??new Uint8Array;switch(t){case ut.Ed25519:return ys(n);case ut.secp256k1:return qs(n);case ut.ECDSA:return Ao(n);default:throw new Ee}}function oe(r){return Oe.encode({Type:ut[r.type],Data:r.raw})}var Fs=Symbol.for("nodejs.util.inspect.custom"),Sa=114,ke=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()})`}[Zr]=!0;toString(){return this.string==null&&(this.string=j.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return Q.createV1(Sa,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return lt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return lt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Fs](){return`PeerId(${this.toString()})`}},gr=class extends ke{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},xr=class extends ke{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},wr=class extends ke{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Aa=2336,Me=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=ht.digest(Tt(this.url))}[Fs](){return`PeerId(${this.url})`}[Zr]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return Q.createV1(Aa,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=ot(t)),t.toString()===this.toString())}};var va=114,Zs=2336;function zs(r,t){let e;if(r.charAt(0)==="1"||r.charAt(0)==="Q")e=ge(j.decode(`z${r}`));else{if(r.startsWith("k51qzi5uqu5")||r.startsWith("kzwfwjn5ji4")||r.startsWith("k2k4r8")||r.startsWith("bafz"))return Ba(Q.parse(r));if(t==null)throw new yt('Please pass a multibase decoder for strings that do not start with "1" or "Q"');e=ge(t.decode(r))}return $s(e)}function $s(r){if(La(r))return new gr({multihash:r});if(Ia(r))try{let t=Vs(r);if(t.type==="Ed25519")return new xr({multihash:r,publicKey:t});if(t.type==="secp256k1")return new wr({multihash:r,publicKey:t})}catch{let e=ot(r.digest);return new Me(new URL(e))}throw new $e("Supplied PeerID Multihash is invalid")}function Ba(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==va&&r.code!==Zs)throw new ze("Supplied PeerID CID is invalid");if(r.code===Zs){let t=ot(r.multihash.digest);return new Me(new URL(t))}return $s(r.multihash)}function Ia(r){return r.code===ht.code}function La(r){return r.code===xe.code}var Ys=(r,t)=>{let[,e,n,...o]=r.split("/");if(e!=="ipns")throw new re(`Namespace ${e} was not "ipns"`);return{namespace:"ipns",peerId:zs(n),path:o.length>0?`/${o.join("/")}`:"",answer:t}};var Er=class{dns;log;namespaces;cache;cacheMaxAnswers;constructor(t,e={}){this.dns=t.dns,this.log=t.logger.forComponent("helia:dnslink"),this.namespaces={ipfs:yo,ipns:Ys,...e.namespaces},this.cache=new ee({maxSize:e.cacheSize??1e3,maxAge:e.cacheMaxAge??3e4}),this.cacheMaxAnswers=e.cacheMaxAnswers??10}async resolve(t,e={}){if(e.nocache!==!0){let i=this.cache.get(t);if(i!=null){let a=[...i.values()];if(a.length>0)return a}}let n=await this.recursiveResolveDomain(t,e.maxRecursiveDepth??mo,e),o=new ee({maxSize:this.cacheMaxAnswers});n.forEach((i,a)=>{o.set(a,i,{maxAge:i.answer.TTL*1e3})});let s=n.reduce((i,a)=>{let c=a.answer.TTL*1e3;return c>i?c:i},0);return this.cache.maxAge<s&&(s=this.cache.maxAge),this.cache.set(t,o,{maxAge:s}),n}async recursiveResolveDomain(t,e,n={}){if(e===0)throw new Error("recursion limit exceeded");t.startsWith("_dnslink.")||(t=`_dnslink.${t}`);try{return await this.recursiveResolveDnslink(t,e,n)}catch(o){if(o.code!=="ENOTFOUND"&&o.code!=="ENODATA"&&o.name!=="DNSLinkNotFoundError"&&o.name!=="NotFoundError")throw o;return t.startsWith("_dnslink.")?t=t.replace("_dnslink.",""):t=`_dnslink.${t}`,this.recursiveResolveDnslink(t,e,n)}}async recursiveResolveDnslink(t,e,n={}){if(e===0)throw new Error("recursion limit exceeded");this.log("query %s for TXT and CNAME records",t);let s=((await this.dns.query(t,{...n,types:[xt.TXT]}))?.Answer??[]).sort((f,u)=>f.data.localeCompare(u.data));this.log("found %d TXT records for %s",s.length,t);let i=[];for(let f of s)try{let u=f.data;if(u.startsWith('"')&&u.endsWith('"')&&(u=u.substring(1,u.length-1)),!u.startsWith("dnslink="))continue;this.log("%s TXT %s",f.name,u),u=u.replace("dnslink=","");let[,h,w]=u.split("/");if(h==="dnslink")return await this.recursiveResolveDomain(w,e-1,n);let E=this.namespaces[h];if(E==null){this.log('unknown protocol "%s" in DNSLink record for domain: %s',h,t);continue}i.push(E(u,f))}catch(u){this.log.error("could not parse DNS link record for domain %s, %s - %e",t,f.data,u)}if(i.length>0)return i;this.log("no DNSLink records found for %s, falling back to CNAME",t);let c=((await this.dns.query(t,{...n,types:[xt.CNAME]}))?.Answer??[]).sort((f,u)=>f.data.localeCompare(u.data));this.log("found %d CNAME records for %s",c.length,t);for(let f of c)try{return await this.recursiveResolveDomain(f.data,e-1,n)}catch(u){this.log.error("domain %s cname %s had no DNSLink records - %e",t,f.data,u)}throw new Fe(`No DNSLink records found for domain: ${t}`)}};function Da(r,t={}){return new Er(r,t)}return ei(_a);})();
2
+ "use strict";var HeliaDnslink=(()=>{var js=Object.create;var He=Object.defineProperty;var Gs=Object.getOwnPropertyDescriptor;var Xs=Object.getOwnPropertyNames;var Ws=Object.getPrototypeOf,Qs=Object.prototype.hasOwnProperty;var Js=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),it=(r,t)=>{for(var e in t)He(r,e,{get:t[e],enumerable:!0})},Zn=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Xs(t))!Qs.call(r,o)&&o!==e&&He(r,o,{get:()=>t[o],enumerable:!(n=Gs(t,o))||n.enumerable});return r};var ti=(r,t,e)=>(e=r!=null?js(Ws(r)):{},Zn(t||!r||!r.__esModule?He(e,"default",{value:r,enumerable:!0}):e,r)),ei=r=>Zn(He({},"__esModule",{value:!0}),r);var po=Js((Pf,lo)=>{lo.exports=function(r){if(!r)throw Error("hashlru must have a max value, of type number, greater than 0");var t=0,e=Object.create(null),n=Object.create(null);function o(s,i){e[s]=i,t++,t>=r&&(t=0,n=e,e=Object.create(null))}return{has:function(s){return e[s]!==void 0||n[s]!==void 0},remove:function(s){e[s]!==void 0&&(e[s]=void 0),n[s]!==void 0&&(n[s]=void 0)},get:function(s){var i=e[s];if(i!==void 0)return i;if((i=n[s])!==void 0)return o(s,i),i},set:function(s,i){e[s]!==void 0?e[s]=i:o(s,i)},clear:function(){e=Object.create(null),n=Object.create(null)}}}});var _a={};it(_a,{dnsLink:()=>Da});var Ir={};it(Ir,{base10:()=>ai});var Na=new Uint8Array(0);function zn(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function wt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function $n(r){return new TextEncoder().encode(r)}function Yn(r){return new TextDecoder().decode(r)}function ri(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var a=r.length,c=r.charAt(0),f=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function h(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var B=0,A=0,y=0,v=d.length;y!==v&&d[y]===0;)y++,B++;for(var b=(v-y)*u+1>>>0,I=new Uint8Array(b);y!==v;){for(var U=d[y],k=0,M=b-1;(U!==0||k<A)&&M!==-1;M--,k++)U+=256*I[M]>>>0,I[M]=U%a>>>0,U=U/a>>>0;if(U!==0)throw new Error("Non-zero carry");A=k,y++}for(var x=b-A;x!==b&&I[x]===0;)x++;for(var g=c.repeat(B);x<b;++x)g+=r.charAt(I[x]);return g}function w(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var B=0;if(d[B]!==" "){for(var A=0,y=0;d[B]===c;)A++,B++;for(var v=(d.length-B)*f+1>>>0,b=new Uint8Array(v);d[B];){var I=e[d.charCodeAt(B)];if(I===255)return;for(var U=0,k=v-1;(I!==0||U<y)&&k!==-1;k--,U++)I+=a*b[k]>>>0,b[k]=I%256>>>0,I=I/256>>>0;if(I!==0)throw new Error("Non-zero carry");y=U,B++}if(d[B]!==" "){for(var M=v-y;M!==v&&b[M]===0;)M++;for(var x=new Uint8Array(A+(v-M)),g=A;M!==v;)x[g++]=b[M++];return x}}}function E(d){var B=w(d);if(B)return B;throw new Error(`Non-${t} character`)}return{encode:h,decodeUnsafe:w,decode:E}}var ni=ri,oi=ni,Gn=oi;var Sr=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Ar=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.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 Xn(this,t)}},vr=class{decoders;constructor(t){this.decoders=t}or(t){return Xn(this,t)}decode(t){let e=t[0],n=this.decoders[e];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 Xn(r,t){return new vr({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Br=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new Sr(t,e,n),this.decoder=new Ar(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function jt({name:r,prefix:t,encode:e,decode:n}){return new Br(r,t,e,n)}function _t({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Gn(e,r);return jt({prefix:t,name:r,encode:n,decode:s=>wt(o(s))})}function si(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,a=0,c=0;for(let f=0;f<o;++f){let u=t[r[f]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|u,i+=e,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function ii(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function ci(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function $({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=ci(n);return jt({prefix:t,name:r,encode(s){return ii(s,n,e)},decode(s){return si(s,o,e,r)}})}var ai=_t({prefix:"9",name:"base10",alphabet:"0123456789"});var Lr={};it(Lr,{base16:()=>fi,base16upper:()=>ui});var fi=$({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),ui=$({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Dr={};it(Dr,{base2:()=>hi});var hi=$({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var _r={};it(_r,{base256emoji:()=>yi});var Wn=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}"),li=Wn.reduce((r,t,e)=>(r[e]=t,r),[]),di=Wn.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function pi(r){return r.reduce((t,e)=>(t+=li[e],t),"")}function mi(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=di[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var yi=jt({prefix:"\u{1F680}",name:"base256emoji",encode:pi,decode:mi});var Tr={};it(Tr,{base32:()=>Gt,base32hex:()=>wi,base32hexpad:()=>Si,base32hexpadupper:()=>Ai,base32hexupper:()=>Ei,base32pad:()=>gi,base32padupper:()=>xi,base32upper:()=>bi,base32z:()=>vi});var Gt=$({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),bi=$({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),gi=$({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),xi=$({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),wi=$({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ei=$({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Si=$({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Ai=$({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),vi=$({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Rr={};it(Rr,{base36:()=>me,base36upper:()=>Bi});var me=_t({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Bi=_t({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Cr={};it(Cr,{base58btc:()=>j,base58flickr:()=>Ii});var j=_t({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ii=_t({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ur={};it(Ur,{base64:()=>Li,base64pad:()=>Di,base64url:()=>_i,base64urlpad:()=>Ti});var Li=$({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Di=$({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),_i=$({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ti=$({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Nr={};it(Nr,{base8:()=>Ri});var Ri=$({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Kr={};it(Kr,{identity:()=>Ci});var Ci=jt({prefix:"\0",name:"identity",encode:r=>Yn(r),decode:r=>$n(r)});var Xa=new TextEncoder,Wa=new TextDecoder;var kr={};it(kr,{identity:()=>ht});var Ki=to,Qn=128,Oi=127,ki=~Oi,Mi=Math.pow(2,31);function to(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Mi;)t[e++]=r&255|Qn,r/=128;for(;r&ki;)t[e++]=r&255|Qn,r>>>=7;return t[e]=r|0,to.bytes=e-n+1,t}var Pi=Or,Hi=128,Jn=127;function Or(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Or.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&Jn)<<o:(i&Jn)*Math.pow(2,o),o+=7}while(i>=Hi);return Or.bytes=s-n,e}var qi=Math.pow(2,7),Vi=Math.pow(2,14),Fi=Math.pow(2,21),Zi=Math.pow(2,28),zi=Math.pow(2,35),$i=Math.pow(2,42),Yi=Math.pow(2,49),ji=Math.pow(2,56),Gi=Math.pow(2,63),Xi=function(r){return r<qi?1:r<Vi?2:r<Fi?3:r<Zi?4:r<zi?5:r<$i?6:r<Yi?7:r<ji?8:r<Gi?9:10},Wi={encode:Ki,decode:Pi,encodingLength:Xi},Qi=Wi,ye=Qi;function be(r,t=0){return[ye.decode(r,t),ye.decode.bytes]}function Xt(r,t,e=0){return ye.encode(r,t,e),t}function Wt(r){return ye.encodingLength(r)}function Jt(r,t){let e=t.byteLength,n=Wt(r),o=n+Wt(e),s=new Uint8Array(o+e);return Xt(r,s,0),Xt(e,s,n),s.set(t,o),new Qt(r,e,t,s)}function ge(r){let t=wt(r),[e,n]=be(t),[o,s]=be(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Qt(e,o,i,t)}function eo(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&zn(r.bytes,e.bytes)}}var Qt=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};var ro=0,Ji="identity",no=wt;function tc(r,t){if(t?.truncate!=null&&t.truncate!==r.byteLength){if(t.truncate<0||t.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t.truncate)}return Jt(ro,no(r))}var ht={code:ro,name:Ji,encode:no,digest:tc};var Hr={};it(Hr,{sha256:()=>xe,sha512:()=>rc});var ec=20;function Pr({name:r,code:t,encode:e,minDigestLength:n,maxDigestLength:o}){return new Mr(r,t,e,n,o)}var Mr=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,e,n,o,s){this.name=t,this.code=e,this.encode=n,this.minDigestLength=o??ec,this.maxDigestLength=s}digest(t,e){if(e?.truncate!=null){if(e.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&e.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?oo(n,this.code,e?.truncate):n.then(o=>oo(o,this.code,e?.truncate))}else throw Error("Unknown type, must be binary type")}};function oo(r,t,e){if(e!=null&&e!==r.byteLength){if(e>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e)}return Jt(t,r)}function io(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var xe=Pr({name:"sha2-256",code:18,encode:io("SHA-256")}),rc=Pr({name:"sha2-512",code:19,encode:io("SHA-512")});function co(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return oc(e,qr(r),t??j.encoder);default:return sc(e,qr(r),t??Gt.encoder)}}var ao=new WeakMap;function qr(r){let t=ao.get(r);if(t==null){let e=new Map;return ao.set(r,e),e}return t}var Q=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,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:e}=this;if(t!==we)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==ic)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}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:e}=this.multihash,n=Jt(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&eo(t.multihash,n.multihash)}toString(t){return co(this,t)}toJSON(){return{"/":co(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 e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:s,bytes:i}=e;return new r(n,o,s,i??fo(n,o,s.bytes))}else if(e[cc]===!0){let{version:n,multihash:o,code:s}=e,i=ge(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="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(e!==we)throw new Error(`Version 0 CID must use dag-pb (code: ${we}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=fo(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,we,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=wt(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new Qt(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[h,w]=be(t.subarray(e));return e+=w,h},o=n(),s=we;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),c=n(),f=e+c,u=f-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:u,size:f}}static parse(t,e){let[n,o]=nc(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return qr(s).set(n,t),s}};function nc(r,t){switch(r[0]){case"Q":{let e=t??j;return[j.prefix,e.decode(`${j.prefix}${r}`)]}case j.prefix:{let e=t??j;return[j.prefix,e.decode(r)]}case Gt.prefix:{let e=t??Gt;return[Gt.prefix,e.decode(r)]}case me.prefix:{let e=t??me;return[me.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function oc(r,t,e){let{prefix:n}=e;if(n!==j.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function sc(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var we=112,ic=18;function fo(r,t,e){let n=Wt(r),o=n+Wt(t),s=new Uint8Array(o+e.byteLength);return Xt(r,s,0),Xt(t,s,n),s.set(e,o),s}var cc=Symbol.for("@ipld/js-cid/CID");var Vr={...Kr,...Dr,...Nr,...Ir,...Lr,...Tr,...Rr,...Cr,...Ur,..._r},wf={...Hr,...kr};function Et(r=0){return new Uint8Array(r)}function ct(r=0){return new Uint8Array(r)}function ho(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var uo=ho("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Fr=ho("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=ct(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),ac={utf8:uo,"utf-8":uo,hex:Vr.base16,latin1:Fr,ascii:Fr,binary:Fr,...Vr},Ve=ac;function ot(r,t="utf8"){let e=Ve[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var lc=ti(po(),1);var xt;(function(r){r[r.A=1]="A",r[r.CNAME=5]="CNAME",r[r.TXT=16]="TXT",r[r.AAAA=28]="AAAA"})(xt||(xt={}));var mo=32;var ee=class extends Map{#r=0;#t=new Map;#e=new Map;#o;#i;#s;constructor(t={}){if(super(),!(t.maxSize&&t.maxSize>0))throw new TypeError("`maxSize` must be a number greater than 0");if(typeof t.maxAge=="number"&&t.maxAge===0)throw new TypeError("`maxAge` must be a number greater than 0");this.#o=t.maxSize,this.#i=t.maxAge||Number.POSITIVE_INFINITY,this.#s=t.onEviction}get __oldCache(){return this.#e}#c(t){if(typeof this.#s=="function")for(let[e,n]of t)this.#s(e,n.value)}#n(t,e){return typeof e.expiry=="number"&&e.expiry<=Date.now()?(typeof this.#s=="function"&&this.#s(t,e.value),this.delete(t)):!1}#l(t,e){if(this.#n(t,e)===!1)return e.value}#f(t,e){return e.expiry?this.#l(t,e):e.value}#u(t,e){let n=e.get(t);return this.#f(t,n)}#h(t,e){this.#t.set(t,e),this.#r++,this.#r>=this.#o&&(this.#r=0,this.#c(this.#e),this.#e=this.#t,this.#t=new Map)}#d(t,e){this.#e.delete(t),this.#h(t,e)}*#a(){for(let t of this.#e){let[e,n]=t;this.#t.has(e)||this.#n(e,n)===!1&&(yield t)}for(let t of this.#t){let[e,n]=t;this.#n(e,n)===!1&&(yield t)}}get(t){if(this.#t.has(t)){let e=this.#t.get(t);return this.#f(t,e)}if(this.#e.has(t)){let e=this.#e.get(t);if(this.#n(t,e)===!1)return this.#d(t,e),e.value}}set(t,e,{maxAge:n=this.#i}={}){let o=typeof n=="number"&&n!==Number.POSITIVE_INFINITY?Date.now()+n:void 0;return this.#t.has(t)?this.#t.set(t,{value:e,expiry:o}):this.#h(t,{value:e,expiry:o}),this}has(t){return this.#t.has(t)?!this.#n(t,this.#t.get(t)):this.#e.has(t)?!this.#n(t,this.#e.get(t)):!1}peek(t){if(this.#t.has(t))return this.#u(t,this.#t);if(this.#e.has(t))return this.#u(t,this.#e)}expiresIn(t){let e=this.#t.get(t)??this.#e.get(t);if(e)return e.expiry?e.expiry-Date.now():Number.POSITIVE_INFINITY}delete(t){let e=this.#t.delete(t);return e&&this.#r--,this.#e.delete(t)||e}clear(){this.#t.clear(),this.#e.clear(),this.#r=0}resize(t){if(!(t&&t>0))throw new TypeError("`maxSize` must be a number greater than 0");let e=[...this.#a()],n=e.length-t;n<0?(this.#t=new Map(e),this.#e=new Map,this.#r=e.length):(n>0&&this.#c(e.slice(0,n)),this.#e=new Map(e.slice(n)),this.#t=new Map,this.#r=0),this.#o=t}evict(t=1){let e=Number(t);if(!e||e<=0)return;let n=[...this.#a()],o=Math.trunc(Math.min(e,Math.max(n.length-1,0)));o<=0||(this.#c(n.slice(0,o)),this.#e=new Map(n.slice(o)),this.#t=new Map,this.#r=0)}*keys(){for(let[t]of this)yield t}*values(){for(let[,t]of this)yield t}*[Symbol.iterator](){for(let t of this.#t){let[e,n]=t;this.#n(e,n)===!1&&(yield[e,n.value])}for(let t of this.#e){let[e,n]=t;this.#t.has(e)||this.#n(e,n)===!1&&(yield[e,n.value])}}*entriesDescending(){let t=[...this.#t];for(let e=t.length-1;e>=0;--e){let n=t[e],[o,s]=n;this.#n(o,s)===!1&&(yield[o,s.value])}t=[...this.#e];for(let e=t.length-1;e>=0;--e){let n=t[e],[o,s]=n;this.#t.has(o)||this.#n(o,s)===!1&&(yield[o,s.value])}}*entriesAscending(){for(let[t,e]of this.#a())yield[t,e.value]}get size(){if(!this.#r)return this.#e.size;let t=0;for(let e of this.#e.keys())this.#t.has(e)||t++;return Math.min(this.#r+t,this.#o)}get maxSize(){return this.#o}get maxAge(){return this.#i}entries(){return this.entriesAscending()}forEach(t,e=this){for(let[n,o]of this.entriesAscending())t.call(e,o,n,this)}get[Symbol.toStringTag](){return"QuickLRU"}toString(){return`QuickLRU(${this.size}/${this.maxSize})`}[Symbol.for("nodejs.util.inspect.custom")](){return this.toString()}};var Fe=class extends Error{static name="DNSLinkNotFoundError";constructor(t="DNSLink not found"){super(t),this.name="DNSLinkNotFoundError"}},re=class extends Error{static name="InvalidNamespaceError";constructor(t="Invalid namespace"){super(t),this.name="InvalidNamespaceError"}};var yo=(r,t)=>{let[,e,n,...o]=r.split("/");if(e!=="ipfs")throw new re(`Namespace ${e} was not "ipfs"`);return{namespace:"ipfs",cid:Q.parse(n),path:o.length>0?`/${o.join("/")}`:"",answer:t}};var yt=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 ze=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 Ee=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Zr=Symbol.for("@libp2p/peer-id");function lt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Ye(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=ct(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var go=Symbol.for("@achingbrain/uint8arraylist");function bo(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function je(r){return!!r?.[go]}var at=class r{bufs;length;[go]=!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 e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(je(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(je(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=bo(this.bufs,t);return e.buf[e.index]}set(t,e){let n=bo(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(je(t))for(let n=0;n<t.length;n++)this.set(e+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,e){let{bufs:n,length:o}=this._subList(t,e);return Ye(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:Ye(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=[...n],s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let f=t>=a&&t<c,u=e>a&&e<=c;if(f&&u){if(t===a&&e===c){n.push(i);break}let h=t-a;n.push(i.subarray(h,h+(e-t)));break}if(f){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(u){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!je(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(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let h=0;h<s;h++)i[h]=-1;for(let h=0;h<o;h++)i[n[h]]=h;let a=i,c=this.byteLength-n.byteLength,f=n.byteLength-1,u;for(let h=e;h<=c;h+=u){u=0;for(let w=f;w>=0;w--){let E=this.get(h+w);if(n[w]!==E){u=Math.max(1,w-a[E]);break}}if(u===0)return h}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=ct(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=Et(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=Et(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=Et(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=ct(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=Et(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=Et(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=Et(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=Et(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=Et(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!lt(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};function Tt(r,t="utf8"){let e=Ve[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}var dc=parseInt("11111",2),zr=parseInt("10000000",2),pc=parseInt("01111111",2),xo={0:Se,1:Se,2:mc,3:gc,4:xc,5:bc,6:yc,16:Se,22:Se,48:Se};function $r(r,t={offset:0}){let e=r[t.offset]&dc;if(t.offset++,xo[e]!=null)return xo[e](r,t);throw new Error("No decoder for tag "+e)}function Ae(r,t){let e=0;if((r[t.offset]&zr)===zr){let n=r[t.offset]&pc,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=r[t.offset].toString(16).padStart(2,"0");e=parseInt(o,16)}else e=r[t.offset],t.offset++;return e}function Se(r,t){Ae(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=$r(r,t);if(n===null)break;e.push(n)}return e}function mc(r,t){let e=Ae(r,t),n=t.offset,o=t.offset+e,s=[];for(let i=n;i<o;i++)i===n&&r[i]===0||s.push(r[i]);return t.offset+=e,Uint8Array.from(s)}function yc(r,t){let e=Ae(r,t),n=t.offset+e,o=r[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let f=r[t.offset];if(t.offset++,c.push(f&127),f<128){c.reverse();let u=0;for(let h=0;h<c.length;h++)u+=c[h]<<h*7;a+=`.${u}`,c=[]}}return a}function bc(r,t){return t.offset++,null}function gc(r,t){let e=Ae(r,t),n=r[t.offset];t.offset++;let o=r.subarray(t.offset,t.offset+e-1);if(t.offset+=e,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function xc(r,t){let e=Ae(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function wc(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new at;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function Yr(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=wc(r.byteLength);return new at(Uint8Array.from([t.byteLength|zr]),t)}function wo(r){let t=new at,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new at(Uint8Array.from([2]),Yr(t),t)}function Eo(r){let t=Uint8Array.from([0]),e=new at(t,r);return new at(Uint8Array.from([3]),Yr(e),e)}function Ge(r,t=48){let e=new at;for(let n of r)e.append(n);return new at(Uint8Array.from([t]),Yr(e),e)}async function So(r,t,e,n){let o=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,e.subarray());return n?.signal?.throwIfAborted(),s}var Ec=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Sc=Uint8Array.from([6,5,43,129,4,0,34]),Ac=Uint8Array.from([6,5,43,129,4,0,35]),vc={ext:!0,kty:"EC",crv:"P-256"},Bc={ext:!0,kty:"EC",crv:"P-384"},Ic={ext:!0,kty:"EC",crv:"P-521"},jr=32,Gr=48,Xr=66;function Ao(r){let t=$r(r);return vo(t)}function vo(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===jr*2+1)return n=ot(t.subarray(e,e+jr),"base64url"),o=ot(t.subarray(e+jr),"base64url"),new ne({...vc,key_ops:["verify"],x:n,y:o});if(t.byteLength===Gr*2+1)return n=ot(t.subarray(e,e+Gr),"base64url"),o=ot(t.subarray(e+Gr),"base64url"),new ne({...Bc,key_ops:["verify"],x:n,y:o});if(t.byteLength===Xr*2+1)return n=ot(t.subarray(e,e+Xr),"base64url"),o=ot(t.subarray(e+Xr),"base64url"),new ne({...Ic,key_ops:["verify"],x:n,y:o});throw new yt(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Bo(r){return Ge([wo(Uint8Array.from([1])),Ge([Lc(r.crv)],160),Ge([Eo(new at(Uint8Array.from([4]),Tt(r.x??"","base64url"),Tt(r.y??"","base64url")))],161)]).subarray()}function Lc(r){if(r==="P-256")return Ec;if(r==="P-384")return Sc;if(r==="P-521")return Ac;throw new yt(`Invalid curve ${r}`)}var ne=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Bo(this.jwk)),this._raw}toMultihash(){return ht.digest(oe(this))}toCID(){return Q.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}async verify(t,e,n){return So(this.jwk,e,t,n)}};function Pt(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function bt(r,t=""){if(!Number.isSafeInteger(r)||r<0){let e=t&&`"${t}" `;throw new Error(`${e}expected integer >= 0, got ${r}`)}}function O(r,t,e=""){let n=Pt(r),o=r?.length,s=t!==void 0;if(!n||s&&o!==t){let i=e&&`"${e}" `,a=s?` of length ${t}`:"",c=n?`length=${o}`:`type=${typeof r}`;throw new Error(i+"expected Uint8Array"+a+", got "+c)}return r}function Xe(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash must wrapped by utils.createHasher");bt(r.outputLen),bt(r.blockLen)}function se(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function Lo(r,t){O(r,void 0,"digestInto() output");let e=t.outputLen;if(r.length<e)throw new Error('"digestInto() output" expected to be of length >='+e)}function At(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function We(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function dt(r,t){return r<<32-t|r>>>t}var Do=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Dc=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function vt(r){if(O(r),Do)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=Dc[r[e]];return t}var St={_0:48,_9:57,A:65,F:70,a:97,f:102};function Io(r){if(r>=St._0&&r<=St._9)return r-St._0;if(r>=St.A&&r<=St.F)return r-(St.A-10);if(r>=St.a&&r<=St.f)return r-(St.a-10)}function Bt(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(Do)return Uint8Array.fromHex(r);let t=r.length,e=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,s=0;o<e;o++,s+=2){let i=Io(r.charCodeAt(s)),a=Io(r.charCodeAt(s+1));if(i===void 0||a===void 0){let c=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function st(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];O(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}function Wr(r,t={}){let e=(o,s)=>r(s).update(o).digest(),n=r(void 0);return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=o=>r(o),Object.assign(e,t),Object.freeze(e)}function ie(r=32){let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return t.getRandomValues(new Uint8Array(r))}var Qr=r=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,r])});function _o(r,t,e){return r&t^~r&e}function To(r,t,e){return r&t^r&e^t&e}var ve=class{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,e,n,o){this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=We(this.buffer)}update(t){se(this),O(t);let{view:e,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=We(t);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){se(this),Lo(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,At(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let h=i;h<o;h++)e[h]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let a=We(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let f=c/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<f;h++)a.setUint32(4*h,u[h],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:e,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},It=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var J=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Qe=BigInt(4294967295),Ro=BigInt(32);function _c(r,t=!1){return t?{h:Number(r&Qe),l:Number(r>>Ro&Qe)}:{h:Number(r>>Ro&Qe)|0,l:Number(r&Qe)|0}}function Co(r,t=!1){let e=r.length,n=new Uint32Array(e),o=new Uint32Array(e);for(let s=0;s<e;s++){let{h:i,l:a}=_c(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var Jr=(r,t,e)=>r>>>e,tn=(r,t,e)=>r<<32-e|t>>>e,Ht=(r,t,e)=>r>>>e|t<<32-e,qt=(r,t,e)=>r<<32-e|t>>>e,Be=(r,t,e)=>r<<64-e|t>>>e-32,Ie=(r,t,e)=>r>>>e-32|t<<64-e;function gt(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var Uo=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),No=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Ko=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Oo=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,ko=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Mo=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var Rc=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Rt=new Uint32Array(64),en=class extends ve{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,e,n,o,s,i,a,c]}set(t,e,n,o,s,i,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,e){for(let h=0;h<16;h++,e+=4)Rt[h]=t.getUint32(e,!1);for(let h=16;h<64;h++){let w=Rt[h-15],E=Rt[h-2],d=dt(w,7)^dt(w,18)^w>>>3,B=dt(E,17)^dt(E,19)^E>>>10;Rt[h]=B+Rt[h-7]+d+Rt[h-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:f,H:u}=this;for(let h=0;h<64;h++){let w=dt(a,6)^dt(a,11)^dt(a,25),E=u+w+_o(a,c,f)+Rc[h]+Rt[h]|0,B=(dt(n,2)^dt(n,13)^dt(n,22))+To(n,o,s)|0;u=f,f=c,c=a,a=i+E|0,i=s,s=o,o=n,n=E+B|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(n,o,s,i,a,c,f,u)}roundClean(){At(Rt)}destroy(){this.set(0,0,0,0,0,0,0,0),At(this.buffer)}},rn=class extends en{A=It[0]|0;B=It[1]|0;C=It[2]|0;D=It[3]|0;E=It[4]|0;F=It[5]|0;G=It[6]|0;H=It[7]|0;constructor(){super(32)}};var Po=Co(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),Cc=Po[0],Uc=Po[1],Ct=new Uint32Array(80),Ut=new Uint32Array(80),nn=class extends ve{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:f,El:u,Fh:h,Fl:w,Gh:E,Gl:d,Hh:B,Hl:A}=this;return[t,e,n,o,s,i,a,c,f,u,h,w,E,d,B,A]}set(t,e,n,o,s,i,a,c,f,u,h,w,E,d,B,A){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=u|0,this.Fh=h|0,this.Fl=w|0,this.Gh=E|0,this.Gl=d|0,this.Hh=B|0,this.Hl=A|0}process(t,e){for(let b=0;b<16;b++,e+=4)Ct[b]=t.getUint32(e),Ut[b]=t.getUint32(e+=4);for(let b=16;b<80;b++){let I=Ct[b-15]|0,U=Ut[b-15]|0,k=Ht(I,U,1)^Ht(I,U,8)^Jr(I,U,7),M=qt(I,U,1)^qt(I,U,8)^tn(I,U,7),x=Ct[b-2]|0,g=Ut[b-2]|0,N=Ht(x,g,19)^Be(x,g,61)^Jr(x,g,6),P=qt(x,g,19)^Ie(x,g,61)^tn(x,g,6),T=Ko(M,P,Ut[b-7],Ut[b-16]),p=Oo(T,k,N,Ct[b-7],Ct[b-16]);Ct[b]=p|0,Ut[b]=T|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:f,Dl:u,Eh:h,El:w,Fh:E,Fl:d,Gh:B,Gl:A,Hh:y,Hl:v}=this;for(let b=0;b<80;b++){let I=Ht(h,w,14)^Ht(h,w,18)^Be(h,w,41),U=qt(h,w,14)^qt(h,w,18)^Ie(h,w,41),k=h&E^~h&B,M=w&d^~w&A,x=ko(v,U,M,Uc[b],Ut[b]),g=Mo(x,y,I,k,Cc[b],Ct[b]),N=x|0,P=Ht(n,o,28)^Be(n,o,34)^Be(n,o,39),T=qt(n,o,28)^Ie(n,o,34)^Ie(n,o,39),p=n&s^n&a^s&a,m=o&i^o&c^i&c;y=B|0,v=A|0,B=E|0,A=d|0,E=h|0,d=w|0,{h,l:w}=gt(f|0,u|0,g|0,N|0),f=a|0,u=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let l=Uo(N,T,m);n=No(l,g,P,p),o=l|0}({h:n,l:o}=gt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=gt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=gt(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=gt(this.Dh|0,this.Dl|0,f|0,u|0),{h,l:w}=gt(this.Eh|0,this.El|0,h|0,w|0),{h:E,l:d}=gt(this.Fh|0,this.Fl|0,E|0,d|0),{h:B,l:A}=gt(this.Gh|0,this.Gl|0,B|0,A|0),{h:y,l:v}=gt(this.Hh|0,this.Hl|0,y|0,v|0),this.set(n,o,s,i,a,c,f,u,h,w,E,d,B,A,y,v)}roundClean(){At(Ct,Ut)}destroy(){At(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},on=class extends nn{Ah=J[0]|0;Al=J[1]|0;Bh=J[2]|0;Bl=J[3]|0;Ch=J[4]|0;Cl=J[5]|0;Dh=J[6]|0;Dl=J[7]|0;Eh=J[8]|0;El=J[9]|0;Fh=J[10]|0;Fl=J[11]|0;Gh=J[12]|0;Gl=J[13]|0;Hh=J[14]|0;Hl=J[15]|0;constructor(){super(64)}};var Ho=Wr(()=>new rn,Qr(1));var qo=Wr(()=>new on,Qr(3));var cn=BigInt(0),sn=BigInt(1);function Lt(r,t=""){if(typeof r!="boolean"){let e=t&&`"${t}" `;throw new Error(e+"expected boolean, got type="+typeof r)}return r}function Vo(r){if(typeof r=="bigint"){if(!Je(r))throw new Error("positive bigint expected, got "+r)}else bt(r);return r}function Le(r){let t=Vo(r).toString(16);return t.length&1?"0"+t:t}function Fo(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?cn:BigInt("0x"+r)}function ce(r){return Fo(vt(r))}function Vt(r){return Fo(vt(er(O(r)).reverse()))}function tr(r,t){bt(t),r=Vo(r);let e=Bt(r.toString(16).padStart(t*2,"0"));if(e.length!==t)throw new Error("number too large");return e}function an(r,t){return tr(r,t).reverse()}function er(r){return Uint8Array.from(r)}var Je=r=>typeof r=="bigint"&&cn<=r;function Nc(r,t,e){return Je(r)&&Je(t)&&Je(e)&&t<=r&&r<e}function De(r,t,e,n){if(!Nc(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function fn(r){let t;for(t=0;r>cn;r>>=sn,t+=1);return t}var _e=r=>(sn<<BigInt(r))-sn;function Zo(r,t,e){if(bt(r,"hashLen"),bt(t,"qByteLen"),typeof e!="function")throw new Error("hmacFn must be a function");let n=A=>new Uint8Array(A),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(r),f=n(r),u=0,h=()=>{c.fill(1),f.fill(0),u=0},w=(...A)=>e(f,st(c,...A)),E=(A=o)=>{f=w(s,A),c=w(),A.length!==0&&(f=w(i,A),c=w())},d=()=>{if(u++>=a)throw new Error("drbg: tried max amount of iterations");let A=0,y=[];for(;A<t;){c=w();let v=c.slice();y.push(v),A+=c.length}return st(...y)};return(A,y)=>{h(),E(A);let v;for(;!(v=y(d()));)E();return h(),v}}function Nt(r,t={},e={}){if(!r||typeof r!="object")throw new Error("expected valid options object");function n(s,i,a){let c=r[s];if(a&&c===void 0)return;let f=typeof c;if(f!==i||c===null)throw new Error(`param "${s}" is invalid: expected ${i}, got ${f}`)}let o=(s,i)=>Object.entries(s).forEach(([a,c])=>n(a,c,i));o(t,!1),o(e,!0)}function ae(r){let t=new WeakMap;return(e,...n)=>{let o=t.get(e);if(o!==void 0)return o;let s=r(e,...n);return t.set(e,s),s}}var rt=BigInt(0),G=BigInt(1),Ft=BigInt(2),Yo=BigInt(3),jo=BigInt(4),Go=BigInt(5),Kc=BigInt(7),Xo=BigInt(8),Oc=BigInt(9),Wo=BigInt(16);function Y(r,t){let e=r%t;return e>=rt?e:t+e}function V(r,t,e){let n=r;for(;t-- >rt;)n*=n,n%=e;return n}function zo(r,t){if(r===rt)throw new Error("invert: expected non-zero number");if(t<=rt)throw new Error("invert: expected positive modulus, got "+t);let e=Y(r,t),n=t,o=rt,s=G,i=G,a=rt;for(;e!==rt;){let f=n/e,u=n%e,h=o-i*f,w=s-a*f;n=e,e=u,o=i,s=a,i=h,a=w}if(n!==G)throw new Error("invert: does not exist");return Y(o,t)}function hn(r,t,e){if(!r.eql(r.sqr(t),e))throw new Error("Cannot find square root")}function Qo(r,t){let e=(r.ORDER+G)/jo,n=r.pow(t,e);return hn(r,n,t),n}function kc(r,t){let e=(r.ORDER-Go)/Xo,n=r.mul(t,Ft),o=r.pow(n,e),s=r.mul(t,o),i=r.mul(r.mul(s,Ft),o),a=r.mul(s,r.sub(i,r.ONE));return hn(r,a,t),a}function Mc(r){let t=fe(r),e=Jo(r),n=e(t,t.neg(t.ONE)),o=e(t,n),s=e(t,t.neg(n)),i=(r+Kc)/Wo;return(a,c)=>{let f=a.pow(c,i),u=a.mul(f,n),h=a.mul(f,o),w=a.mul(f,s),E=a.eql(a.sqr(u),c),d=a.eql(a.sqr(h),c);f=a.cmov(f,u,E),u=a.cmov(w,h,d);let B=a.eql(a.sqr(u),c),A=a.cmov(f,u,B);return hn(a,A,c),A}}function Jo(r){if(r<Yo)throw new Error("sqrt is not defined for small field");let t=r-G,e=0;for(;t%Ft===rt;)t/=Ft,e++;let n=Ft,o=fe(r);for(;$o(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return Qo;let s=o.pow(n,t),i=(t+G)/Ft;return function(c,f){if(c.is0(f))return f;if($o(c,f)!==1)throw new Error("Cannot find square root");let u=e,h=c.mul(c.ONE,s),w=c.pow(f,t),E=c.pow(f,i);for(;!c.eql(w,c.ONE);){if(c.is0(w))return c.ZERO;let d=1,B=c.sqr(w);for(;!c.eql(B,c.ONE);)if(d++,B=c.sqr(B),d===u)throw new Error("Cannot find square root");let A=G<<BigInt(u-d-1),y=c.pow(h,A);u=d,h=c.sqr(y),w=c.mul(w,h),E=c.mul(E,y)}return E}}function Pc(r){return r%jo===Yo?Qo:r%Xo===Go?kc:r%Wo===Oc?Mc(r):Jo(r)}var ts=(r,t)=>(Y(r,t)&G)===G,Hc=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ln(r){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},e=Hc.reduce((n,o)=>(n[o]="function",n),t);return Nt(r,e),r}function qc(r,t,e){if(e<rt)throw new Error("invalid exponent, negatives unsupported");if(e===rt)return r.ONE;if(e===G)return t;let n=r.ONE,o=t;for(;e>rt;)e&G&&(n=r.mul(n,o)),o=r.sqr(o),e>>=G;return n}function Te(r,t,e=!1){let n=new Array(t.length).fill(e?r.ZERO:void 0),o=t.reduce((i,a,c)=>r.is0(a)?i:(n[c]=i,r.mul(i,a)),r.ONE),s=r.inv(o);return t.reduceRight((i,a,c)=>r.is0(a)?i:(n[c]=r.mul(i,n[c]),r.mul(i,a)),s),n}function $o(r,t){let e=(r.ORDER-G)/Ft,n=r.pow(t,e),o=r.eql(n,r.ONE),s=r.eql(n,r.ZERO),i=r.eql(n,r.neg(r.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function Vc(r,t){t!==void 0&&bt(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}var un=class{ORDER;BITS;BYTES;isLE;ZERO=rt;ONE=G;_lengths;_sqrt;_mod;constructor(t,e={}){if(t<=rt)throw new Error("invalid field: expected ORDER > 0, got "+t);let n;this.isLE=!1,e!=null&&typeof e=="object"&&(typeof e.BITS=="number"&&(n=e.BITS),typeof e.sqrt=="function"&&(this.sqrt=e.sqrt),typeof e.isLE=="boolean"&&(this.isLE=e.isLE),e.allowedLengths&&(this._lengths=e.allowedLengths?.slice()),typeof e.modFromBytes=="boolean"&&(this._mod=e.modFromBytes));let{nBitLength:o,nByteLength:s}=Vc(t,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=o,this.BYTES=s,this._sqrt=void 0,Object.preventExtensions(this)}create(t){return Y(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof t);return rt<=t&&t<this.ORDER}is0(t){return t===rt}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&G)===G}neg(t){return Y(-t,this.ORDER)}eql(t,e){return t===e}sqr(t){return Y(t*t,this.ORDER)}add(t,e){return Y(t+e,this.ORDER)}sub(t,e){return Y(t-e,this.ORDER)}mul(t,e){return Y(t*e,this.ORDER)}pow(t,e){return qc(this,t,e)}div(t,e){return Y(t*zo(e,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,e){return t+e}subN(t,e){return t-e}mulN(t,e){return t*e}inv(t){return zo(t,this.ORDER)}sqrt(t){return this._sqrt||(this._sqrt=Pc(this.ORDER)),this._sqrt(this,t)}toBytes(t){return this.isLE?an(t,this.BYTES):tr(t,this.BYTES)}fromBytes(t,e=!1){O(t);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(!n.includes(t.length)||t.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let f=new Uint8Array(o);f.set(t,s?0:f.length-t.length),t=f}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let c=s?Vt(t):ce(t);if(a&&(c=Y(c,i)),!e&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return Te(this,t)}cmov(t,e,n){return n?e:t}};function fe(r,t={}){return new un(r,t)}function es(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let t=r.toString(2).length;return Math.ceil(t/8)}function dn(r){let t=es(r);return t+Math.ceil(t/2)}function pn(r,t,e=!1){O(r);let n=r.length,o=es(t),s=dn(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?Vt(r):ce(r),a=Y(i,t-G)+G;return e?an(a,o):tr(a,o)}var ue=BigInt(0),Zt=BigInt(1);function Re(r,t){let e=t.negate();return r?e:t}function zt(r,t){let e=Te(r.Fp,t.map(n=>n.Z));return t.map((n,o)=>r.fromAffine(n.toAffine(e[o])))}function ss(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function mn(r,t){ss(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=_e(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function rs(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,a=Number(r&o),c=r>>i;a>n&&(a-=s,c+=Zt);let f=t*n,u=f+Math.abs(a)-1,h=a===0,w=a<0,E=t%2!==0;return{nextN:c,offset:u,isZero:h,isNeg:w,isNegF:E,offsetF:f}}var yn=new WeakMap,is=new WeakMap;function bn(r){return is.get(r)||1}function ns(r){if(r!==ue)throw new Error("invalid wNAF")}var he=class{BASE;ZERO;Fn;bits;constructor(t,e){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=e}_unsafeLadder(t,e,n=this.ZERO){let o=t;for(;e>ue;)e&Zt&&(n=n.add(o)),o=o.double(),e>>=Zt;return n}precomputeWindow(t,e){let{windows:n,windowSize:o}=mn(e,this.bits),s=[],i=t,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let f=1;f<o;f++)a=a.add(i),s.push(a);i=a.double()}return s}wNAF(t,e,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=mn(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:f,isZero:u,isNeg:h,isNegF:w,offsetF:E}=rs(n,a,i);n=c,u?s=s.add(Re(w,e[E])):o=o.add(Re(h,e[f]))}return ns(n),{p:o,f:s}}wNAFUnsafe(t,e,n,o=this.ZERO){let s=mn(t,this.bits);for(let i=0;i<s.windows&&n!==ue;i++){let{nextN:a,offset:c,isZero:f,isNeg:u}=rs(n,i,s);if(n=a,!f){let h=e[c];o=o.add(u?h.negate():h)}}return ns(n),o}getPrecomputes(t,e,n){let o=yn.get(e);return o||(o=this.precomputeWindow(e,t),t!==1&&(typeof n=="function"&&(o=n(o)),yn.set(e,o))),o}cached(t,e,n){let o=bn(t);return this.wNAF(o,this.getPrecomputes(o,t,n),e)}unsafe(t,e,n,o){let s=bn(t);return s===1?this._unsafeLadder(t,e,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),e,o)}createCache(t,e){ss(e,this.bits),is.set(t,e),yn.delete(t)}hasCache(t){return bn(t)!==1}};function cs(r,t,e,n){let o=t,s=r.ZERO,i=r.ZERO;for(;e>ue||n>ue;)e&Zt&&(s=s.add(o)),n&Zt&&(i=i.add(o)),o=o.double(),e>>=Zt,n>>=Zt;return{p1:s,p2:i}}function os(r,t,e){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return ln(t),t}else return fe(r,{isLE:e})}function rr(r,t,e={},n){if(n===void 0&&(n=r==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${r} CURVE object`);for(let c of["p","n","h"]){let f=t[c];if(!(typeof f=="bigint"&&f>ue))throw new Error(`CURVE.${c} must be positive bigint`)}let o=os(t.p,e.Fp,n),s=os(t.n,e.Fn,n),a=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}function nr(r,t){return function(n){let o=r(n);return{secretKey:o,publicKey:t(o)}}}var Kt=BigInt(0),X=BigInt(1),gn=BigInt(2),Fc=BigInt(8);function Zc(r,t,e,n){let o=r.sqr(e),s=r.sqr(n),i=r.add(r.mul(t.a,o),s),a=r.add(r.ONE,r.mul(t.d,r.mul(o,s)));return r.eql(i,a)}function as(r,t={}){let e=rr("edwards",r,t,t.FpFnLE),{Fp:n,Fn:o}=e,s=e.CURVE,{h:i}=s;Nt(t,{},{uvRatio:"function"});let a=gn<<BigInt(o.BYTES*8)-X,c=A=>n.create(A),f=t.uvRatio||((A,y)=>{try{return{isValid:!0,value:n.sqrt(n.div(A,y))}}catch{return{isValid:!1,value:Kt}}});if(!Zc(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function u(A,y,v=!1){let b=v?X:Kt;return De("coordinate "+A,y,b,a),y}function h(A){if(!(A instanceof d))throw new Error("EdwardsPoint expected")}let w=ae((A,y)=>{let{X:v,Y:b,Z:I}=A,U=A.is0();y==null&&(y=U?Fc:n.inv(I));let k=c(v*y),M=c(b*y),x=n.mul(I,y);if(U)return{x:Kt,y:X};if(x!==X)throw new Error("invZ was invalid");return{x:k,y:M}}),E=ae(A=>{let{a:y,d:v}=s;if(A.is0())throw new Error("bad point: ZERO");let{X:b,Y:I,Z:U,T:k}=A,M=c(b*b),x=c(I*I),g=c(U*U),N=c(g*g),P=c(M*y),T=c(g*c(P+x)),p=c(N+c(v*c(M*x)));if(T!==p)throw new Error("bad point: equation left != right (1)");let m=c(b*I),l=c(U*k);if(m!==l)throw new Error("bad point: equation left != right (2)");return!0});class d{static BASE=new d(s.Gx,s.Gy,X,c(s.Gx*s.Gy));static ZERO=new d(Kt,X,X,Kt);static Fp=n;static Fn=o;X;Y;Z;T;constructor(y,v,b,I){this.X=u("x",y),this.Y=u("y",v),this.Z=u("z",b,!0),this.T=u("t",I),Object.freeze(this)}static CURVE(){return s}static fromAffine(y){if(y instanceof d)throw new Error("extended point not allowed");let{x:v,y:b}=y||{};return u("x",v),u("y",b),new d(v,b,X,c(v*b))}static fromBytes(y,v=!1){let b=n.BYTES,{a:I,d:U}=s;y=er(O(y,b,"point")),Lt(v,"zip215");let k=er(y),M=y[b-1];k[b-1]=M&-129;let x=Vt(k),g=v?a:n.ORDER;De("point.y",x,Kt,g);let N=c(x*x),P=c(N-X),T=c(U*N-I),{isValid:p,value:m}=f(P,T);if(!p)throw new Error("bad point: invalid y coordinate");let l=(m&X)===X,S=(M&128)!==0;if(!v&&m===Kt&&S)throw new Error("bad point: x=0 and x_0=1");return S!==l&&(m=c(-m)),d.fromAffine({x:m,y:x})}static fromHex(y,v=!1){return d.fromBytes(Bt(y),v)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=8,v=!0){return B.createCache(this,y),v||this.multiply(gn),this}assertValidity(){E(this)}equals(y){h(y);let{X:v,Y:b,Z:I}=this,{X:U,Y:k,Z:M}=y,x=c(v*M),g=c(U*I),N=c(b*M),P=c(k*I);return x===g&&N===P}is0(){return this.equals(d.ZERO)}negate(){return new d(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:y}=s,{X:v,Y:b,Z:I}=this,U=c(v*v),k=c(b*b),M=c(gn*c(I*I)),x=c(y*U),g=v+b,N=c(c(g*g)-U-k),P=x+k,T=P-M,p=x-k,m=c(N*T),l=c(P*p),S=c(N*p),L=c(T*P);return new d(m,l,L,S)}add(y){h(y);let{a:v,d:b}=s,{X:I,Y:U,Z:k,T:M}=this,{X:x,Y:g,Z:N,T:P}=y,T=c(I*x),p=c(U*g),m=c(M*b*P),l=c(k*N),S=c((I+U)*(x+g)-T-p),L=l-m,_=l+m,R=c(p-v*T),D=c(S*L),C=c(_*R),K=c(S*R),F=c(L*_);return new d(D,C,F,K)}subtract(y){return this.add(y.negate())}multiply(y){if(!o.isValidNot0(y))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:v,f:b}=B.cached(this,y,I=>zt(d,I));return zt(d,[v,b])[0]}multiplyUnsafe(y,v=d.ZERO){if(!o.isValid(y))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return y===Kt?d.ZERO:this.is0()||y===X?this:B.unsafe(this,y,b=>zt(d,b),v)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return B.unsafe(this,s.n).is0()}toAffine(y){return w(this,y)}clearCofactor(){return i===X?this:this.multiplyUnsafe(i)}toBytes(){let{x:y,y:v}=this.toAffine(),b=n.toBytes(v);return b[b.length-1]|=y&X?128:0,b}toHex(){return vt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let B=new he(d,o.BITS);return d.BASE.precompute(8),d}function fs(r,t,e={}){if(typeof t!="function")throw new Error('"hash" function param is required');Nt(e,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=e,{BASE:o,Fp:s,Fn:i}=r,a=e.randomBytes||ie,c=e.adjustScalarBytes||(x=>x),f=e.domain||((x,g,N)=>{if(Lt(N,"phflag"),g.length||N)throw new Error("Contexts/pre-hash are not supported");return x});function u(x){return i.create(Vt(x))}function h(x){let g=b.secretKey;O(x,b.secretKey,"secretKey");let N=O(t(x),2*g,"hashedSecretKey"),P=c(N.slice(0,g)),T=N.slice(g,2*g),p=u(P);return{head:P,prefix:T,scalar:p}}function w(x){let{head:g,prefix:N,scalar:P}=h(x),T=o.multiply(P),p=T.toBytes();return{head:g,prefix:N,scalar:P,point:T,pointBytes:p}}function E(x){return w(x).pointBytes}function d(x=Uint8Array.of(),...g){let N=st(...g);return u(t(f(N,O(x,void 0,"context"),!!n)))}function B(x,g,N={}){x=O(x,void 0,"message"),n&&(x=n(x));let{prefix:P,scalar:T,pointBytes:p}=w(g),m=d(N.context,P,x),l=o.multiply(m).toBytes(),S=d(N.context,l,p,x),L=i.create(m+S*T);if(!i.isValid(L))throw new Error("sign failed: invalid s");let _=st(l,i.toBytes(L));return O(_,b.signature,"result")}let A={zip215:!0};function y(x,g,N,P=A){let{context:T,zip215:p}=P,m=b.signature;x=O(x,m,"signature"),g=O(g,void 0,"message"),N=O(N,b.publicKey,"publicKey"),p!==void 0&&Lt(p,"zip215"),n&&(g=n(g));let l=m/2,S=x.subarray(0,l),L=Vt(x.subarray(l,m)),_,R,D;try{_=r.fromBytes(N,p),R=r.fromBytes(S,p),D=o.multiplyUnsafe(L)}catch{return!1}if(!p&&_.isSmallOrder())return!1;let C=d(T,R.toBytes(),_.toBytes(),g);return R.add(_.multiplyUnsafe(C)).subtract(D).clearCofactor().is0()}let v=s.BYTES,b={secretKey:v,publicKey:v,signature:2*v,seed:v};function I(x=a(b.seed)){return O(x,b.seed,"seed")}function U(x){return Pt(x)&&x.length===i.BYTES}function k(x,g){try{return!!r.fromBytes(x,g)}catch{return!1}}let M={getExtendedPublicKey:w,randomSecretKey:I,isValidSecretKey:U,isValidPublicKey:k,toMontgomery(x){let{y:g}=r.fromBytes(x),N=b.publicKey,P=N===32;if(!P&&N!==57)throw new Error("only defined for 25519 and 448");let T=P?s.div(X+g,X-g):s.div(g-X,g+X);return s.toBytes(T)},toMontgomerySecret(x){let g=b.secretKey;O(x,g);let N=t(x.subarray(0,g));return c(N).subarray(0,g)}};return Object.freeze({keygen:nr(I,E),getPublicKey:E,sign:B,verify:y,utils:M,Point:r,lengths:b})}var zc=BigInt(1),us=BigInt(2);var $c=BigInt(5),Yc=BigInt(8),xn=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),jc={p:xn,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Yc,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Gc(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=xn,a=r*r%s*r%s,c=V(a,us,s)*a%s,f=V(c,zc,s)*r%s,u=V(f,$c,s)*f%s,h=V(u,t,s)*u%s,w=V(h,e,s)*h%s,E=V(w,n,s)*w%s,d=V(E,o,s)*E%s,B=V(d,o,s)*E%s,A=V(B,t,s)*u%s;return{pow_p_5_8:V(A,us,s)*r%s,b2:a}}function Xc(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var hs=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Wc(r,t){let e=xn,n=Y(t*t*t,e),o=Y(n*n*t,e),s=Gc(r*o).pow_p_5_8,i=Y(r*n*s,e),a=Y(t*i*i,e),c=i,f=Y(i*hs,e),u=a===r,h=a===Y(-r,e),w=a===Y(-r*hs,e);return u&&(i=c),(h||w)&&(i=f),ts(i,e)&&(i=Y(-i,e)),{isValid:u||h,value:i}}var Qc=as(jc,{uvRatio:Wc});function Jc(r){return fs(Qc,qo,Object.assign({adjustScalarBytes:Xc},r))}var ls=Jc({});var Ce=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},or=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var ds={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new or("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 sr=ds;var ir=32;var wn,ta=(async()=>{try{return await sr.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function ea(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await sr.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await sr.get().subtle.verify({name:"Ed25519"},n,t,e instanceof Uint8Array?e:e.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function ra(r,t,e){return ls.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function ps(r,t,e){return wn==null&&(wn=await ta),wn?ea(r,t,e):ra(r,t,e)}function cr(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var ar=class{type="Ed25519";raw;constructor(t){this.raw=En(t,ir)}toMultihash(){return ht.digest(oe(this))}toCID(){return Q.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let o=ps(this.raw,e,t);return cr(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function ys(r){return r=En(r,ir),new ar(r)}function En(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new yt(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var oa=Math.pow(2,7),sa=Math.pow(2,14),ia=Math.pow(2,21),bs=Math.pow(2,28),gs=Math.pow(2,35),xs=Math.pow(2,42),ws=Math.pow(2,49),nt=128,Ot=127;function Ue(r){if(r<oa)return 1;if(r<sa)return 2;if(r<ia)return 3;if(r<bs)return 4;if(r<gs)return 5;if(r<xs)return 6;if(r<ws)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Es(r,t,e=0){switch(Ue(r)){case 8:t[e++]=r&255|nt,r/=128;case 7:t[e++]=r&255|nt,r/=128;case 6:t[e++]=r&255|nt,r/=128;case 5:t[e++]=r&255|nt,r/=128;case 4:t[e++]=r&255|nt,r>>>=7;case 3:t[e++]=r&255|nt,r>>>=7;case 2:t[e++]=r&255|nt,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Ss(r,t){let e=r[t],n=0;if(n+=e&Ot,e<nt||(e=r[t+1],n+=(e&Ot)<<7,e<nt)||(e=r[t+2],n+=(e&Ot)<<14,e<nt)||(e=r[t+3],n+=(e&Ot)<<21,e<nt)||(e=r[t+4],n+=(e&Ot)*bs,e<nt)||(e=r[t+5],n+=(e&Ot)*gs,e<nt)||(e=r[t+6],n+=(e&Ot)*xs,e<nt)||(e=r[t+7],n+=(e&Ot)*ws,e<nt))return n;throw new RangeError("Could not decode varint")}var Sn=new Float32Array([-0]),kt=new Uint8Array(Sn.buffer);function As(r,t,e){Sn[0]=r,t[e]=kt[0],t[e+1]=kt[1],t[e+2]=kt[2],t[e+3]=kt[3]}function vs(r,t){return kt[0]=r[t],kt[1]=r[t+1],kt[2]=r[t+2],kt[3]=r[t+3],Sn[0]}var An=new Float64Array([-0]),et=new Uint8Array(An.buffer);function Bs(r,t,e){An[0]=r,t[e]=et[0],t[e+1]=et[1],t[e+2]=et[2],t[e+3]=et[3],t[e+4]=et[4],t[e+5]=et[5],t[e+6]=et[6],t[e+7]=et[7]}function Is(r,t){return et[0]=r[t],et[1]=r[t+1],et[2]=r[t+2],et[3]=r[t+3],et[4]=r[t+4],et[5]=r[t+5],et[6]=r[t+6],et[7]=r[t+7],An[0]}var ca=BigInt(Number.MAX_SAFE_INTEGER),aa=BigInt(Number.MIN_SAFE_INTEGER),ft=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+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 e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(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,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return $t;if(t<ca&&t>aa)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>Ls&&(o=0n,++n>Ls&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return $t;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):$t}},$t=new ft(0,0);$t.toBigInt=function(){return 0n};$t.zzEncode=$t.zzDecode=function(){return this};$t.length=function(){return 1};var Ls=4294967296n;function Ds(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function _s(r,t,e){if(e-t<1)return"";let o,s=[],i=0,a;for(;t<e;)a=r[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function vn(r,t,e){let n=e,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function pt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function fr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Bn=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,pt(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 pt(this,4);return fr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw pt(this,4);return fr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw pt(this,4);let t=vs(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw pt(this,4);let t=Is(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw pt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return _s(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw pt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw pt(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 ft(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*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;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw pt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw pt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw pt(this,8);let t=fr(this.buf,this.pos+=4),e=fr(this.buf,this.pos+=4);return new ft(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Ss(this.buf,this.pos);return this.pos+=Ue(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 In(r){return new Bn(r instanceof Uint8Array?r:r.subarray())}function ur(r,t,e){let n=In(r);return t.decode(n,void 0,e)}function Ln(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return ct(i);o+i>t&&(n=ct(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Yt=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Dn(){}var Tn=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},fa=Ln();function ua(r){return globalThis.Buffer!=null?ct(r):fa(r)}var Ke=class{len;head;tail;states;constructor(){this.len=0,this.head=new Yt(Dn,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new Yt(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Rn((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(hr,10,ft.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=ft.fromBigInt(t);return this._push(hr,e.length(),e)}uint64Number(t){return this._push(Es,Ue(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 e=ft.fromBigInt(t).zzEncode();return this._push(hr,e.length(),e)}sint64Number(t){let e=ft.fromNumber(t).zzEncode();return this._push(hr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(_n,1,t?1:0)}fixed32(t){return this._push(Ne,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=ft.fromBigInt(t);return this._push(Ne,4,e.lo)._push(Ne,4,e.hi)}fixed64Number(t){let e=ft.fromNumber(t);return this._push(Ne,4,e.lo)._push(Ne,4,e.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(As,4,t)}double(t){return this._push(Bs,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(_n,1,0):this.uint32(e)._push(la,e,t)}string(t){let e=Ds(t);return e!==0?this.uint32(e)._push(vn,e,t):this._push(_n,1,0)}fork(){return this.states=new Tn(this),this.head=this.tail=new Yt(Dn,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 Yt(Dn,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=ua(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function _n(r,t,e){t[e]=r&255}function ha(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Rn=class extends Yt{next;constructor(t,e){super(ha,t,e),this.next=void 0}};function hr(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function Ne(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function la(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Ke.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(da,t,r),this},Ke.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(pa,t,r),this});function da(r,t,e){t.set(r,e)}function pa(r,t,e){r.length<40?vn(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(Tt(r),e)}function Cn(){return new Ke}function lr(r,t){let e=Cn();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var le;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(le||(le={}));function dr(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Un(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(s,i){let a=t(s);i.int32(a)},n=function(s){let i=s.int32();return t(i)};return dr("enum",le.VARINT,e,n)}function pr(r,t){return dr("message",le.LENGTH_DELIMITED,r,t)}var ut;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(ut||(ut={}));var Nn;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(Nn||(Nn={}));(function(r){r.codec=()=>Un(Nn)})(ut||(ut={}));var Oe;(function(r){let t;r.codec=()=>(t==null&&(t=pr((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),ut.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=ut.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>lr(e,r.codec()),r.decode=(e,n)=>ur(e,r.codec(),n)})(Oe||(Oe={}));var Kn;(function(r){let t;r.codec=()=>(t==null&&(t=pr((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),ut.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=ut.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>lr(e,r.codec()),r.decode=(e,n)=>ur(e,r.codec(),n)})(Kn||(Kn={}));var mr=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(t,e){if(Xe(t),O(e,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(e.length>n?t.create().update(e).digest():e);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=t.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),At(o)}update(t){return se(this),this.iHash.update(t),this}digestInto(t){se(this),O(t,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:e,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},On=(r,t,e)=>new mr(r,t).update(e).digest();On.create=(r,t)=>new mr(r,t);var Rs=(r,t)=>(r+(r>=0?t:-t)/Cs)/t;function ya(r,t,e){let[[n,o],[s,i]]=t,a=Rs(i*r,e),c=Rs(-o*r,e),f=r-a*n-c*s,u=-a*o-c*i,h=f<Dt,w=u<Dt;h&&(f=-f),w&&(u=-u);let E=_e(Math.ceil(fn(e)/2))+de;if(f<Dt||f>=E||u<Dt||u>=E)throw new Error("splitScalar (endomorphism): failed, k="+r);return{k1neg:h,k1:f,k2neg:w,k2:u}}function Mn(r){if(!["compact","recovered","der"].includes(r))throw new Error('Signature format must be "compact", "recovered", or "der"');return r}function kn(r,t){let e={};for(let n of Object.keys(t))e[n]=r[n]===void 0?t[n]:r[n];return Lt(e.lowS,"lowS"),Lt(e.prehash,"prehash"),e.format!==void 0&&Mn(e.format),e}var Pn=class extends Error{constructor(t=""){super(t)}},Mt={Err:Pn,_tlv:{encode:(r,t)=>{let{Err:e}=Mt;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,o=Le(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?Le(o.length/2|128):"";return Le(r)+s+o+t},decode(r,t){let{Err:e}=Mt,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new e("tlv.decode(long): indefinite length not supported");if(c>4)throw new e("tlv.decode(long): byte length is too big");let f=t.subarray(n,n+c);if(f.length!==c)throw new e("tlv.decode: length bytes not complete");if(f[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let u of f)i=i<<8|u;if(n+=c,i<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=Mt;if(r<Dt)throw new t("integer: negative integers are not allowed");let e=Le(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return e},decode(r){let{Err:t}=Mt;if(r[0]&128)throw new t("invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return ce(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Mt,o=O(r,void 0,"signature"),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:f,l:u}=n.decode(2,c);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(f)}},hexFromSig(r){let{_tlv:t,_int:e}=Mt,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}},Dt=BigInt(0),de=BigInt(1),Cs=BigInt(2),yr=BigInt(3),ba=BigInt(4);function Us(r,t={}){let e=rr("weierstrass",r,t),{Fp:n,Fn:o}=e,s=e.CURVE,{h:i,n:a}=s;Nt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c}=t;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let f=Ks(n,o);function u(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function h(T,p,m){let{x:l,y:S}=p.toAffine(),L=n.toBytes(l);if(Lt(m,"isCompressed"),m){u();let _=!n.isOdd(S);return st(Ns(_),L)}else return st(Uint8Array.of(4),L,n.toBytes(S))}function w(T){O(T,void 0,"Point");let{publicKey:p,publicKeyUncompressed:m}=f,l=T.length,S=T[0],L=T.subarray(1);if(l===p&&(S===2||S===3)){let _=n.fromBytes(L);if(!n.isValid(_))throw new Error("bad point: is not on curve, wrong x");let R=B(_),D;try{D=n.sqrt(R)}catch(F){let q=F instanceof Error?": "+F.message:"";throw new Error("bad point: is not on curve, sqrt error"+q)}u();let C=n.isOdd(D);return(S&1)===1!==C&&(D=n.neg(D)),{x:_,y:D}}else if(l===m&&S===4){let _=n.BYTES,R=n.fromBytes(L.subarray(0,_)),D=n.fromBytes(L.subarray(_,_*2));if(!A(R,D))throw new Error("bad point: is not on curve");return{x:R,y:D}}else throw new Error(`bad point: got length ${l}, expected compressed=${p} or uncompressed=${m}`)}let E=t.toBytes||h,d=t.fromBytes||w;function B(T){let p=n.sqr(T),m=n.mul(p,T);return n.add(n.add(m,n.mul(T,s.a)),s.b)}function A(T,p){let m=n.sqr(p),l=B(T);return n.eql(m,l)}if(!A(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let y=n.mul(n.pow(s.a,yr),ba),v=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(y,v)))throw new Error("bad curve params: a or b");function b(T,p,m=!1){if(!n.isValid(p)||m&&n.is0(p))throw new Error(`bad point coordinate ${T}`);return p}function I(T){if(!(T instanceof g))throw new Error("Weierstrass Point expected")}function U(T){if(!c||!c.basises)throw new Error("no endo");return ya(T,c.basises,o.ORDER)}let k=ae((T,p)=>{let{X:m,Y:l,Z:S}=T;if(n.eql(S,n.ONE))return{x:m,y:l};let L=T.is0();p==null&&(p=L?n.ONE:n.inv(S));let _=n.mul(m,p),R=n.mul(l,p),D=n.mul(S,p);if(L)return{x:n.ZERO,y:n.ZERO};if(!n.eql(D,n.ONE))throw new Error("invZ was invalid");return{x:_,y:R}}),M=ae(T=>{if(T.is0()){if(t.allowInfinityPoint&&!n.is0(T.Y))return;throw new Error("bad point: ZERO")}let{x:p,y:m}=T.toAffine();if(!n.isValid(p)||!n.isValid(m))throw new Error("bad point: x or y not field elements");if(!A(p,m))throw new Error("bad point: equation left != right");if(!T.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function x(T,p,m,l,S){return m=new g(n.mul(m.X,T),m.Y,m.Z),p=Re(l,p),m=Re(S,m),p.add(m)}class g{static BASE=new g(s.Gx,s.Gy,n.ONE);static ZERO=new g(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(p,m,l){this.X=b("x",p),this.Y=b("y",m,!0),this.Z=b("z",l),Object.freeze(this)}static CURVE(){return s}static fromAffine(p){let{x:m,y:l}=p||{};if(!p||!n.isValid(m)||!n.isValid(l))throw new Error("invalid affine point");if(p instanceof g)throw new Error("projective point not allowed");return n.is0(m)&&n.is0(l)?g.ZERO:new g(m,l,n.ONE)}static fromBytes(p){let m=g.fromAffine(d(O(p,void 0,"point")));return m.assertValidity(),m}static fromHex(p){return g.fromBytes(Bt(p))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=8,m=!0){return P.createCache(this,p),m||this.multiply(yr),this}assertValidity(){M(this)}hasEvenY(){let{y:p}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(p)}equals(p){I(p);let{X:m,Y:l,Z:S}=this,{X:L,Y:_,Z:R}=p,D=n.eql(n.mul(m,R),n.mul(L,S)),C=n.eql(n.mul(l,R),n.mul(_,S));return D&&C}negate(){return new g(this.X,n.neg(this.Y),this.Z)}double(){let{a:p,b:m}=s,l=n.mul(m,yr),{X:S,Y:L,Z:_}=this,R=n.ZERO,D=n.ZERO,C=n.ZERO,K=n.mul(S,S),F=n.mul(L,L),q=n.mul(_,_),H=n.mul(S,L);return H=n.add(H,H),C=n.mul(S,_),C=n.add(C,C),R=n.mul(p,C),D=n.mul(l,q),D=n.add(R,D),R=n.sub(F,D),D=n.add(F,D),D=n.mul(R,D),R=n.mul(H,R),C=n.mul(l,C),q=n.mul(p,q),H=n.sub(K,q),H=n.mul(p,H),H=n.add(H,C),C=n.add(K,K),K=n.add(C,K),K=n.add(K,q),K=n.mul(K,H),D=n.add(D,K),q=n.mul(L,_),q=n.add(q,q),K=n.mul(q,H),R=n.sub(R,K),C=n.mul(q,F),C=n.add(C,C),C=n.add(C,C),new g(R,D,C)}add(p){I(p);let{X:m,Y:l,Z:S}=this,{X:L,Y:_,Z:R}=p,D=n.ZERO,C=n.ZERO,K=n.ZERO,F=s.a,q=n.mul(s.b,yr),H=n.mul(m,L),Z=n.mul(l,_),W=n.mul(S,R),mt=n.add(m,l),z=n.add(L,_);mt=n.mul(mt,z),z=n.add(H,Z),mt=n.sub(mt,z),z=n.add(m,S);let tt=n.add(L,R);return z=n.mul(z,tt),tt=n.add(H,W),z=n.sub(z,tt),tt=n.add(l,S),D=n.add(_,R),tt=n.mul(tt,D),D=n.add(Z,W),tt=n.sub(tt,D),K=n.mul(F,z),D=n.mul(q,W),K=n.add(D,K),D=n.sub(Z,K),K=n.add(Z,K),C=n.mul(D,K),Z=n.add(H,H),Z=n.add(Z,H),W=n.mul(F,W),z=n.mul(q,z),Z=n.add(Z,W),W=n.sub(H,W),W=n.mul(F,W),z=n.add(z,W),H=n.mul(Z,z),C=n.add(C,H),H=n.mul(tt,z),D=n.mul(mt,D),D=n.sub(D,H),H=n.mul(mt,Z),K=n.mul(tt,K),K=n.add(K,H),new g(D,C,K)}subtract(p){return this.add(p.negate())}is0(){return this.equals(g.ZERO)}multiply(p){let{endo:m}=t;if(!o.isValidNot0(p))throw new Error("invalid scalar: out of range");let l,S,L=_=>P.cached(this,_,R=>zt(g,R));if(m){let{k1neg:_,k1:R,k2neg:D,k2:C}=U(p),{p:K,f:F}=L(R),{p:q,f:H}=L(C);S=F.add(H),l=x(m.beta,K,q,_,D)}else{let{p:_,f:R}=L(p);l=_,S=R}return zt(g,[l,S])[0]}multiplyUnsafe(p){let{endo:m}=t,l=this;if(!o.isValid(p))throw new Error("invalid scalar: out of range");if(p===Dt||l.is0())return g.ZERO;if(p===de)return l;if(P.hasCache(this))return this.multiply(p);if(m){let{k1neg:S,k1:L,k2neg:_,k2:R}=U(p),{p1:D,p2:C}=cs(g,l,L,R);return x(m.beta,D,C,S,_)}else return P.unsafe(l,p)}toAffine(p){return k(this,p)}isTorsionFree(){let{isTorsionFree:p}=t;return i===de?!0:p?p(g,this):P.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:p}=t;return i===de?this:p?p(g,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(p=!0){return Lt(p,"isCompressed"),this.assertValidity(),E(g,this,p)}toHex(p=!0){return vt(this.toBytes(p))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let N=o.BITS,P=new he(g,t.endo?Math.ceil(N/2):N);return g.BASE.precompute(8),g}function Ns(r){return Uint8Array.of(r?2:3)}function Ks(r,t){return{secretKey:t.BYTES,publicKey:1+r.BYTES,publicKeyUncompressed:1+2*r.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function ga(r,t={}){let{Fn:e}=r,n=t.randomBytes||ie,o=Object.assign(Ks(r.Fp,e),{seed:dn(e.ORDER)});function s(E){try{let d=e.fromBytes(E);return e.isValidNot0(d)}catch{return!1}}function i(E,d){let{publicKey:B,publicKeyUncompressed:A}=o;try{let y=E.length;return d===!0&&y!==B||d===!1&&y!==A?!1:!!r.fromBytes(E)}catch{return!1}}function a(E=n(o.seed)){return pn(O(E,o.seed,"seed"),e.ORDER)}function c(E,d=!0){return r.BASE.multiply(e.fromBytes(E)).toBytes(d)}function f(E){let{secretKey:d,publicKey:B,publicKeyUncompressed:A}=o;if(!Pt(E)||"_lengths"in e&&e._lengths||d===B)return;let y=O(E,void 0,"key").length;return y===B||y===A}function u(E,d,B=!0){if(f(E)===!0)throw new Error("first arg must be private key");if(f(d)===!1)throw new Error("second arg must be public key");let A=e.fromBytes(E);return r.fromBytes(d).multiply(A).toBytes(B)}let h={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},w=nr(a,c);return Object.freeze({getPublicKey:c,getSharedSecret:u,keygen:w,Point:r,utils:h,lengths:o})}function Os(r,t,e={}){Xe(t),Nt(e,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),e=Object.assign({},e);let n=e.randomBytes||ie,o=e.hmac||((m,l)=>On(t,m,l)),{Fp:s,Fn:i}=r,{ORDER:a,BITS:c}=i,{keygen:f,getPublicKey:u,getSharedSecret:h,utils:w,lengths:E}=ga(r,e),d={prehash:!0,lowS:typeof e.lowS=="boolean"?e.lowS:!0,format:"compact",extraEntropy:!1},B=a*Cs<s.ORDER;function A(m){let l=a>>de;return m>l}function y(m,l){if(!i.isValidNot0(l))throw new Error(`invalid signature ${m}: out of range 1..Point.Fn.ORDER`);return l}function v(){if(B)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function b(m,l){Mn(l);let S=E.signature,L=l==="compact"?S:l==="recovered"?S+1:void 0;return O(m,L)}class I{r;s;recovery;constructor(l,S,L){if(this.r=y("r",l),this.s=y("s",S),L!=null){if(v(),![0,1,2,3].includes(L))throw new Error("invalid recovery id");this.recovery=L}Object.freeze(this)}static fromBytes(l,S=d.format){b(l,S);let L;if(S==="der"){let{r:C,s:K}=Mt.toSig(O(l));return new I(C,K)}S==="recovered"&&(L=l[0],S="compact",l=l.subarray(1));let _=E.signature/2,R=l.subarray(0,_),D=l.subarray(_,_*2);return new I(i.fromBytes(R),i.fromBytes(D),L)}static fromHex(l,S){return this.fromBytes(Bt(l),S)}assertRecovery(){let{recovery:l}=this;if(l==null)throw new Error("invalid recovery id: must be present");return l}addRecoveryBit(l){return new I(this.r,this.s,l)}recoverPublicKey(l){let{r:S,s:L}=this,_=this.assertRecovery(),R=_===2||_===3?S+a:S;if(!s.isValid(R))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let D=s.toBytes(R),C=r.fromBytes(st(Ns((_&1)===0),D)),K=i.inv(R),F=k(O(l,void 0,"msgHash")),q=i.create(-F*K),H=i.create(L*K),Z=r.BASE.multiplyUnsafe(q).add(C.multiplyUnsafe(H));if(Z.is0())throw new Error("invalid recovery: point at infinify");return Z.assertValidity(),Z}hasHighS(){return A(this.s)}toBytes(l=d.format){if(Mn(l),l==="der")return Bt(Mt.hexFromSig(this));let{r:S,s:L}=this,_=i.toBytes(S),R=i.toBytes(L);return l==="recovered"?(v(),st(Uint8Array.of(this.assertRecovery()),_,R)):st(_,R)}toHex(l){return vt(this.toBytes(l))}}let U=e.bits2int||function(l){if(l.length>8192)throw new Error("input is too large");let S=ce(l),L=l.length*8-c;return L>0?S>>BigInt(L):S},k=e.bits2int_modN||function(l){return i.create(U(l))},M=_e(c);function x(m){return De("num < 2^"+c,m,Dt,M),i.toBytes(m)}function g(m,l){return O(m,void 0,"message"),l?O(t(m),void 0,"prehashed message"):m}function N(m,l,S){let{lowS:L,prehash:_,extraEntropy:R}=kn(S,d);m=g(m,_);let D=k(m),C=i.fromBytes(l);if(!i.isValidNot0(C))throw new Error("invalid private key");let K=[x(C),x(D)];if(R!=null&&R!==!1){let Z=R===!0?n(E.secretKey):R;K.push(O(Z,void 0,"extraEntropy"))}let F=st(...K),q=D;function H(Z){let W=U(Z);if(!i.isValidNot0(W))return;let mt=i.inv(W),z=r.BASE.multiply(W).toAffine(),tt=i.create(z.x);if(tt===Dt)return;let Pe=i.create(mt*i.create(q+tt*C));if(Pe===Dt)return;let Vn=(z.x===tt?0:2)|Number(z.y&de),Fn=Pe;return L&&A(Pe)&&(Fn=i.neg(Pe),Vn^=1),new I(tt,Fn,B?void 0:Vn)}return{seed:F,k2sig:H}}function P(m,l,S={}){let{seed:L,k2sig:_}=N(m,l,S);return Zo(t.outputLen,i.BYTES,o)(L,_).toBytes(S.format)}function T(m,l,S,L={}){let{lowS:_,prehash:R,format:D}=kn(L,d);if(S=O(S,void 0,"publicKey"),l=g(l,R),!Pt(m)){let C=m instanceof I?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+C)}b(m,D);try{let C=I.fromBytes(m,D),K=r.fromBytes(S);if(_&&C.hasHighS())return!1;let{r:F,s:q}=C,H=k(l),Z=i.inv(q),W=i.create(H*Z),mt=i.create(F*Z),z=r.BASE.multiplyUnsafe(W).add(K.multiplyUnsafe(mt));return z.is0()?!1:i.create(z.x)===F}catch{return!1}}function p(m,l,S={}){let{prehash:L}=kn(S,d);return l=g(l,L),I.fromBytes(m,"recovered").recoverPublicKey(l).toBytes()}return Object.freeze({keygen:f,getPublicKey:u,getSharedSecret:h,utils:w,lengths:E,Point:r,sign:P,verify:T,recoverPublicKey:p,Signature:I,hash:t})}var qn={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},xa={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var ks=BigInt(2);function wa(r){let t=qn.p,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),f=r*r*r%t,u=f*f*r%t,h=V(u,e,t)*u%t,w=V(h,e,t)*u%t,E=V(w,ks,t)*f%t,d=V(E,o,t)*E%t,B=V(d,s,t)*d%t,A=V(B,a,t)*B%t,y=V(A,c,t)*A%t,v=V(y,a,t)*B%t,b=V(v,e,t)*u%t,I=V(b,i,t)*d%t,U=V(I,n,t)*f%t,k=V(U,ks,t);if(!Hn.eql(Hn.sqr(k),r))throw new Error("Cannot find square root");return k}var Hn=fe(qn.p,{sqrt:wa}),Ea=Us(qn,{Fp:Hn,endo:xa}),pe=Os(Ea,Ho);function Ms(r,t,e,n){let o=xe.digest(e instanceof Uint8Array?e:e.subarray());if(cr(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),pe.verify(t,s,r,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new Ce(String(s))});try{return n?.signal?.throwIfAborted(),pe.verify(t,o.digest,r,{prehash:!1,format:"der"})}catch(s){throw new Ce(String(s))}}var br=class{type="secp256k1";raw;_key;constructor(t){this._key=Hs(t),this.raw=Ps(this._key)}toMultihash(){return ht.digest(oe(this))}toCID(){return Q.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}verify(t,e,n){return Ms(this._key,e,t,n)}};function qs(r){return new br(r)}function Ps(r){return pe.Point.fromBytes(r).toBytes()}function Hs(r){try{return pe.Point.fromBytes(r),r}catch(t){throw new Ze(String(t))}}function Vs(r){let{Type:t,Data:e}=Oe.decode(r.digest),n=e??new Uint8Array;switch(t){case ut.Ed25519:return ys(n);case ut.secp256k1:return qs(n);case ut.ECDSA:return Ao(n);default:throw new Ee}}function oe(r){return Oe.encode({Type:ut[r.type],Data:r.raw})}var Fs=Symbol.for("nodejs.util.inspect.custom"),Sa=114,ke=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()})`}[Zr]=!0;toString(){return this.string==null&&(this.string=j.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return Q.createV1(Sa,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return lt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return lt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Fs](){return`PeerId(${this.toString()})`}},gr=class extends ke{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},xr=class extends ke{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},wr=class extends ke{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Aa=2336,Me=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=ht.digest(Tt(this.url))}[Fs](){return`PeerId(${this.url})`}[Zr]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return Q.createV1(Aa,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=ot(t)),t.toString()===this.toString())}};var va=114,Zs=2336;function zs(r,t){let e;if(r.charAt(0)==="1"||r.charAt(0)==="Q")e=ge(j.decode(`z${r}`));else{if(r.startsWith("k51qzi5uqu5")||r.startsWith("kzwfwjn5ji4")||r.startsWith("k2k4r8")||r.startsWith("bafz"))return Ba(Q.parse(r));if(t==null)throw new yt('Please pass a multibase decoder for strings that do not start with "1" or "Q"');e=ge(t.decode(r))}return $s(e)}function $s(r){if(La(r))return new gr({multihash:r});if(Ia(r))try{let t=Vs(r);if(t.type==="Ed25519")return new xr({multihash:r,publicKey:t});if(t.type==="secp256k1")return new wr({multihash:r,publicKey:t})}catch{let e=ot(r.digest);return new Me(new URL(e))}throw new $e("Supplied PeerID Multihash is invalid")}function Ba(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==va&&r.code!==Zs)throw new ze("Supplied PeerID CID is invalid");if(r.code===Zs){let t=ot(r.multihash.digest);return new Me(new URL(t))}return $s(r.multihash)}function Ia(r){return r.code===ht.code}function La(r){return r.code===xe.code}var Ys=(r,t)=>{let[,e,n,...o]=r.split("/");if(e!=="ipns")throw new re(`Namespace ${e} was not "ipns"`);try{return{namespace:"ipns",peerId:zs(n),path:o.length>0?`/${o.join("/")}`:"",answer:t}}catch{return{namespace:"dnslink",value:n,path:o.length>0?`/${o.join("/")}`:"",answer:t}}};var Er=class{dns;log;namespaces;cache;cacheMaxAnswers;constructor(t,e={}){this.dns=t.dns,this.log=t.logger.forComponent("helia:dnslink"),this.namespaces={ipfs:yo,ipns:Ys,...e.namespaces},this.cache=new ee({maxSize:e.cacheSize??1e3,maxAge:e.cacheMaxAge??3e4}),this.cacheMaxAnswers=e.cacheMaxAnswers??10}async resolve(t,e={}){if(e.nocache!==!0){let i=this.cache.get(t);if(i!=null){let a=[...i.values()];if(a.length>0)return a}}let n=await this.recursiveResolveDomain(t,e.maxRecursiveDepth??mo,e),o=new ee({maxSize:this.cacheMaxAnswers});n.forEach((i,a)=>{o.set(a,i,{maxAge:i.answer.TTL*1e3})});let s=n.reduce((i,a)=>{let c=a.answer.TTL*1e3;return c>i?c:i},0);return this.cache.maxAge<s&&(s=this.cache.maxAge),this.cache.set(t,o,{maxAge:s}),n}async recursiveResolveDomain(t,e,n={}){if(e===0)throw new Error("recursion limit exceeded");t.startsWith("_dnslink.")||(t=`_dnslink.${t}`);try{return await this.recursiveResolveDnslink(t,e,n)}catch(o){if(o.code!=="ENOTFOUND"&&o.code!=="ENODATA"&&o.name!=="DNSLinkNotFoundError"&&o.name!=="NotFoundError")throw o;return t.startsWith("_dnslink.")?t=t.replace("_dnslink.",""):t=`_dnslink.${t}`,this.recursiveResolveDnslink(t,e,n)}}async recursiveResolveDnslink(t,e,n={}){if(e===0)throw new Error("recursion limit exceeded");this.log("query %s for TXT and CNAME records",t);let s=((await this.dns.query(t,{...n,types:[xt.TXT]}))?.Answer??[]).sort((f,u)=>f.data.localeCompare(u.data));this.log("found %d TXT records for %s",s.length,t);let i=[];for(let f of s)try{let u=f.data;if(u.startsWith('"')&&u.endsWith('"')&&(u=u.substring(1,u.length-1)),!u.startsWith("dnslink="))continue;this.log("%s TXT %s",f.name,u),u=u.replace("dnslink=","");let[,h,w]=u.split("/");if(h==="dnslink"){i.push(...await this.recursiveResolveDomain(w,e-1,n));continue}let E=this.namespaces[h];if(E==null){this.log('unknown protocol "%s" in DNSLink record for domain: %s',h,t);continue}let d=E(u,f);if(d.namespace==="dnslink"){i.push(...await this.recursiveResolveDomain(d.value,e-1,n));continue}i.push(E(u,f))}catch(u){this.log.error("could not parse DNS link record for domain %s, %s - %e",t,f.data,u)}if(i.length>0)return i;this.log("no DNSLink records found for %s, falling back to CNAME",t);let c=((await this.dns.query(t,{...n,types:[xt.CNAME]}))?.Answer??[]).sort((f,u)=>f.data.localeCompare(u.data));this.log("found %d CNAME records for %s",c.length,t);for(let f of c)try{return await this.recursiveResolveDomain(f.data,e-1,n)}catch(u){this.log.error("domain %s cname %s had no DNSLink records - %e",t,f.data,u)}throw new Fe(`No DNSLink records found for domain: ${t}`)}};function Da(r,t={}){return new Er(r,t)}return ei(_a);})();
3
3
  /*! Bundled license information:
4
4
 
5
5
  @noble/hashes/utils.js: