@helia/dnslink 1.2.0 → 1.2.1-eb1908b3

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