@helia/dnslink 1.2.1-6f8165b5 → 1.2.1-73a28eda
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +4 -4
- package/package.json +1 -1
package/dist/index.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.HeliaDnslink = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var HeliaDnslink=(()=>{var Bf=Object.create;var Vr=Object.defineProperty;var If=Object.getOwnPropertyDescriptor;var Df=Object.getOwnPropertyNames;var Cf=Object.getPrototypeOf,Tf=Object.prototype.hasOwnProperty;var Lf=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),M=(r,e)=>{for(var t in e)Vr(r,t,{get:e[t],enumerable:!0})},hi=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Df(e))!Tf.call(r,o)&&o!==t&&Vr(r,o,{get:()=>e[o],enumerable:!(n=If(e,o))||n.enumerable});return r};var Uf=(r,e,t)=>(t=r!=null?Bf(Cf(r)):{},hi(e||!r||!r.__esModule?Vr(t,"default",{value:r,enumerable:!0}):t,r)),_f=r=>hi(Vr({},"__esModule",{value:!0}),r);var Fi=Lf((bm,Ni)=>{Ni.exports=function(r){if(!r)throw Error("hashlru must have a max value, of type number, greater than 0");var e=0,t=Object.create(null),n=Object.create(null);function o(s,i){t[s]=i,e++,e>=r&&(e=0,n=t,t=Object.create(null))}return{has:function(s){return t[s]!==void 0||n[s]!==void 0},remove:function(s){t[s]!==void 0&&(t[s]=void 0),n[s]!==void 0&&(n[s]=void 0)},get:function(s){var i=t[s];if(i!==void 0)return i;if((i=n[s])!==void 0)return o(s,i),i},set:function(s,i){t[s]!==void 0?t[s]=i:o(s,i)},clear:function(){t=Object.create(null),n=Object.create(null)}}}});var n0={};M(n0,{dnsLink:()=>r0});var Hn={};M(Hn,{base10:()=>Pf});var f0=new Uint8Array(0);function di(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function De(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 li(r){return new TextEncoder().encode(r)}function pi(r){return new TextDecoder().decode(r)}function Rf(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(t[i]!==255)throw new TypeError(s+" is ambiguous");t[i]=o}var a=r.length,f=r.charAt(0),c=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function d(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var b=0,l=0,p=0,x=h.length;p!==x&&h[p]===0;)p++,b++;for(var g=(x-p)*u+1>>>0,B=new Uint8Array(g);p!==x;){for(var I=h[p],L=0,D=g-1;(I!==0||L<l)&&D!==-1;D--,L++)I+=256*B[D]>>>0,B[D]=I%a>>>0,I=I/a>>>0;if(I!==0)throw new Error("Non-zero carry");l=L,p++}for(var S=g-l;S!==g&&B[S]===0;)S++;for(var O=f.repeat(b);S<g;++S)O+=r.charAt(B[S]);return O}function w(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;var b=0;if(h[b]!==" "){for(var l=0,p=0;h[b]===f;)l++,b++;for(var x=(h.length-b)*c+1>>>0,g=new Uint8Array(x);h[b];){var B=t[h.charCodeAt(b)];if(B===255)return;for(var I=0,L=x-1;(B!==0||I<p)&&L!==-1;L--,I++)B+=a*g[L]>>>0,g[L]=B%256>>>0,B=B/256>>>0;if(B!==0)throw new Error("Non-zero carry");p=I,b++}if(h[b]!==" "){for(var D=x-p;D!==x&&g[D]===0;)D++;for(var S=new Uint8Array(l+(x-D)),O=l;D!==x;)S[O++]=g[D++];return S}}}function y(h){var b=w(h);if(b)return b;throw new Error(`Non-${e} character`)}return{encode:d,decodeUnsafe:w,decode:y}}var Of=Rf,Nf=Of,bi=Nf;var Kn=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},zn=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let o=t.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return yi(this,e)}},Vn=class{decoders;constructor(e){this.decoders=e}or(e){return yi(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function yi(r,e){return new Vn({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var qn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new Kn(e,t,n),this.decoder=new zn(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function dt({name:r,prefix:e,encode:t,decode:n}){return new qn(r,e,t,n)}function ke({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=bi(t,r);return dt({prefix:e,name:r,encode:n,decode:s=>De(o(s))})}function Ff(r,e,t,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*t/8|0),i=0,a=0,f=0;for(let c=0;c<o;++c){let u=e[r[c]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|u,i+=t,i>=8&&(i-=8,s[f++]=255&a>>i)}if(i>=t||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Mf(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,a=0;for(let f=0;f<r.length;++f)for(a=a<<8|r[f],i+=8;i>t;)i-=t,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<t-i]),n)for(;(s.length*t&7)!==0;)s+="=";return s}function kf(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}function H({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let o=kf(n);return dt({prefix:e,name:r,encode(s){return Mf(s,n,t)},decode(s){return Ff(s,o,t,r)}})}var Pf=ke({prefix:"9",name:"base10",alphabet:"0123456789"});var jn={};M(jn,{base16:()=>Kf,base16upper:()=>zf});var Kf=H({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),zf=H({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var $n={};M($n,{base2:()=>Vf});var Vf=H({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Zn={};M(Zn,{base256emoji:()=>Zf});var xi=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}"),qf=xi.reduce((r,e,t)=>(r[t]=e,r),[]),Hf=xi.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function jf(r){return r.reduce((e,t)=>(e+=qf[t],e),"")}function $f(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=Hf[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var Zf=dt({prefix:"\u{1F680}",name:"base256emoji",encode:jf,decode:$f});var Yn={};M(Yn,{base32:()=>lt,base32hex:()=>Wf,base32hexpad:()=>Qf,base32hexpadupper:()=>eu,base32hexupper:()=>Jf,base32pad:()=>Gf,base32padupper:()=>Xf,base32upper:()=>Yf,base32z:()=>tu});var lt=H({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Yf=H({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Gf=H({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Xf=H({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Wf=H({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Jf=H({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Qf=H({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),eu=H({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),tu=H({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Gn={};M(Gn,{base36:()=>Jt,base36upper:()=>ru});var Jt=ke({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),ru=ke({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Xn={};M(Xn,{base58btc:()=>ge,base58flickr:()=>nu});var ge=ke({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),nu=ke({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Wn={};M(Wn,{base64:()=>ou,base64pad:()=>su,base64url:()=>iu,base64urlpad:()=>au});var ou=H({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),su=H({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),iu=H({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),au=H({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Jn={};M(Jn,{base8:()=>cu});var cu=H({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Qn={};M(Qn,{identity:()=>fu});var fu=dt({prefix:"\0",name:"identity",encode:r=>pi(r),decode:r=>li(r)});var B0=new TextEncoder,I0=new TextDecoder;var to={};M(to,{identity:()=>_u});var du=Ei,gi=128,lu=127,pu=~lu,mu=Math.pow(2,31);function Ei(r,e,t){e=e||[],t=t||0;for(var n=t;r>=mu;)e[t++]=r&255|gi,r/=128;for(;r&pu;)e[t++]=r&255|gi,r>>>=7;return e[t]=r|0,Ei.bytes=t-n+1,e}var bu=eo,yu=128,wi=127;function eo(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw eo.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&wi)<<o:(i&wi)*Math.pow(2,o),o+=7}while(i>=yu);return eo.bytes=s-n,t}var xu=Math.pow(2,7),gu=Math.pow(2,14),wu=Math.pow(2,21),Eu=Math.pow(2,28),vu=Math.pow(2,35),Su=Math.pow(2,42),Au=Math.pow(2,49),Bu=Math.pow(2,56),Iu=Math.pow(2,63),Du=function(r){return r<xu?1:r<gu?2:r<wu?3:r<Eu?4:r<vu?5:r<Su?6:r<Au?7:r<Bu?8:r<Iu?9:10},Cu={encode:du,decode:bu,encodingLength:Du},Tu=Cu,Qt=Tu;function er(r,e=0){return[Qt.decode(r,e),Qt.decode.bytes]}function pt(r,e,t=0){return Qt.encode(r,e,t),e}function mt(r){return Qt.encodingLength(r)}function yt(r,e){let t=e.byteLength,n=mt(r),o=n+mt(t),s=new Uint8Array(o+t);return pt(r,s,0),pt(t,s,n),s.set(e,o),new bt(r,t,e,s)}function vi(r){let e=De(r),[t,n]=er(e),[o,s]=er(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new bt(t,o,i,e)}function Si(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&di(r.bytes,t.bytes)}}var bt=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};var Ai=0,Lu="identity",Bi=De;function Uu(r,e){if(e?.truncate!=null&&e.truncate!==r.byteLength){if(e.truncate<0||e.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e.truncate)}return yt(Ai,Bi(r))}var _u={code:Ai,name:Lu,encode:Bi,digest:Uu};var oo={};M(oo,{sha256:()=>Ou,sha512:()=>Nu});var Ru=20;function no({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:o}){return new ro(r,e,t,n,o)}var ro=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,o,s){this.name=e,this.code=t,this.encode=n,this.minDigestLength=o??Ru,this.maxDigestLength=s}digest(e,t){if(t?.truncate!=null){if(t.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&t.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?Ii(n,this.code,t?.truncate):n.then(o=>Ii(o,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function Ii(r,e,t){if(t!=null&&t!==r.byteLength){if(t>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t)}return yt(e,r)}function Ci(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var Ou=no({name:"sha2-256",code:18,encode:Ci("SHA-256")}),Nu=no({name:"sha2-512",code:19,encode:Ci("SHA-512")});function Ti(r,e){let{bytes:t,version:n}=r;return n===0?Mu(t,so(r),e??ge.encoder):ku(t,so(r),e??lt.encoder)}var Li=new WeakMap;function so(r){let e=Li.get(r);if(e==null){let t=new Map;return Li.set(r,t),t}return e}var Hr=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,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:e,multihash:t}=this;if(e!==rr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Pu)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}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:e,digest:t}=this.multihash,n=yt(e,t);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(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&Si(e.multihash,n.multihash)}toString(e){return Ti(this,e)}toJSON(){return{"/":Ti(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:s,bytes:i}=t;return new r(n,o,s,i??Ui(n,o,s.bytes))}else if(t[Ku]===!0){let{version:n,multihash:o,code:s}=t,i=vi(o);return r.create(n,s,i)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==rr)throw new Error(`Version 0 CID must use dag-pb (code: ${rr}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=Ui(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,rr,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=De(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let s=o.subarray(t.multihashSize-t.digestSize),i=new bt(t.multihashCode,t.digestSize,s,o);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[d,w]=er(e.subarray(t));return t+=w,d},o=n(),s=rr;if(o===18?(o=0,t=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=t,a=n(),f=n(),c=t+f,u=c-i;return{version:o,codec:s,multihashCode:a,digestSize:f,multihashSize:u,size:c}}static parse(e,t){let[n,o]=Fu(e,t),s=r.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return so(s).set(n,e),s}};function Fu(r,e){switch(r[0]){case"Q":{let t=e??ge;return[ge.prefix,t.decode(`${ge.prefix}${r}`)]}case ge.prefix:{let t=e??ge;return[ge.prefix,t.decode(r)]}case lt.prefix:{let t=e??lt;return[lt.prefix,t.decode(r)]}case Jt.prefix:{let t=e??Jt;return[Jt.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function Mu(r,e,t){let{prefix:n}=t;if(n!==ge.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let s=t.encode(r).slice(1);return e.set(n,s),s}else return o}function ku(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let s=t.encode(r);return e.set(n,s),s}else return o}var rr=112,Pu=18;function Ui(r,e,t){let n=mt(r),o=n+mt(e),s=new Uint8Array(o+t.byteLength);return pt(r,s,0),pt(e,s,n),s.set(t,o),s}var Ku=Symbol.for("@ipld/js-cid/CID");var io={...Qn,...$n,...Jn,...Hn,...jn,...Yn,...Gn,...Xn,...Wn,...Zn},Y0={...oo,...to};function _i(r=0){return new Uint8Array(r)}function Oi(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Ri=Oi("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),ao=Oi("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=_i(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Q0={utf8:Ri,"utf-8":Ri,hex:io.base16,latin1:ao,ascii:ao,binary:ao,...io};var Hu=Uf(Fi(),1);var Ie;(function(r){r[r.A=1]="A",r[r.CNAME=5]="CNAME",r[r.TXT=16]="TXT",r[r.AAAA=28]="AAAA"})(Ie||(Ie={}));var Mi=32;var xt=class extends Map{#r=0;#e=new Map;#t=new Map;#o;#i;#s;constructor(e={}){if(super(),!(e.maxSize&&e.maxSize>0))throw new TypeError("`maxSize` must be a number greater than 0");if(typeof e.maxAge=="number"&&e.maxAge===0)throw new TypeError("`maxAge` must be a number greater than 0");this.#o=e.maxSize,this.#i=e.maxAge||Number.POSITIVE_INFINITY,this.#s=e.onEviction}get __oldCache(){return this.#t}#a(e){if(typeof this.#s=="function")for(let[t,n]of e)this.#s(t,n.value)}#n(e,t){return typeof t.expiry=="number"&&t.expiry<=Date.now()?(typeof this.#s=="function"&&this.#s(e,t.value),this.delete(e)):!1}#d(e,t){if(this.#n(e,t)===!1)return t.value}#f(e,t){return t.expiry?this.#d(e,t):t.value}#u(e,t){let n=t.get(e);return this.#f(e,n)}#h(e,t){this.#e.set(e,t),this.#r++,this.#r>=this.#o&&(this.#r=0,this.#a(this.#t),this.#t=this.#e,this.#e=new Map)}#l(e,t){this.#t.delete(e),this.#h(e,t)}*#c(){for(let e of this.#t){let[t,n]=e;this.#e.has(t)||this.#n(t,n)===!1&&(yield e)}for(let e of this.#e){let[t,n]=e;this.#n(t,n)===!1&&(yield e)}}get(e){if(this.#e.has(e)){let t=this.#e.get(e);return this.#f(e,t)}if(this.#t.has(e)){let t=this.#t.get(e);if(this.#n(e,t)===!1)return this.#l(e,t),t.value}}set(e,t,{maxAge:n=this.#i}={}){let o=typeof n=="number"&&n!==Number.POSITIVE_INFINITY?Date.now()+n:void 0;return this.#e.has(e)?this.#e.set(e,{value:t,expiry:o}):this.#h(e,{value:t,expiry:o}),this}has(e){return this.#e.has(e)?!this.#n(e,this.#e.get(e)):this.#t.has(e)?!this.#n(e,this.#t.get(e)):!1}peek(e){if(this.#e.has(e))return this.#u(e,this.#e);if(this.#t.has(e))return this.#u(e,this.#t)}expiresIn(e){let t=this.#e.get(e)??this.#t.get(e);if(t)return t.expiry?t.expiry-Date.now():Number.POSITIVE_INFINITY}delete(e){let t=this.#e.delete(e);return t&&this.#r--,this.#t.delete(e)||t}clear(){this.#e.clear(),this.#t.clear(),this.#r=0}resize(e){if(!(e&&e>0))throw new TypeError("`maxSize` must be a number greater than 0");let t=[...this.#c()],n=t.length-e;n<0?(this.#e=new Map(t),this.#t=new Map,this.#r=t.length):(n>0&&this.#a(t.slice(0,n)),this.#t=new Map(t.slice(n)),this.#e=new Map,this.#r=0),this.#o=e}evict(e=1){let t=Number(e);if(!t||t<=0)return;let n=[...this.#c()],o=Math.trunc(Math.min(t,Math.max(n.length-1,0)));o<=0||(this.#a(n.slice(0,o)),this.#t=new Map(n.slice(o)),this.#e=new Map,this.#r=0)}*keys(){for(let[e]of this)yield e}*values(){for(let[,e]of this)yield e}*[Symbol.iterator](){for(let e of this.#e){let[t,n]=e;this.#n(t,n)===!1&&(yield[t,n.value])}for(let e of this.#t){let[t,n]=e;this.#e.has(t)||this.#n(t,n)===!1&&(yield[t,n.value])}}*entriesDescending(){let e=[...this.#e];for(let t=e.length-1;t>=0;--t){let n=e[t],[o,s]=n;this.#n(o,s)===!1&&(yield[o,s.value])}e=[...this.#t];for(let t=e.length-1;t>=0;--t){let n=e[t],[o,s]=n;this.#e.has(o)||this.#n(o,s)===!1&&(yield[o,s.value])}}*entriesAscending(){for(let[e,t]of this.#c())yield[e,t.value]}get size(){if(!this.#r)return this.#t.size;let e=0;for(let t of this.#t.keys())this.#e.has(t)||e++;return Math.min(this.#r+e,this.#o)}get maxSize(){return this.#o}get maxAge(){return this.#i}entries(){return this.entriesAscending()}forEach(e,t=this){for(let[n,o]of this.entriesAscending())e.call(t,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 jr=class extends Error{static name="DNSLinkNotFoundError";constructor(e="DNSLink not found"){super(e),this.name="DNSLinkNotFoundError"}},gt=class extends Error{static name="InvalidNamespaceError";constructor(e="Invalid namespace"){super(e),this.name="InvalidNamespaceError"}};var Nm=new Uint8Array(0);function ki(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function wt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return et(r);if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return et(new Uint8Array(r.buffer,r.byteOffset,r.byteLength));throw new Error("Unknown type, must be binary type")}function ju(r){return r?.buffer instanceof ArrayBuffer}function et(r){return ju(r)?r:r.slice()}function $u(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(t[i]!==255)throw new TypeError(s+" is ambiguous");t[i]=o}var a=r.length,f=r.charAt(0),c=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function d(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var b=0,l=0,p=0,x=h.length;p!==x&&h[p]===0;)p++,b++;for(var g=(x-p)*u+1>>>0,B=new Uint8Array(g);p!==x;){for(var I=h[p],L=0,D=g-1;(I!==0||L<l)&&D!==-1;D--,L++)I+=256*B[D]>>>0,B[D]=I%a>>>0,I=I/a>>>0;if(I!==0)throw new Error("Non-zero carry");l=L,p++}for(var S=g-l;S!==g&&B[S]===0;)S++;for(var O=f.repeat(b);S<g;++S)O+=r.charAt(B[S]);return O}function w(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;var b=0;if(h[b]!==" "){for(var l=0,p=0;h[b]===f;)l++,b++;for(var x=(h.length-b)*c+1>>>0,g=new Uint8Array(x);h[b];){var B=t[h.charCodeAt(b)];if(B===255)return;for(var I=0,L=x-1;(B!==0||I<p)&&L!==-1;L--,I++)B+=a*g[L]>>>0,g[L]=B%256>>>0,B=B/256>>>0;if(B!==0)throw new Error("Non-zero carry");p=I,b++}if(h[b]!==" "){for(var D=x-p;D!==x&&g[D]===0;)D++;for(var S=new Uint8Array(l+(x-D)),O=l;D!==x;)S[O++]=g[D++];return S}}}function y(h){var b=w(h);if(b)return b;throw new Error(`Non-${e} character`)}return{encode:d,decodeUnsafe:w,decode:y}}var Zu=$u,Yu=Zu,Pi=Yu;var co=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},fo=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let o=t.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Ki(this,e)}},uo=class{decoders;constructor(e){this.decoders=e}or(e){return Ki(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Ki(r,e){return new uo({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var ho=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new co(e,t,n),this.decoder=new fo(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function zi({name:r,prefix:e,encode:t,decode:n}){return new ho(r,e,t,n)}function Et({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=Pi(t,r);return zi({prefix:e,name:r,encode:n,decode:s=>wt(o(s))})}function Gu(r,e,t,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*t/8|0),i=0,a=0,f=0;for(let c=0;c<o;++c){let u=e[r[c]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|u,i+=t,i>=8&&(i-=8,s[f++]=255&a>>i)}if(i>=t||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Xu(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,a=0;for(let f=0;f<r.length;++f)for(a=a<<8|r[f],i+=8;i>t;)i-=t,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<t-i]),n)for(;(s.length*t&7)!==0;)s+="=";return s}function Wu(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}function we({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let o=Wu(n);return zi({prefix:e,name:r,encode(s){return Xu(s,n,t)},decode(s){return Gu(s,o,t,r)}})}var nr=we({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Vm=we({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),qm=we({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Hm=we({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),jm=we({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),$m=we({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Zm=we({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Ym=we({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Gm=we({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var $r=Et({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Jm=Et({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ce=Et({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),tb=Et({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ju=Hi,Vi=128,Qu=127,eh=~Qu,th=Math.pow(2,31);function Hi(r,e,t){e=e||[],t=t||0;for(var n=t;r>=th;)e[t++]=r&255|Vi,r/=128;for(;r&eh;)e[t++]=r&255|Vi,r>>>=7;return e[t]=r|0,Hi.bytes=t-n+1,e}var rh=lo,nh=128,qi=127;function lo(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw lo.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&qi)<<o:(i&qi)*Math.pow(2,o),o+=7}while(i>=nh);return lo.bytes=s-n,t}var oh=Math.pow(2,7),sh=Math.pow(2,14),ih=Math.pow(2,21),ah=Math.pow(2,28),ch=Math.pow(2,35),fh=Math.pow(2,42),uh=Math.pow(2,49),hh=Math.pow(2,56),dh=Math.pow(2,63),lh=function(r){return r<oh?1:r<sh?2:r<ih?3:r<ah?4:r<ch?5:r<fh?6:r<uh?7:r<hh?8:r<dh?9:10},ph={encode:Ju,decode:rh,encodingLength:lh},mh=ph,or=mh;function sr(r,e=0){return[or.decode(r,e),or.decode.bytes]}function vt(r,e,t=0){return or.encode(r,e,t),e}function St(r){return or.encodingLength(r)}function $i(r,e){let t=e.byteLength,n=St(r),o=n+St(t),s=new Uint8Array(o+t);return vt(r,s,0),vt(t,s,n),s.set(e,o),new At(r,t,e,s)}function Zi(r){let e=wt(r),[t,n]=sr(e),[o,s]=sr(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new At(t,o,i,e)}function Yi(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&ki(r.bytes,t.bytes)}}var At=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=et(n),this.bytes=et(o)}};function Gi(r,e){let{bytes:t,version:n}=r;return n===0?xh(t,po(r),e??Ce.encoder):gh(t,po(r),e??nr.encoder)}var Xi=new WeakMap;function po(r){let e=Xi.get(r);if(e==null){let t=new Map;return Xi.set(r,t),t}return e}var Zr=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=et(o),this["/"]=this.bytes}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:e,multihash:t}=this;if(e!==ir)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==wh)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}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:e,digest:t}=this.multihash,n=$i(e,t);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(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&Yi(e.multihash,n.multihash)}toString(e){return Gi(this,e)}toJSON(){return{"/":Gi(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:s,bytes:i}=t;return new r(n,o,s,i??Wi(n,o,s.bytes))}else if(t[Eh]===!0){let{version:n,multihash:o,code:s}=t,i=Zi(o);return r.create(n,s,i)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==ir)throw new Error(`Version 0 CID must use dag-pb (code: ${ir}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=Wi(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,ir,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=wt(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let s=o.subarray(t.multihashSize-t.digestSize),i=new At(t.multihashCode,t.digestSize,s,o);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[d,w]=sr(e.subarray(t));return t+=w,d},o=n(),s=ir;if(o===18?(o=0,t=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=t,a=n(),f=n(),c=t+f,u=c-i;return{version:o,codec:s,multihashCode:a,digestSize:f,multihashSize:u,size:c}}static parse(e,t){let[n,o]=yh(e,t),s=r.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return po(s).set(n,e),s}};function yh(r,e){switch(r[0]){case"Q":{let t=e??Ce;return[Ce.prefix,t.decode(`${Ce.prefix}${r}`)]}case Ce.prefix:{let t=e??Ce;return[Ce.prefix,t.decode(r)]}case nr.prefix:{let t=e??nr;return[nr.prefix,t.decode(r)]}case $r.prefix:{let t=e??$r;return[$r.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function xh(r,e,t){let{prefix:n}=t;if(n!==Ce.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let s=t.encode(r).slice(1);return e.set(n,s),s}else return o}function gh(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let s=t.encode(r);return e.set(n,s),s}else return o}var ir=112,wh=18;function Wi(r,e,t){let n=St(r),o=n+St(e),s=new Uint8Array(o+t.byteLength);return vt(r,s,0),vt(e,s,n),s.set(t,o),s}var Eh=Symbol.for("@ipld/js-cid/CID");var Ji=(r,e)=>{let[,t,n,...o]=r.split("/");if(t!=="ipfs")throw new gt(`Namespace ${t} was not "ipfs"`);return{namespace:"ipfs",cid:Zr.parse(n),path:o.length>0?`/${o.join("/")}`:"",answer:e}};var Ee=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},Yr=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var Gr=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},Xr=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var ar=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var mo=Symbol.for("@libp2p/peer-id");var wo={};M(wo,{base58btc:()=>ne,base58flickr:()=>Ch});var yb=new Uint8Array(0);function Qi(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function Te(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 ea(r){return new TextEncoder().encode(r)}function ta(r){return new TextDecoder().decode(r)}function vh(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(t[i]!==255)throw new TypeError(s+" is ambiguous");t[i]=o}var a=r.length,f=r.charAt(0),c=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function d(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var b=0,l=0,p=0,x=h.length;p!==x&&h[p]===0;)p++,b++;for(var g=(x-p)*u+1>>>0,B=new Uint8Array(g);p!==x;){for(var I=h[p],L=0,D=g-1;(I!==0||L<l)&&D!==-1;D--,L++)I+=256*B[D]>>>0,B[D]=I%a>>>0,I=I/a>>>0;if(I!==0)throw new Error("Non-zero carry");l=L,p++}for(var S=g-l;S!==g&&B[S]===0;)S++;for(var O=f.repeat(b);S<g;++S)O+=r.charAt(B[S]);return O}function w(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;var b=0;if(h[b]!==" "){for(var l=0,p=0;h[b]===f;)l++,b++;for(var x=(h.length-b)*c+1>>>0,g=new Uint8Array(x);h[b];){var B=t[h.charCodeAt(b)];if(B===255)return;for(var I=0,L=x-1;(B!==0||I<p)&&L!==-1;L--,I++)B+=a*g[L]>>>0,g[L]=B%256>>>0,B=B/256>>>0;if(B!==0)throw new Error("Non-zero carry");p=I,b++}if(h[b]!==" "){for(var D=x-p;D!==x&&g[D]===0;)D++;for(var S=new Uint8Array(l+(x-D)),O=l;D!==x;)S[O++]=g[D++];return S}}}function y(h){var b=w(h);if(b)return b;throw new Error(`Non-${e} character`)}return{encode:d,decodeUnsafe:w,decode:y}}var Sh=vh,Ah=Sh,na=Ah;var bo=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},yo=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let o=t.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return oa(this,e)}},xo=class{decoders;constructor(e){this.decoders=e}or(e){return oa(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function oa(r,e){return new xo({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var go=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new bo(e,t,n),this.decoder=new yo(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Bt({name:r,prefix:e,encode:t,decode:n}){return new go(r,e,t,n)}function Pe({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=na(t,r);return Bt({prefix:e,name:r,encode:n,decode:s=>Te(o(s))})}function Bh(r,e,t,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*t/8|0),i=0,a=0,f=0;for(let c=0;c<o;++c){let u=e[r[c]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|u,i+=t,i>=8&&(i-=8,s[f++]=255&a>>i)}if(i>=t||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Ih(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,a=0;for(let f=0;f<r.length;++f)for(a=a<<8|r[f],i+=8;i>t;)i-=t,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<t-i]),n)for(;(s.length*t&7)!==0;)s+="=";return s}function Dh(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}function j({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let o=Dh(n);return Bt({prefix:e,name:r,encode(s){return Ih(s,n,t)},decode(s){return Bh(s,o,t,r)}})}var ne=Pe({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ch=Pe({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Eo={};M(Eo,{base32:()=>It,base32hex:()=>_h,base32hexpad:()=>Oh,base32hexpadupper:()=>Nh,base32hexupper:()=>Rh,base32pad:()=>Lh,base32padupper:()=>Uh,base32upper:()=>Th,base32z:()=>Fh});var It=j({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Th=j({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Lh=j({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Uh=j({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),_h=j({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Rh=j({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Oh=j({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Nh=j({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Fh=j({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var vo={};M(vo,{base36:()=>cr,base36upper:()=>Mh});var cr=Pe({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Mh=Pe({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var kh=aa,sa=128,Ph=127,Kh=~Ph,zh=Math.pow(2,31);function aa(r,e,t){e=e||[],t=t||0;for(var n=t;r>=zh;)e[t++]=r&255|sa,r/=128;for(;r&Kh;)e[t++]=r&255|sa,r>>>=7;return e[t]=r|0,aa.bytes=t-n+1,e}var Vh=So,qh=128,ia=127;function So(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw So.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&ia)<<o:(i&ia)*Math.pow(2,o),o+=7}while(i>=qh);return So.bytes=s-n,t}var Hh=Math.pow(2,7),jh=Math.pow(2,14),$h=Math.pow(2,21),Zh=Math.pow(2,28),Yh=Math.pow(2,35),Gh=Math.pow(2,42),Xh=Math.pow(2,49),Wh=Math.pow(2,56),Jh=Math.pow(2,63),Qh=function(r){return r<Hh?1:r<jh?2:r<$h?3:r<Zh?4:r<Yh?5:r<Gh?6:r<Xh?7:r<Wh?8:r<Jh?9:10},ed={encode:kh,decode:Vh,encodingLength:Qh},td=ed,fr=td;function ur(r,e=0){return[fr.decode(r,e),fr.decode.bytes]}function Dt(r,e,t=0){return fr.encode(r,e,t),e}function Ct(r){return fr.encodingLength(r)}function Lt(r,e){let t=e.byteLength,n=Ct(r),o=n+Ct(t),s=new Uint8Array(o+t);return Dt(r,s,0),Dt(t,s,n),s.set(e,o),new Tt(r,t,e,s)}function ca(r){let e=Te(r),[t,n]=ur(e),[o,s]=ur(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Tt(t,o,i,e)}function fa(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Qi(r.bytes,t.bytes)}}var Tt=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function ua(r,e){let{bytes:t,version:n}=r;return n===0?nd(t,Ao(r),e??ne.encoder):od(t,Ao(r),e??It.encoder)}var ha=new WeakMap;function Ao(r){let e=ha.get(r);if(e==null){let t=new Map;return ha.set(r,t),t}return e}var ve=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,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:e,multihash:t}=this;if(e!==dr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==sd)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}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:e,digest:t}=this.multihash,n=Lt(e,t);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(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&fa(e.multihash,n.multihash)}toString(e){return ua(this,e)}toJSON(){return{"/":ua(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:s,bytes:i}=t;return new r(n,o,s,i??da(n,o,s.bytes))}else if(t[id]===!0){let{version:n,multihash:o,code:s}=t,i=ca(o);return r.create(n,s,i)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==dr)throw new Error(`Version 0 CID must use dag-pb (code: ${dr}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=da(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,dr,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=Te(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let s=o.subarray(t.multihashSize-t.digestSize),i=new Tt(t.multihashCode,t.digestSize,s,o);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[d,w]=ur(e.subarray(t));return t+=w,d},o=n(),s=dr;if(o===18?(o=0,t=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=t,a=n(),f=n(),c=t+f,u=c-i;return{version:o,codec:s,multihashCode:a,digestSize:f,multihashSize:u,size:c}}static parse(e,t){let[n,o]=rd(e,t),s=r.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Ao(s).set(n,e),s}};function rd(r,e){switch(r[0]){case"Q":{let t=e??ne;return[ne.prefix,t.decode(`${ne.prefix}${r}`)]}case ne.prefix:{let t=e??ne;return[ne.prefix,t.decode(r)]}case It.prefix:{let t=e??It;return[It.prefix,t.decode(r)]}case cr.prefix:{let t=e??cr;return[cr.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function nd(r,e,t){let{prefix:n}=t;if(n!==ne.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let s=t.encode(r).slice(1);return e.set(n,s),s}else return o}function od(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let s=t.encode(r);return e.set(n,s),s}else return o}var dr=112,sd=18;function da(r,e,t){let n=Ct(r),o=n+Ct(e),s=new Uint8Array(o+t.byteLength);return Dt(r,s,0),Dt(e,s,n),s.set(t,o),s}var id=Symbol.for("@ipld/js-cid/CID");var Bo={};M(Bo,{identity:()=>tt});var la=0,ad="identity",pa=Te;function cd(r,e){if(e?.truncate!=null&&e.truncate!==r.byteLength){if(e.truncate<0||e.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e.truncate)}return Lt(la,pa(r))}var tt={code:la,name:ad,encode:pa,digest:cd};function Ke(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}async function ma(r,e,t,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,e,t.subarray());return n?.signal?.throwIfAborted(),s}function Le(r=0){return new Uint8Array(r)}function fe(r=0){return new Uint8Array(r)}function Jr(r,e){e==null&&(e=r.reduce((o,s)=>o+s.length,0));let t=fe(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}var ya=Symbol.for("@achingbrain/uint8arraylist");function ba(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let o=t+n.byteLength;if(e<o)return{buf:n,index:e-t};t=o}throw new RangeError("index is out of bounds")}function Qr(r){return!!r?.[ya]}var ue=class r{bufs;length;[ya]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let t=0;for(let n of e)if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.push(n);else if(Qr(n)){t+=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+=t}prepend(...e){this.prependAll(e)}prependAll(e){let t=0;for(let n of e.reverse())if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.unshift(n);else if(Qr(n))t+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}get(e){let t=ba(this.bufs,e);return t.buf[t.index]}set(e,t){let n=ba(this.bufs,e);n.buf[n.index]=t}write(e,t=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(t+n,e[n]);else if(Qr(e))for(let n=0;n<e.length;n++)this.set(t+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:n,length:o}=this._subList(e,t);return Jr(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:Jr(n,o)}sublist(e,t){let{bufs:n,length:o}=this._subList(e,t),s=new r;return s.length=o,s.bufs=n,s}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===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,f=a+i.byteLength;if(o=f,e>=f)continue;let c=e>=a&&e<f,u=t>a&&t<=f;if(c&&u){if(e===a&&t===f){n.push(i);break}let d=e-a;n.push(i.subarray(d,d+(t-e)));break}if(c){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(u){if(t===f){n.push(i);break}n.push(i.subarray(0,t-a));break}n.push(i)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!Qr(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;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 d=0;d<s;d++)i[d]=-1;for(let d=0;d<o;d++)i[n[d]]=d;let a=i,f=this.byteLength-n.byteLength,c=n.byteLength-1,u;for(let d=t;d<=f;d+=u){u=0;for(let w=c;w>=0;w--){let y=this.get(d+w);if(n[w]!==y){u=Math.max(1,w-a[y]);break}}if(u===0)return d}return-1}getInt8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){let n=fe(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,t),this.write(n,e)}getInt16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,t)}setInt16(e,t,n){let o=Le(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,t,n),this.write(o,e)}getInt32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,t)}setInt32(e,t,n){let o=Le(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,t,n),this.write(o,e)}getBigInt64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,t)}setBigInt64(e,t,n){let o=Le(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,t,n),this.write(o,e)}getUint8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){let n=fe(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,t),this.write(n,e)}getUint16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,t)}setUint16(e,t,n){let o=Le(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,t,n),this.write(o,e)}getUint32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,t)}setUint32(e,t,n){let o=Le(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,t,n),this.write(o,e)}getBigUint64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,t)}setBigUint64(e,t,n){let o=Le(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,t,n),this.write(o,e)}getFloat32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,t)}setFloat32(e,t,n){let o=Le(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,t,n),this.write(o,e)}getFloat64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,t)}setFloat64(e,t,n){let o=Le(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,t,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof r)||e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!Ke(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let n=new r;return n.bufs=e,t==null&&(t=e.reduce((o,s)=>o+s.byteLength,0)),n.length=t,n}};var Io={};M(Io,{base10:()=>fd});var fd=Pe({prefix:"9",name:"base10",alphabet:"0123456789"});var Do={};M(Do,{base16:()=>ud,base16upper:()=>hd});var ud=j({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),hd=j({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Co={};M(Co,{base2:()=>dd});var dd=j({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var To={};M(To,{base256emoji:()=>yd});var xa=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}"),ld=xa.reduce((r,e,t)=>(r[t]=e,r),[]),pd=xa.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function md(r){return r.reduce((e,t)=>(e+=ld[t],e),"")}function bd(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=pd[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var yd=Bt({prefix:"\u{1F680}",name:"base256emoji",encode:md,decode:bd});var Lo={};M(Lo,{base64:()=>xd,base64pad:()=>gd,base64url:()=>wd,base64urlpad:()=>Ed});var xd=j({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),gd=j({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),wd=j({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ed=j({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Uo={};M(Uo,{base8:()=>vd});var vd=j({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var _o={};M(_o,{identity:()=>Sd});var Sd=Bt({prefix:"\0",name:"identity",encode:r=>ta(r),decode:r=>ea(r)});var ty=new TextEncoder,ry=new TextDecoder;var Fo={};M(Fo,{sha256:()=>No,sha512:()=>Dd});var Id=20;function Oo({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:o}){return new Ro(r,e,t,n,o)}var Ro=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,o,s){this.name=e,this.code=t,this.encode=n,this.minDigestLength=o??Id,this.maxDigestLength=s}digest(e,t){if(t?.truncate!=null){if(t.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&t.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?ga(n,this.code,t?.truncate):n.then(o=>ga(o,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function ga(r,e,t){if(t!=null&&t!==r.byteLength){if(t>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t)}return Lt(e,r)}function Ea(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var No=Oo({name:"sha2-256",code:18,encode:Ea("SHA-256")}),Dd=Oo({name:"sha2-512",code:19,encode:Ea("SHA-512")});var Mo={..._o,...Co,...Uo,...Io,...Do,...Eo,...vo,...wo,...Lo,...To},py={...Fo,...Bo};function Sa(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var va=Sa("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),ko=Sa("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=fe(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Cd={utf8:va,"utf-8":va,hex:Mo.base16,latin1:ko,ascii:ko,binary:ko,...Mo},en=Cd;function Ut(r,e="utf8"){let t=en[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function ze(r,e="utf8"){let t=en[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var Td=parseInt("11111",2),Po=parseInt("10000000",2),Ld=parseInt("01111111",2),Aa={0:lr,1:lr,2:Ud,3:Od,4:Nd,5:Rd,6:_d,16:lr,22:lr,48:lr};function Ko(r,e={offset:0}){let t=r[e.offset]&Td;if(e.offset++,Aa[t]!=null)return Aa[t](r,e);throw new Error("No decoder for tag "+t)}function pr(r,e){let t=0;if((r[e.offset]&Po)===Po){let n=r[e.offset]&Ld,o="0x";e.offset++;for(let s=0;s<n;s++,e.offset++)o+=r[e.offset].toString(16).padStart(2,"0");t=parseInt(o,16)}else t=r[e.offset],e.offset++;return t}function lr(r,e){pr(r,e);let t=[];for(;!(e.offset>=r.byteLength);){let n=Ko(r,e);if(n===null)break;t.push(n)}return t}function Ud(r,e){let t=pr(r,e),n=e.offset,o=e.offset+t,s=[];for(let i=n;i<o;i++)i===n&&r[i]===0||s.push(r[i]);return e.offset+=t,Uint8Array.from(s)}function _d(r,e){let t=pr(r,e),n=e.offset+t,o=r[e.offset];e.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}`,f=[];for(;e.offset<n;){let c=r[e.offset];if(e.offset++,f.push(c&127),c<128){f.reverse();let u=0;for(let d=0;d<f.length;d++)u+=f[d]<<d*7;a+=`.${u}`,f=[]}}return a}function Rd(r,e){return e.offset++,null}function Od(r,e){let t=pr(r,e),n=r[e.offset];e.offset++;let o=r.subarray(e.offset,e.offset+t-1);if(e.offset+=t,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Nd(r,e){let t=pr(r,e),n=r.subarray(e.offset,e.offset+t);return e.offset+=t,n}function Fd(r){let e=r.toString(16);e.length%2===1&&(e="0"+e);let t=new ue;for(let n=0;n<e.length;n+=2)t.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return t}function zo(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let e=Fd(r.byteLength);return new ue(Uint8Array.from([e.byteLength|Po]),e)}function Ba(r){let e=new ue,t=128;return(r.subarray()[0]&t)===t&&e.append(Uint8Array.from([0])),e.append(r),new ue(Uint8Array.from([2]),zo(e),e)}function Ia(r){let e=Uint8Array.from([0]),t=new ue(e,r);return new ue(Uint8Array.from([3]),zo(t),t)}function tn(r,e=48){let t=new ue;for(let n of r)t.append(n);return new ue(Uint8Array.from([e]),zo(t),t)}var Md=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),kd=Uint8Array.from([6,5,43,129,4,0,34]),Pd=Uint8Array.from([6,5,43,129,4,0,35]),Kd={ext:!0,kty:"EC",crv:"P-256"},zd={ext:!0,kty:"EC",crv:"P-384"},Vd={ext:!0,kty:"EC",crv:"P-521"},Vo=32,qo=48,Ho=66;function Da(r){let e=Ko(r);return Ca(e)}function Ca(r){let e=r[1][1][0],t=1,n,o;if(e.byteLength===Vo*2+1)return n=ze(e.subarray(t,t+Vo),"base64url"),o=ze(e.subarray(t+Vo),"base64url"),new _t({...Kd,key_ops:["verify"],x:n,y:o});if(e.byteLength===qo*2+1)return n=ze(e.subarray(t,t+qo),"base64url"),o=ze(e.subarray(t+qo),"base64url"),new _t({...zd,key_ops:["verify"],x:n,y:o});if(e.byteLength===Ho*2+1)return n=ze(e.subarray(t,t+Ho),"base64url"),o=ze(e.subarray(t+Ho),"base64url"),new _t({...Vd,key_ops:["verify"],x:n,y:o});throw new Ee(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function Ta(r){return tn([Ba(Uint8Array.from([1])),tn([qd(r.crv)],160),tn([Ia(new ue(Uint8Array.from([4]),Ut(r.x??"","base64url"),Ut(r.y??"","base64url")))],161)]).subarray()}function qd(r){if(r==="P-256")return Md;if(r==="P-384")return kd;if(r==="P-521")return Pd;throw new Ee(`Invalid curve ${r}`)}var _t=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=Ta(this.jwk)),this._raw}toMultihash(){return tt.digest(Rt(this))}toCID(){return ve.createV1(114,this.toMultihash())}toString(){return ne.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ke(this.raw,e.raw)}async verify(e,t,n){return ma(this.jwk,t,e,n)}};function jo(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in r&&r.BYTES_PER_ELEMENT===1}function Ve(r,e=""){if(typeof r!="number"){let t=e&&`"${e}" `;throw new TypeError(`${t}expected number, got ${typeof r}`)}if(!Number.isSafeInteger(r)||r<0){let t=e&&`"${e}" `;throw new RangeError(`${t}expected integer >= 0, got ${r}`)}}function he(r,e,t=""){let n=jo(r),o=r?.length,s=e!==void 0;if(!n||s&&o!==e){let i=t&&`"${t}" `,a=s?` of length ${e}`:"",f=n?`length=${o}`:`type=${typeof r}`,c=i+"expected Uint8Array"+a+", got "+f;throw n?new RangeError(c):new TypeError(c)}return r}function rn(r){if(typeof r!="function"||typeof r.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(Ve(r.outputLen),Ve(r.blockLen),r.outputLen<1)throw new Error('"outputLen" must be >= 1');if(r.blockLen<1)throw new Error('"blockLen" must be >= 1')}function Ot(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function nn(r,e){he(r,void 0,"digestInto() output");let t=e.outputLen;if(r.length<t)throw new RangeError('"digestInto() output" expected to be of length >='+t)}function _e(...r){for(let e=0;e<r.length;e++)r[e].fill(0)}function on(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function le(r,e){return r<<32-e|r>>>e}var Ua=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Hd=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function sn(r){if(he(r),Ua)return r.toHex();let e="";for(let t=0;t<r.length;t++)e+=Hd[r[t]];return e}var Ue={_0:48,_9:57,A:65,F:70,a:97,f:102};function La(r){if(r>=Ue._0&&r<=Ue._9)return r-Ue._0;if(r>=Ue.A&&r<=Ue.F)return r-(Ue.A-10);if(r>=Ue.a&&r<=Ue.f)return r-(Ue.a-10)}function mr(r){if(typeof r!="string")throw new TypeError("hex string expected, got "+typeof r);if(Ua)try{return Uint8Array.fromHex(r)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let e=r.length,t=e/2;if(e%2)throw new RangeError("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(t);for(let o=0,s=0;o<t;o++,s+=2){let i=La(r.charCodeAt(s)),a=La(r.charCodeAt(s+1));if(i===void 0||a===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+a}return n}function $o(...r){let e=0;for(let n=0;n<r.length;n++){let o=r[n];he(o),e+=o.length}let t=new Uint8Array(e);for(let n=0,o=0;n<r.length;n++){let s=r[n];t.set(s,o),o+=s.length}return t}function Zo(r,e={}){let t=(o,s)=>r(s).update(o).digest(),n=r(void 0);return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.canXOF=n.canXOF,t.create=o=>r(o),Object.assign(t,e),Object.freeze(t)}function _a(r=32){Ve(r,"bytesLength");let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(r>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${r}`);return e.getRandomValues(new Uint8Array(r))}var Yo=r=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,r])});function Ra(r,e,t){return r&e^~r&t}function Oa(r,e,t){return r&e^r&t^e&t}var br=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,t,n,o){this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=on(this.buffer)}update(e){Ot(this),he(e);let{view:t,buffer:n,blockLen:o}=this,s=e.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let f=on(e);for(;o<=s-i;i+=o)this.process(f,i);continue}n.set(e.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Ot(this),nn(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;t[i++]=128,_e(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let d=i;d<o;d++)t[d]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let a=on(e),f=this.outputLen;if(f%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let c=f/4,u=this.get();if(c>u.length)throw new Error("_sha2: outputLen bigger than state");for(let d=0;d<c;d++)a.setUint32(4*d,u[d],s)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());let{blockLen:t,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return e.destroyed=i,e.finished=s,e.length=o,e.pos=a,o%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}},Re=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var te=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var an=BigInt(4294967295),Na=BigInt(32);function jd(r,e=!1){return e?{h:Number(r&an),l:Number(r>>Na&an)}:{h:Number(r>>Na&an)|0,l:Number(r&an)|0}}function Fa(r,e=!1){let t=r.length,n=new Uint32Array(t),o=new Uint32Array(t);for(let s=0;s<t;s++){let{h:i,l:a}=jd(r[s],e);[n[s],o[s]]=[i,a]}return[n,o]}var Go=(r,e,t)=>r>>>t,Xo=(r,e,t)=>r<<32-t|e>>>t,rt=(r,e,t)=>r>>>t|e<<32-t,nt=(r,e,t)=>r<<32-t|e>>>t,yr=(r,e,t)=>r<<64-t|e>>>t-32,xr=(r,e,t)=>r>>>t-32|e<<64-t;function Se(r,e,t,n){let o=(e>>>0)+(n>>>0);return{h:r+t+(o/2**32|0)|0,l:o|0}}var Ma=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),ka=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,Pa=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),Ka=(r,e,t,n,o)=>e+t+n+o+(r/2**32|0)|0,za=(r,e,t,n,o)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(o>>>0),Va=(r,e,t,n,o,s)=>e+t+n+o+s+(r/2**32|0)|0;var Zd=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]),qe=new Uint32Array(64),Wo=class extends br{constructor(e){super(64,e,8,!1)}get(){let{A:e,B:t,C:n,D:o,E:s,F:i,G:a,H:f}=this;return[e,t,n,o,s,i,a,f]}set(e,t,n,o,s,i,a,f){this.A=e|0,this.B=t|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=f|0}process(e,t){for(let d=0;d<16;d++,t+=4)qe[d]=e.getUint32(t,!1);for(let d=16;d<64;d++){let w=qe[d-15],y=qe[d-2],h=le(w,7)^le(w,18)^w>>>3,b=le(y,17)^le(y,19)^y>>>10;qe[d]=b+qe[d-7]+h+qe[d-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:f,G:c,H:u}=this;for(let d=0;d<64;d++){let w=le(a,6)^le(a,11)^le(a,25),y=u+w+Ra(a,f,c)+Zd[d]+qe[d]|0,b=(le(n,2)^le(n,13)^le(n,22))+Oa(n,o,s)|0;u=c,c=f,f=a,a=i+y|0,i=s,s=o,o=n,n=y+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,f=f+this.F|0,c=c+this.G|0,u=u+this.H|0,this.set(n,o,s,i,a,f,c,u)}roundClean(){_e(qe)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),_e(this.buffer)}},Jo=class extends Wo{A=Re[0]|0;B=Re[1]|0;C=Re[2]|0;D=Re[3]|0;E=Re[4]|0;F=Re[5]|0;G=Re[6]|0;H=Re[7]|0;constructor(){super(32)}};var qa=Fa(["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))),Yd=qa[0],Gd=qa[1],He=new Uint32Array(80),je=new Uint32Array(80),Qo=class extends br{constructor(e){super(128,e,16,!1)}get(){let{Ah:e,Al:t,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:f,Eh:c,El:u,Fh:d,Fl:w,Gh:y,Gl:h,Hh:b,Hl:l}=this;return[e,t,n,o,s,i,a,f,c,u,d,w,y,h,b,l]}set(e,t,n,o,s,i,a,f,c,u,d,w,y,h,b,l){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=f|0,this.Eh=c|0,this.El=u|0,this.Fh=d|0,this.Fl=w|0,this.Gh=y|0,this.Gl=h|0,this.Hh=b|0,this.Hl=l|0}process(e,t){for(let g=0;g<16;g++,t+=4)He[g]=e.getUint32(t),je[g]=e.getUint32(t+=4);for(let g=16;g<80;g++){let B=He[g-15]|0,I=je[g-15]|0,L=rt(B,I,1)^rt(B,I,8)^Go(B,I,7),D=nt(B,I,1)^nt(B,I,8)^Xo(B,I,7),S=He[g-2]|0,O=je[g-2]|0,V=rt(S,O,19)^yr(S,O,61)^Go(S,O,6),F=nt(S,O,19)^xr(S,O,61)^Xo(S,O,6),m=Pa(D,F,je[g-7],je[g-16]),E=Ka(m,L,V,He[g-7],He[g-16]);He[g]=E|0,je[g]=m|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:f,Dh:c,Dl:u,Eh:d,El:w,Fh:y,Fl:h,Gh:b,Gl:l,Hh:p,Hl:x}=this;for(let g=0;g<80;g++){let B=rt(d,w,14)^rt(d,w,18)^yr(d,w,41),I=nt(d,w,14)^nt(d,w,18)^xr(d,w,41),L=d&y^~d&b,D=w&h^~w&l,S=za(x,I,D,Gd[g],je[g]),O=Va(S,p,B,L,Yd[g],He[g]),V=S|0,F=rt(n,o,28)^yr(n,o,34)^yr(n,o,39),m=nt(n,o,28)^xr(n,o,34)^xr(n,o,39),E=n&s^n&a^s&a,C=o&i^o&f^i&f;p=b|0,x=l|0,b=y|0,l=h|0,y=d|0,h=w|0,{h:d,l:w}=Se(c|0,u|0,O|0,V|0),c=a|0,u=f|0,a=s|0,f=i|0,s=n|0,i=o|0;let A=Ma(V,m,C);n=ka(A,O,F,E),o=A|0}({h:n,l:o}=Se(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Se(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:f}=Se(this.Ch|0,this.Cl|0,a|0,f|0),{h:c,l:u}=Se(this.Dh|0,this.Dl|0,c|0,u|0),{h:d,l:w}=Se(this.Eh|0,this.El|0,d|0,w|0),{h:y,l:h}=Se(this.Fh|0,this.Fl|0,y|0,h|0),{h:b,l}=Se(this.Gh|0,this.Gl|0,b|0,l|0),{h:p,l:x}=Se(this.Hh|0,this.Hl|0,p|0,x|0),this.set(n,o,s,i,a,f,c,u,d,w,y,h,b,l,p,x)}roundClean(){_e(He,je)}destroy(){this.destroyed=!0,_e(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},es=class extends Qo{Ah=te[0]|0;Al=te[1]|0;Bh=te[2]|0;Bl=te[3]|0;Ch=te[4]|0;Cl=te[5]|0;Dh=te[6]|0;Dl=te[7]|0;Eh=te[8]|0;El=te[9]|0;Fh=te[10]|0;Fl=te[11]|0;Gh=te[12]|0;Gl=te[13]|0;Hh=te[14]|0;Hl=te[15]|0;constructor(){super(64)}};var Ha=Zo(()=>new Jo,Yo(1));var cn=Zo(()=>new es,Yo(3));var K=(r,e,t)=>he(r,e,t),rs=Ve,Nt=sn,W=(...r)=>$o(...r),Ft=r=>mr(r),ot=jo,gr=r=>_a(r),un=BigInt(0),ts=BigInt(1);function pe(r,e=""){if(typeof r!="boolean"){let t=e&&`"${e}" `;throw new TypeError(t+"expected boolean, got type="+typeof r)}return r}function hn(r){if(typeof r=="bigint"){if(!fn(r))throw new RangeError("positive bigint expected, got "+r)}else rs(r);return r}function me(r,e=""){if(typeof r!="number"){let t=e&&`"${e}" `;throw new TypeError(t+"expected number, got type="+typeof r)}if(!Number.isSafeInteger(r)){let t=e&&`"${e}" `;throw new RangeError(t+"expected safe integer, got "+r)}}function wr(r){let e=hn(r).toString(16);return e.length&1?"0"+e:e}function ja(r){if(typeof r!="string")throw new TypeError("hex string expected, got "+typeof r);return r===""?un:BigInt("0x"+r)}function st(r){return ja(sn(r))}function Ae(r){return ja(sn(Er(he(r)).reverse()))}function dn(r,e){if(Ve(e),e===0)throw new RangeError("zero length");r=hn(r);let t=r.toString(16);if(t.length>e*2)throw new RangeError("number too large");return mr(t.padStart(e*2,"0"))}function ns(r,e){return dn(r,e).reverse()}function $a(r,e){if(r=K(r),e=K(e),r.length!==e.length)return!1;let t=0;for(let n=0;n<r.length;n++)t|=r[n]^e[n];return t===0}function Er(r){return Uint8Array.from(K(r))}function ln(r){if(typeof r!="string")throw new TypeError("ascii string expected, got "+typeof r);return Uint8Array.from(r,(e,t)=>{let n=e.charCodeAt(0);if(e.length!==1||n>127)throw new RangeError(`string contains non-ASCII character "${r[t]}" with code ${n} at position ${t}`);return n})}var fn=r=>typeof r=="bigint"&&un<=r;function Xd(r,e,t){return fn(r)&&fn(e)&&fn(t)&&e<=r&&r<t}function Mt(r,e,t,n){if(!Xd(e,t,n))throw new RangeError("expected valid "+r+": "+t+" <= n < "+n+", got "+e)}function kt(r){if(r<un)throw new Error("expected non-negative bigint, got "+r);let e;for(e=0;r>un;r>>=ts,e+=1);return e}var vr=r=>(ts<<BigInt(r))-ts;function Za(r,e,t){if(Ve(r,"hashLen"),Ve(e,"qByteLen"),typeof t!="function")throw new TypeError("hmacFn must be a function");let n=l=>new Uint8Array(l),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,f=n(r),c=n(r),u=0,d=()=>{f.fill(1),c.fill(0),u=0},w=(...l)=>t(c,W(f,...l)),y=(l=o)=>{c=w(s,l),f=w(),l.length!==0&&(c=w(i,l),f=w())},h=()=>{if(u++>=a)throw new Error("drbg: tried max amount of iterations");let l=0,p=[];for(;l<e;){f=w();let x=f.slice();p.push(x),l+=f.length}return W(...p)};return(l,p)=>{d(),y(l);let x;for(;(x=p(h()))===void 0;)y();return d(),x}}function be(r,e={},t={}){if(Object.prototype.toString.call(r)!=="[object Object]")throw new TypeError("expected valid options object");function n(s,i,a){if(!a&&i!=="function"&&!Object.hasOwn(r,s))throw new TypeError(`param "${s}" is invalid: expected own property`);let f=r[s];if(a&&f===void 0)return;let c=typeof f;if(c!==i||f===null)throw new TypeError(`param "${s}" is invalid: expected ${i}, got ${c}`)}let o=(s,i)=>Object.entries(s).forEach(([a,f])=>n(a,f,i));o(e,!1),o(t,!0)}var os=()=>{throw new Error("not implemented")};var re=BigInt(0),$=BigInt(1),it=BigInt(2),Wa=BigInt(3),Ja=BigInt(4),Qa=BigInt(5),Wd=BigInt(7),ec=BigInt(8),Jd=BigInt(9),tc=BigInt(16);function G(r,e){if(e<=re)throw new Error("mod: expected positive modulus, got "+e);let t=r%e;return t>=re?t:e+t}function q(r,e,t){if(e<re)throw new Error("pow2: expected non-negative exponent, got "+e);let n=r;for(;e-- >re;)n*=n,n%=t;return n}function Ya(r,e){if(r===re)throw new Error("invert: expected non-zero number");if(e<=re)throw new Error("invert: expected positive modulus, got "+e);let t=G(r,e),n=e,o=re,s=$,i=$,a=re;for(;t!==re;){let c=n/t,u=n-t*c,d=o-i*c,w=s-a*c;n=t,t=u,o=i,s=a,i=d,a=w}if(n!==$)throw new Error("invert: does not exist");return G(o,e)}function ss(r,e,t){let n=r;if(!n.eql(n.sqr(e),t))throw new Error("Cannot find square root")}function rc(r,e){let t=r,n=(t.ORDER+$)/Ja,o=t.pow(e,n);return ss(t,o,e),o}function Qd(r,e){let t=r,n=(t.ORDER-Qa)/ec,o=t.mul(e,it),s=t.pow(o,n),i=t.mul(e,s),a=t.mul(t.mul(i,it),s),f=t.mul(i,t.sub(a,t.ONE));return ss(t,f,e),f}function el(r){let e=Pt(r),t=nc(r),n=t(e,e.neg(e.ONE)),o=t(e,n),s=t(e,e.neg(n)),i=(r+Wd)/tc;return((a,f)=>{let c=a,u=c.pow(f,i),d=c.mul(u,n),w=c.mul(u,o),y=c.mul(u,s),h=c.eql(c.sqr(d),f),b=c.eql(c.sqr(w),f);u=c.cmov(u,d,h),d=c.cmov(y,w,b);let l=c.eql(c.sqr(d),f),p=c.cmov(u,d,l);return ss(c,p,f),p})}function nc(r){if(r<Wa)throw new Error("sqrt is not defined for small field");let e=r-$,t=0;for(;e%it===re;)e/=it,t++;let n=it,o=Pt(r);for(;Ga(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(t===1)return rc;let s=o.pow(n,e),i=(e+$)/it;return function(f,c){let u=f;if(u.is0(c))return c;if(Ga(u,c)!==1)throw new Error("Cannot find square root");let d=t,w=u.mul(u.ONE,s),y=u.pow(c,e),h=u.pow(c,i);for(;!u.eql(y,u.ONE);){if(u.is0(y))return u.ZERO;let b=1,l=u.sqr(y);for(;!u.eql(l,u.ONE);)if(b++,l=u.sqr(l),b===d)throw new Error("Cannot find square root");let p=$<<BigInt(d-b-1),x=u.pow(w,p);d=b,w=u.sqr(x),y=u.mul(y,w),h=u.mul(h,x)}return h}}function tl(r){return r%Ja===Wa?rc:r%ec===Qa?Qd:r%tc===Jd?el(r):nc(r)}var Oe=(r,e)=>(G(r,e)&$)===$,rl=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function is(r){let e={ORDER:"bigint",BYTES:"number",BITS:"number"},t=rl.reduce((n,o)=>(n[o]="function",n),e);if(be(r,t),me(r.BYTES,"BYTES"),me(r.BITS,"BITS"),r.BYTES<1||r.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(r.ORDER<=$)throw new Error("invalid field: expected ORDER > 1, got "+r.ORDER);return r}function nl(r,e,t){let n=r;if(t<re)throw new Error("invalid exponent, negatives unsupported");if(t===re)return n.ONE;if(t===$)return e;let o=n.ONE,s=e;for(;t>re;)t&$&&(o=n.mul(o,s)),s=n.sqr(s),t>>=$;return o}function Sr(r,e,t=!1){let n=r,o=new Array(e.length).fill(t?n.ZERO:void 0),s=e.reduce((a,f,c)=>n.is0(f)?a:(o[c]=a,n.mul(a,f)),n.ONE),i=n.inv(s);return e.reduceRight((a,f,c)=>n.is0(f)?a:(o[c]=n.mul(a,o[c]),n.mul(a,f)),i),o}function Ga(r,e){let t=r,n=(t.ORDER-$)/it,o=t.pow(e,n),s=t.eql(o,t.ONE),i=t.eql(o,t.ZERO),a=t.eql(o,t.neg(t.ONE));if(!s&&!i&&!a)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function ol(r,e){if(e!==void 0&&rs(e),r<=re)throw new Error("invalid n length: expected positive n, got "+r);if(e!==void 0&&e<1)throw new Error("invalid n length: expected positive bit length, got "+e);let t=kt(r);if(e!==void 0&&e<t)throw new Error(`invalid n length: expected bit length (${t}) >= n.length (${e})`);let n=e!==void 0?e:t,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var Xa=new WeakMap,pn=class{ORDER;BITS;BYTES;isLE;ZERO=re;ONE=$;_lengths;_mod;constructor(e,t={}){if(e<=$)throw new Error("invalid field: expected ORDER > 1, got "+e);let n;this.isLE=!1,t!=null&&typeof t=="object"&&(typeof t.BITS=="number"&&(n=t.BITS),typeof t.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:t.sqrt,enumerable:!0}),typeof t.isLE=="boolean"&&(this.isLE=t.isLE),t.allowedLengths&&(this._lengths=Object.freeze(t.allowedLengths.slice())),typeof t.modFromBytes=="boolean"&&(this._mod=t.modFromBytes));let{nBitLength:o,nByteLength:s}=ol(e,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=o,this.BYTES=s,Object.freeze(this)}create(e){return G(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return re<=e&&e<this.ORDER}is0(e){return e===re}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&$)===$}neg(e){return G(-e,this.ORDER)}eql(e,t){return e===t}sqr(e){return G(e*e,this.ORDER)}add(e,t){return G(e+t,this.ORDER)}sub(e,t){return G(e-t,this.ORDER)}mul(e,t){return G(e*t,this.ORDER)}pow(e,t){return nl(this,e,t)}div(e,t){return G(e*Ya(t,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,t){return e+t}subN(e,t){return e-t}mulN(e,t){return e*t}inv(e){return Ya(e,this.ORDER)}sqrt(e){let t=Xa.get(this);return t||Xa.set(this,t=tl(this.ORDER)),t(this,e)}toBytes(e){return this.isLE?ns(e,this.BYTES):dn(e,this.BYTES)}fromBytes(e,t=!1){K(e);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let c=new Uint8Array(o);c.set(e,s?0:c.length-e.length),e=c}if(e.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+e.length);let f=s?Ae(e):st(e);if(a&&(f=G(f,i)),!t&&!this.isValid(f))throw new Error("invalid field element: outside of range 0..ORDER");return f}invertBatch(e){return Sr(this,e)}cmov(e,t,n){return pe(n,"condition"),n?t:e}};Object.freeze(pn.prototype);function Pt(r,e={}){return new pn(r,e)}function oc(r){if(typeof r!="bigint")throw new Error("field order must be bigint");if(r<=$)throw new Error("field order must be greater than 1");let e=kt(r-$);return Math.ceil(e/8)}function as(r){let e=oc(r);return e+Math.ceil(e/2)}function cs(r,e,t=!1){K(r);let n=r.length,o=oc(e),s=Math.max(as(e),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=t?Ae(r):st(r),a=G(i,e-$)+$;return t?ns(a,o):dn(a,o)}var Kt=BigInt(0),at=BigInt(1);function Ar(r,e){let t=e.negate();return r?t:e}function ct(r,e){let t=Sr(r.Fp,e.map(n=>n.Z));return e.map((n,o)=>r.fromAffine(n.toAffine(t[o])))}function cc(r,e){if(!Number.isSafeInteger(r)||r<=0||r>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+r)}function fs(r,e){cc(r,e);let t=Math.ceil(e/r)+1,n=2**(r-1),o=2**r,s=vr(r),i=BigInt(r);return{windows:t,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function sc(r,e,t){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=t,a=Number(r&o),f=r>>i;a>n&&(a-=s,f+=at);let c=e*n,u=c+Math.abs(a)-1,d=a===0,w=a<0,y=e%2!==0;return{nextN:f,offset:u,isZero:d,isNeg:w,isNegF:y,offsetF:c}}var us=new WeakMap,fc=new WeakMap;function hs(r){return fc.get(r)||1}function ic(r){if(r!==Kt)throw new Error("invalid wNAF")}var zt=class{BASE;ZERO;Fn;bits;constructor(e,t){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=t}_unsafeLadder(e,t,n=this.ZERO){let o=e;for(;t>Kt;)t&at&&(n=n.add(o)),o=o.double(),t>>=at;return n}precomputeWindow(e,t){let{windows:n,windowSize:o}=fs(t,this.bits),s=[],i=e,a=i;for(let f=0;f<n;f++){a=i,s.push(a);for(let c=1;c<o;c++)a=a.add(i),s.push(a);i=a.double()}return s}wNAF(e,t,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=fs(e,this.bits);for(let a=0;a<i.windows;a++){let{nextN:f,offset:c,isZero:u,isNeg:d,isNegF:w,offsetF:y}=sc(n,a,i);n=f,u?s=s.add(Ar(w,t[y])):o=o.add(Ar(d,t[c]))}return ic(n),{p:o,f:s}}wNAFUnsafe(e,t,n,o=this.ZERO){let s=fs(e,this.bits);for(let i=0;i<s.windows&&n!==Kt;i++){let{nextN:a,offset:f,isZero:c,isNeg:u}=sc(n,i,s);if(n=a,!c){let d=t[f];o=o.add(u?d.negate():d)}}return ic(n),o}getPrecomputes(e,t,n){let o=us.get(t);return o||(o=this.precomputeWindow(t,e),e!==1&&(typeof n=="function"&&(o=n(o)),us.set(t,o))),o}cached(e,t,n){let o=hs(e);return this.wNAF(o,this.getPrecomputes(o,e,n),t)}unsafe(e,t,n,o){let s=hs(e);return s===1?this._unsafeLadder(e,t,o):this.wNAFUnsafe(s,this.getPrecomputes(s,e,n),t,o)}createCache(e,t){cc(t,this.bits),fc.set(e,t),us.delete(e)}hasCache(e){return hs(e)!==1}};function uc(r,e,t,n){let o=e,s=r.ZERO,i=r.ZERO;for(;t>Kt||n>Kt;)t&at&&(s=s.add(o)),n&at&&(i=i.add(o)),o=o.double(),t>>=at,n>>=at;return{p1:s,p2:i}}function ac(r,e,t){if(e){if(e.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return is(e),e}else return Pt(r,{isLE:t})}function mn(r,e,t={},n){if(n===void 0&&(n=r==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${r} CURVE object`);for(let f of["p","n","h"]){let c=e[f];if(!(typeof c=="bigint"&&c>Kt))throw new Error(`CURVE.${f} must be positive bigint`)}let o=ac(e.p,t.Fp,n),s=ac(e.n,t.Fn,n),a=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let f of a)if(!o.isValid(e[f]))throw new Error(`CURVE.${f} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:o,Fn:s}}function bn(r,e){return function(n){let o=r(n);return{secretKey:o,publicKey:e(o)}}}var $e=BigInt(0),ee=BigInt(1),ds=BigInt(2),sl=BigInt(8);function il(r,e,t,n){let o=r.sqr(t),s=r.sqr(n),i=r.add(r.mul(e.a,o),s),a=r.add(r.ONE,r.mul(e.d,r.mul(o,s)));return r.eql(i,a)}function hc(r,e={}){let t=e,n=mn("edwards",r,t,t.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;be(t,{},{uvRatio:"function"});let f=ds<<BigInt(s.BYTES*8)-ee,c=b=>o.create(b),u=t.uvRatio===void 0?(b,l)=>{try{return{isValid:!0,value:o.sqrt(o.div(b,l))}}catch{return{isValid:!1,value:$e}}}:t.uvRatio;if(!il(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function d(b,l,p=!1){let x=p?ee:$e;return Mt("coordinate "+b,l,x,f),l}function w(b){if(!(b instanceof y))throw new Error("EdwardsPoint expected")}class y{static BASE=new y(i.Gx,i.Gy,ee,c(i.Gx*i.Gy));static ZERO=new y($e,ee,ee,$e);static Fp=o;static Fn=s;X;Y;Z;T;constructor(l,p,x,g){this.X=d("x",l),this.Y=d("y",p),this.Z=d("z",x,!0),this.T=d("t",g),Object.freeze(this)}static CURVE(){return i}static fromAffine(l){if(l instanceof y)throw new Error("extended point not allowed");let{x:p,y:x}=l||{};return d("x",p),d("y",x),new y(p,x,ee,c(p*x))}static fromBytes(l,p=!1){let x=o.BYTES,{a:g,d:B}=i;l=Er(K(l,x,"point")),pe(p,"zip215");let I=Er(l),L=l[x-1];I[x-1]=L&-129;let D=Ae(I),S=p?f:o.ORDER;Mt("point.y",D,$e,S);let O=c(D*D),V=c(O-ee),F=c(B*O-g),{isValid:m,value:E}=u(V,F);if(!m)throw new Error("bad point: invalid y coordinate");let C=(E&ee)===ee,A=(L&128)!==0;if(!p&&E===$e&&A)throw new Error("bad point: x=0 and x_0=1");return A!==C&&(E=c(-E)),y.fromAffine({x:E,y:D})}static fromHex(l,p=!1){return y.fromBytes(Ft(l),p)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(l=8,p=!0){return h.createCache(this,l),p||this.multiply(ds),this}assertValidity(){let l=this,{a:p,d:x}=i;if(l.is0())throw new Error("bad point: ZERO");let{X:g,Y:B,Z:I,T:L}=l,D=c(g*g),S=c(B*B),O=c(I*I),V=c(O*O),F=c(D*p),m=c(O*c(F+S)),E=c(V+c(x*c(D*S)));if(m!==E)throw new Error("bad point: equation left != right (1)");let C=c(g*B),A=c(I*L);if(C!==A)throw new Error("bad point: equation left != right (2)")}equals(l){w(l);let{X:p,Y:x,Z:g}=this,{X:B,Y:I,Z:L}=l,D=c(p*L),S=c(B*g),O=c(x*L),V=c(I*g);return D===S&&O===V}is0(){return this.equals(y.ZERO)}negate(){return new y(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:l}=i,{X:p,Y:x,Z:g}=this,B=c(p*p),I=c(x*x),L=c(ds*c(g*g)),D=c(l*B),S=p+x,O=c(c(S*S)-B-I),V=D+I,F=V-L,m=D-I,E=c(O*F),C=c(V*m),A=c(O*m),v=c(F*V);return new y(E,C,v,A)}add(l){w(l);let{a:p,d:x}=i,{X:g,Y:B,Z:I,T:L}=this,{X:D,Y:S,Z:O,T:V}=l,F=c(g*D),m=c(B*S),E=c(L*x*V),C=c(I*O),A=c((g+B)*(D+S)-F-m),v=C-E,T=C+E,_=c(m-p*F),U=c(A*v),R=c(T*_),N=c(A*_),P=c(v*T);return new y(U,R,P,N)}subtract(l){return w(l),this.add(l.negate())}multiply(l){if(!s.isValidNot0(l))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p,f:x}=h.cached(this,l,g=>ct(y,g));return ct(y,[p,x])[0]}multiplyUnsafe(l){if(!s.isValid(l))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return l===$e?y.ZERO:this.is0()||l===ee?this:h.unsafe(this,l,p=>ct(y,p))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return h.unsafe(this,i.n).is0()}toAffine(l){let p=this,x=l,{X:g,Y:B,Z:I}=p,L=p.is0();x==null&&(x=L?sl:o.inv(I));let D=c(g*x),S=c(B*x),O=o.mul(I,x);if(L)return{x:$e,y:ee};if(O!==ee)throw new Error("invZ was invalid");return{x:D,y:S}}clearCofactor(){return a===ee?this:this.multiplyUnsafe(a)}toBytes(){let{x:l,y:p}=this.toAffine(),x=o.toBytes(p);return x[x.length-1]|=l&ee?128:0,x}toHex(){return Nt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let h=new zt(y,s.BITS);return s.BITS>=8&&y.BASE.precompute(8),Object.freeze(y.prototype),Object.freeze(y),y}var yn=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(e){this.ep=e}static fromBytes(e){os()}static fromHex(e){os()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(e){return this.ep.toAffine(e)}toHex(){return Nt(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(e){return this.assertSame(e),this.init(this.ep.add(e.ep))}subtract(e){return this.assertSame(e),this.init(this.ep.subtract(e.ep))}multiply(e){return this.init(this.ep.multiply(e))}multiplyUnsafe(e){return this.init(this.ep.multiplyUnsafe(e))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(e,t){return this.ep.precompute(e,t),this}};function dc(r,e,t={}){if(typeof e!="function")throw new Error('"hash" function param is required');let n=e,o=t;be(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function"});let{prehash:s}=o,{BASE:i,Fp:a,Fn:f}=r,c=n.outputLen,u=2*a.BYTES;if(c!==void 0&&(me(c,"hash.outputLen"),c!==u))throw new Error(`hash.outputLen must be ${u}, got ${c}`);let d=o.randomBytes===void 0?gr:o.randomBytes,w=o.adjustScalarBytes===void 0?m=>m:o.adjustScalarBytes,y=o.domain===void 0?(m,E,C)=>{if(pe(C,"phflag"),E.length||C)throw new Error("Contexts/pre-hash are not supported");return m}:o.domain;function h(m){return f.create(Ae(m))}function b(m){let E=D.secretKey;K(m,D.secretKey,"secretKey");let C=K(n(m),2*E,"hashedSecretKey"),A=w(C.slice(0,E)),v=C.slice(E,2*E),T=h(A);return{head:A,prefix:v,scalar:T}}function l(m){let{head:E,prefix:C,scalar:A}=b(m),v=i.multiply(A),T=v.toBytes();return{head:E,prefix:C,scalar:A,point:v,pointBytes:T}}function p(m){return l(m).pointBytes}function x(m=Uint8Array.of(),...E){let C=W(...E);return h(n(y(C,K(m,void 0,"context"),!!s)))}function g(m,E,C={}){m=K(m,void 0,"message"),s&&(m=s(m));let{prefix:A,scalar:v,pointBytes:T}=l(E),_=x(C.context,A,m),U=i.multiply(_).toBytes(),R=x(C.context,U,T,m),N=f.create(_+R*v);if(!f.isValid(N))throw new Error("sign failed: invalid s");let P=W(U,f.toBytes(N));return K(P,D.signature,"result")}let B={zip215:o.zip215};function I(m,E,C,A=B){let{context:v}=A,T=A.zip215===void 0?!!B.zip215:A.zip215,_=D.signature;m=K(m,_,"signature"),E=K(E,void 0,"message"),C=K(C,D.publicKey,"publicKey"),T!==void 0&&pe(T,"zip215"),s&&(E=s(E));let U=_/2,R=m.subarray(0,U),N=Ae(m.subarray(U,_)),P,z,k;try{P=r.fromBytes(C,T),z=r.fromBytes(R,T),k=i.multiplyUnsafe(N)}catch{return!1}if(!T&&P.isSmallOrder())return!1;let X=x(v,R,C,E);return z.add(P.multiplyUnsafe(X)).subtract(k).clearCofactor().is0()}let L=a.BYTES,D={secretKey:L,publicKey:L,signature:2*L,seed:L};function S(m){return m=m===void 0?d(D.seed):m,K(m,D.seed,"seed")}function O(m){return ot(m)&&m.length===D.secretKey}function V(m,E){try{return!!r.fromBytes(m,E===void 0?B.zip215:E)}catch{return!1}}let F={getExtendedPublicKey:l,randomSecretKey:S,isValidSecretKey:O,isValidPublicKey:V,toMontgomery(m){let{y:E}=r.fromBytes(m),C=D.publicKey,A=C===32;if(!A&&C!==57)throw new Error("only defined for 25519 and 448");let v=A?a.div(ee+E,ee-E):a.div(E-ee,E+ee);return a.toBytes(v)},toMontgomerySecret(m){let E=D.secretKey;K(m,E);let C=n(m.subarray(0,E));return w(C).subarray(0,E)}};return Object.freeze(D),Object.freeze(F),Object.freeze({keygen:bn(S,p),getPublicKey:p,sign:g,verify:I,utils:F,Point:r,lengths:D})}function Br(r,e){if(me(r),me(e),e<0||e>4)throw new Error("invalid I2OSP length: "+e);if(r<0||r>2**(8*e)-1)throw new Error("invalid I2OSP input: "+r);let t=Array.from({length:e}).fill(0);for(let n=e-1;n>=0;n--)t[n]=r&255,r>>>=8;return new Uint8Array(t)}function al(r,e){let t=new Uint8Array(r.length);for(let n=0;n<r.length;n++)t[n]=r[n]^e[n];return t}function cl(r){if(!ot(r)&&typeof r!="string")throw new Error("DST must be Uint8Array or ascii string");let e=typeof r=="string"?ln(r):r;if(e.length===0)throw new Error("DST must be non-empty");return e}function ls(r,e,t,n){K(r),me(t),e=cl(e),e.length>255&&(e=n(W(ln("H2C-OVERSIZE-DST-"),e)));let{outputLen:o,blockLen:s}=n,i=Math.ceil(t/o);if(t>65535||i>255)throw new Error("expand_message_xmd: invalid lenInBytes");let a=W(e,Br(e.length,1)),f=new Uint8Array(s),c=Br(t,2),u=new Array(i),d=n(W(f,r,c,Br(0,1),a));u[0]=n(W(d,Br(1,1),a));for(let y=1;y<i;y++){let h=[al(d,u[y-1]),Br(y+1,1),a];u[y]=n(W(...h))}return W(...u).slice(0,t)}var lc="HashToScalar-";var fl=BigInt(0),Ne=BigInt(1),pc=BigInt(2);var ul=BigInt(5),hl=BigInt(8),Vt=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),ys={p:Vt,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:hl,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function dl(r){let e=BigInt(10),t=BigInt(20),n=BigInt(40),o=BigInt(80),s=Vt,a=r*r%s*r%s,f=q(a,pc,s)*a%s,c=q(f,Ne,s)*r%s,u=q(c,ul,s)*c%s,d=q(u,e,s)*u%s,w=q(d,t,s)*d%s,y=q(w,n,s)*w%s,h=q(y,o,s)*y%s,b=q(h,o,s)*y%s,l=q(b,e,s)*u%s;return{pow_p_5_8:q(l,pc,s)*r%s,b2:a}}function ll(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var ps=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function xs(r,e){let t=Vt,n=G(e*e*e,t),o=G(n*n*e,t),s=dl(r*o).pow_p_5_8,i=G(r*n*s,t),a=G(e*i*i,t),f=i,c=G(i*ps,t),u=a===r,d=a===G(-r,t),w=a===G(-r*ps,t);return u&&(i=f),(d||w)&&(i=c),Oe(i,t)&&(i=G(-i,t)),{isValid:u||d,value:i}}var Ye=hc(ys,{uvRatio:xs}),Ze=Ye.Fp,yc=Ye.Fn;function pl(r){return dc(Ye,cn,Object.assign({adjustScalarBytes:ll,zip215:!0},r))}var xc=pl({});var ms=ps,ml=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),bl=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),yl=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),xl=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),mc=r=>xs(Ne,r),gl=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),bs=r=>Ze.create(Ae(r)&gl);function bc(r){let{d:e}=ys,t=Vt,n=p=>Ze.create(p),o=n(ms*r*r),s=n((o+Ne)*yl),i=BigInt(-1),a=n((i-e*o)*n(o+e)),{isValid:f,value:c}=xs(s,a),u=n(c*r);Oe(u,t)||(u=n(-u)),f||(c=u),f||(i=o);let d=n(i*(o-Ne)*xl-a),w=c*c,y=n((c+c)*a),h=n(d*ml),b=n(Ne-w),l=n(Ne+w);return new Ye(n(y*l),n(b*h),n(h*l),n(y*b))}var Ge=class r extends yn{static BASE=new r(Ye.BASE);static ZERO=new r(Ye.ZERO);static Fp=Ze;static Fn=yc;constructor(e){super(e)}static fromAffine(e){return new r(Ye.fromAffine(e))}assertSame(e){if(!(e instanceof r))throw new Error("RistrettoPoint expected")}init(e){return new r(e)}static fromBytes(e){he(e,32);let{a:t,d:n}=ys,o=Vt,s=B=>Ze.create(B),i=bs(e);if(!$a(Ze.toBytes(i),e)||Oe(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),f=s(Ne+t*a),c=s(Ne-t*a),u=s(f*f),d=s(c*c),w=s(t*n*u-d),{isValid:y,value:h}=mc(s(w*d)),b=s(h*c),l=s(h*b*w),p=s((i+i)*b);Oe(p,o)&&(p=s(-p));let x=s(f*l),g=s(p*x);if(!y||Oe(g,o)||x===fl)throw new Error("invalid ristretto255 encoding 2");return new r(new Ye(p,x,Ne,g))}static fromHex(e){return r.fromBytes(mr(e))}toBytes(){let{X:e,Y:t,Z:n,T:o}=this.ep,s=Vt,i=l=>Ze.create(l),a=i(i(n+t)*i(n-t)),f=i(e*t),c=i(f*f),{value:u}=mc(i(a*c)),d=i(u*a),w=i(u*f),y=i(d*w*o),h;if(Oe(o*y,s)){let l=i(t*ms),p=i(e*ms);e=l,t=p,h=i(d*bl)}else h=w;Oe(e*y,s)&&(t=i(-t));let b=i((n-t)*h);return Oe(b,s)&&(b=i(-b)),Ze.toBytes(b)}equals(e){this.assertSame(e);let{X:t,Y:n}=this.ep,{X:o,Y:s}=e.ep,i=c=>Ze.create(c),a=i(t*s)===i(n*o),f=i(n*s)===i(t*o);return a||f}is0(){return this.equals(r.ZERO)}};Object.freeze(Ge.BASE);Object.freeze(Ge.ZERO);Object.freeze(Ge.prototype);Object.freeze(Ge);var wl=Object.freeze({Point:Ge,hashToCurve(r,e){let t=e?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":e.DST,n=ls(r,t,64,cn);return wl.deriveToCurve(n)},hashToScalar(r,e={DST:lc}){let t=ls(r,e.DST,64,cn);return yc.create(Ae(t))},deriveToCurve(r){he(r,64);let e=bs(r.subarray(0,32)),t=bc(e),n=bs(r.subarray(32,64)),o=bc(n);return new Ge(t.add(o))}});var Ir=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},xn=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var gc={get(r=globalThis){let e=r.crypto;if(e?.subtle==null)throw new xn("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return e}};var gn=gc;var wn=32;var gs,El=(async()=>{try{return await gn.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function vl(r,e,t){if(r.buffer instanceof ArrayBuffer){let n=await gn.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await gn.get().subtle.verify({name:"Ed25519"},n,e,t instanceof Uint8Array?t:t.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Sl(r,e,t){return xc.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}async function wc(r,e,t){return gs==null&&(gs=await El),gs?vl(r,e,t):Sl(r,e,t)}function En(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var vn=class{type="Ed25519";raw;constructor(e){this.raw=ws(e,wn)}toMultihash(){return tt.digest(Rt(this))}toCID(){return ve.createV1(114,this.toMultihash())}toString(){return ne.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ke(this.raw,e.raw)}verify(e,t,n){n?.signal?.throwIfAborted();let o=wc(this.raw,t,e);return En(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function vc(r){return r=ws(r,wn),new vn(r)}function ws(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new Ee(`Key must be a Uint8Array of length ${e}, got ${r.length}`);return r}var Bl=Math.pow(2,7),Il=Math.pow(2,14),Dl=Math.pow(2,21),Sc=Math.pow(2,28),Ac=Math.pow(2,35),Bc=Math.pow(2,42),Ic=Math.pow(2,49),se=128,Xe=127;function Dr(r){if(r<Bl)return 1;if(r<Il)return 2;if(r<Dl)return 3;if(r<Sc)return 4;if(r<Ac)return 5;if(r<Bc)return 6;if(r<Ic)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Dc(r,e,t=0){switch(Dr(r)){case 8:e[t++]=r&255|se,r/=128;case 7:e[t++]=r&255|se,r/=128;case 6:e[t++]=r&255|se,r/=128;case 5:e[t++]=r&255|se,r/=128;case 4:e[t++]=r&255|se,r>>>=7;case 3:e[t++]=r&255|se,r>>>=7;case 2:e[t++]=r&255|se,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function Cc(r,e){let t=r[e],n=0;if(n+=t&Xe,t<se||(t=r[e+1],n+=(t&Xe)<<7,t<se)||(t=r[e+2],n+=(t&Xe)<<14,t<se)||(t=r[e+3],n+=(t&Xe)<<21,t<se)||(t=r[e+4],n+=(t&Xe)*Sc,t<se)||(t=r[e+5],n+=(t&Xe)*Ac,t<se)||(t=r[e+6],n+=(t&Xe)*Bc,t<se)||(t=r[e+7],n+=(t&Xe)*Ic,t<se))return n;throw new RangeError("Could not decode varint")}var Es=new Float32Array([-0]),We=new Uint8Array(Es.buffer);function Tc(r,e,t){Es[0]=r,e[t]=We[0],e[t+1]=We[1],e[t+2]=We[2],e[t+3]=We[3]}function Lc(r,e){return We[0]=r[e],We[1]=r[e+1],We[2]=r[e+2],We[3]=r[e+3],Es[0]}var vs=new Float64Array([-0]),oe=new Uint8Array(vs.buffer);function Uc(r,e,t){vs[0]=r,e[t]=oe[0],e[t+1]=oe[1],e[t+2]=oe[2],e[t+3]=oe[3],e[t+4]=oe[4],e[t+5]=oe[5],e[t+6]=oe[6],e[t+7]=oe[7]}function _c(r,e){return oe[0]=r[e],oe[1]=r[e+1],oe[2]=r[e+2],oe[3]=r[e+3],oe[4]=r[e+4],oe[5]=r[e+5],oe[6]=r[e+6],oe[7]=r[e+7],vs[0]}var Cl=BigInt(Number.MAX_SAFE_INTEGER),Tl=BigInt(Number.MIN_SAFE_INTEGER),de=class r{lo;hi;constructor(e,t){this.lo=e|0,this.hi=t|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(t+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(BigInt(t)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,t=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?t===0?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return ft;if(e<Cl&&e>Tl)return this.fromNumber(Number(e));let t=e<0n;t&&(e=-e);let n=e>>32n,o=e-(n<<32n);return t&&(n=~n|0n,o=~o|0n,++o>Rc&&(o=0n,++n>Rc&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(e){if(e===0)return ft;let t=e<0;t&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return t&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(e){return typeof e=="number"?r.fromNumber(e):typeof e=="bigint"?r.fromBigInt(e):typeof e=="string"?r.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new r(e.low>>>0,e.high>>>0):ft}},ft=new de(0,0);ft.toBigInt=function(){return 0n};ft.zzEncode=ft.zzDecode=function(){return this};ft.length=function(){return 1};var Rc=4294967296n;function Oc(r){let e=0,t=0;for(let n=0;n<r.length;++n)t=r.charCodeAt(n),t<128?e+=1:t<2048?e+=2:(t&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function Nc(r,e,t){if(t-e<1)return"";let o,s=[],i=0,a;for(;e<t;)a=r[e++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|r[e++]&63:a>239&&a<365?(a=((a&7)<<18|(r[e++]&63)<<12|(r[e++]&63)<<6|r[e++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(r[e++]&63)<<6|r[e++]&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 Ss(r,e,t){let n=t,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?e[t++]=o:o<2048?(e[t++]=o>>6|192,e[t++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,e[t++]=o>>18|240,e[t++]=o>>12&63|128,e[t++]=o>>6&63|128,e[t++]=o&63|128):(e[t++]=o>>12|224,e[t++]=o>>6&63|128,e[t++]=o&63|128);return t-n}function ye(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function Sn(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var As=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,ye(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw ye(this,4);return Sn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw ye(this,4);return Sn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw ye(this,4);let e=Lc(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw ye(this,4);let e=_c(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),t=this.pos,n=this.pos+e;if(n>this.len)throw ye(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return Nc(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw ye(this,e);this.pos+=e}else do if(this.pos>=this.len)throw ye(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new de(0,0),t=0;if(this.len-this.pos>4){for(;t<4;++t)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;t=0}else{for(;t<3;++t){if(this.pos>=this.len)throw ye(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<t*7)>>>0,e}if(this.len-this.pos>4){for(;t<5;++t)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;t<5;++t){if(this.pos>=this.len)throw ye(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw ye(this,8);let e=Sn(this.buf,this.pos+=4),t=Sn(this.buf,this.pos+=4);return new de(e,t)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=Cc(this.buf,this.pos);return this.pos+=Dr(e),e}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 Cr(r){return new As(r instanceof Uint8Array?r:r.subarray())}function An(r,e,t){let n=Cr(r);return e.decode(n,void 0,t)}function Bs(r){let e=r??8192,t=e>>>1,n,o=e;return function(i){if(i<1||i>t)return fe(i);o+i>e&&(n=fe(e),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var ut=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function Is(){}var Cs=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Ll=Bs();function Ul(r){return globalThis.Buffer!=null?fe(r):Ll(r)}var Lr=class{len;head;tail;states;constructor(){this.len=0,this.head=new ut(Is,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new ut(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Ts((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(Bn,10,de.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=de.fromBigInt(e);return this._push(Bn,t.length(),t)}uint64Number(e){return this._push(Dc,Dr(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let t=de.fromBigInt(e).zzEncode();return this._push(Bn,t.length(),t)}sint64Number(e){let t=de.fromNumber(e).zzEncode();return this._push(Bn,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Ds,1,e?1:0)}fixed32(e){return this._push(Tr,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=de.fromBigInt(e);return this._push(Tr,4,t.lo)._push(Tr,4,t.hi)}fixed64Number(e){let t=de.fromNumber(e);return this._push(Tr,4,t.lo)._push(Tr,4,t.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(Tc,4,e)}double(e){return this._push(Uc,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(Ds,1,0):this.uint32(t)._push(Rl,t,e)}string(e){let t=Oc(e);return t!==0?this.uint32(t)._push(Ss,t,e):this._push(Ds,1,0)}fork(){return this.states=new Cs(this),this.head=this.tail=new ut(Is,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 ut(Is,0,0),this.len=0),this}ldelim(){let e=this.head,t=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=t,this.len+=n),this}finish(){let e=this.head.next,t=Ul(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function Ds(r,e,t){e[t]=r&255}function _l(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var Ts=class extends ut{next;constructor(e,t){super(_l,e,t),this.next=void 0}};function Bn(r,e,t){for(;r.hi!==0;)e[t++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)e[t++]=r.lo&127|128,r.lo=r.lo>>>7;e[t++]=r.lo}function Tr(r,e,t){e[t]=r&255,e[t+1]=r>>>8&255,e[t+2]=r>>>16&255,e[t+3]=r>>>24}function Rl(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(Lr.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(Ol,e,r),this},Lr.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(Nl,e,r),this});function Ol(r,e,t){e.set(r,t)}function Nl(r,e,t){r.length<40?Ss(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(Ut(r),t)}function Ls(){return new Lr}function In(r,e){let t=Ls();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}function*Dn(r,e,t){let n=Cr(r);yield*e.stream(n,void 0,"$",t)}var Cn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Tn(r,e,t,n,o){return{name:r,type:e,encode:t,decode:n,stream:o}}function Us(r){function e(s){if(r[s.toString()]==null)throw new Error("Invalid enum value");return r[s]}let t=function(i,a){let f=e(i);a.int32(f)},n=function(i){let a=i.int32();return e(a)},o=function*(i){let a=i.int32();yield e(a)};return Tn("enum",Cn.VARINT,t,n,o)}function Ln(r,e,t){return Tn("message",Cn.LENGTH_DELIMITED,r,e,t)}var ie;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(ie||(ie={}));var _s;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(_s||(_s={}));(function(r){r.codec=()=>Us(_s)})(ie||(ie={}));var Ur;(function(r){let e;r.codec=()=>(e==null&&(e=Ln((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),ie.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let f={},c=i==null?s.len:s.pos+i;for(;s.pos<c;){let u=s.uint32();switch(u>>>3){case 1:{f.Type=ie.codec().decode(s);break}case 2:{f.Data=s.bytes();break}default:{s.skipType(u&7);break}}}return f},function*(s,i,a,f={}){let c=i==null?s.len:s.pos+i;for(;s.pos<c;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${a}.Type`,value:ie.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),e);function t(s){return In(s,r.codec())}r.encode=t;function n(s,i){return An(s,r.codec(),i)}r.decode=n;function o(s,i){return Dn(s,r.codec(),i)}r.stream=o})(Ur||(Ur={}));var Rs;(function(r){let e;r.codec=()=>(e==null&&(e=Ln((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),ie.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let f={},c=i==null?s.len:s.pos+i;for(;s.pos<c;){let u=s.uint32();switch(u>>>3){case 1:{f.Type=ie.codec().decode(s);break}case 2:{f.Data=s.bytes();break}default:{s.skipType(u&7);break}}}return f},function*(s,i,a,f={}){let c=i==null?s.len:s.pos+i;for(;s.pos<c;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${a}.Type`,value:ie.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),e);function t(s){return In(s,r.codec())}r.encode=t;function n(s,i){return An(s,r.codec(),i)}r.decode=n;function o(s,i){return Dn(s,r.codec(),i)}r.stream=o})(Rs||(Rs={}));var Un=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,t){if(rn(e),he(t,void 0,"key"),this.iHash=e.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(t.length>n?e.create().update(t).digest():t);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=e.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),_e(o)}update(e){return Ot(this),this.iHash.update(e),this}digestInto(e){Ot(this),nn(e,this),this.finished=!0;let t=e.subarray(0,this.outputLen);this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:t,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=a,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Mc=(()=>{let r=((e,t,n)=>new Un(e,t).update(n).digest());return r.create=(e,t)=>new Un(e,t),r})();var kc=(r,e)=>(r+(r>=0?e:-e)/Pc)/e;function Ml(r,e,t){Mt("scalar",r,Be,t);let[[n,o],[s,i]]=e,a=kc(i*r,t),f=kc(-o*r,t),c=r-a*n-f*s,u=-a*o-f*i,d=c<Be,w=u<Be;d&&(c=-c),w&&(u=-u);let y=vr(Math.ceil(kt(t)/2))+Je;if(c<Be||c>=y||u<Be||u>=y)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:d,k1:c,k2neg:w,k2:u}}function Ns(r){if(!["compact","recovered","der"].includes(r))throw new Error('Signature format must be "compact", "recovered", or "der"');return r}function Os(r,e){be(r);let t={};for(let n of Object.keys(e))t[n]=r[n]===void 0?e[n]:r[n];return pe(t.lowS,"lowS"),pe(t.prehash,"prehash"),t.format!==void 0&&Ns(t.format),t}var Fs=class extends Error{constructor(e=""){super(e)}},xe={Err:Fs,_tlv:{encode:(r,e)=>{let{Err:t}=xe;if(me(r,"tag"),r<0||r>255)throw new t("tlv.encode: wrong tag");if(typeof e!="string")throw new TypeError('"data" expected string, got type='+typeof e);if(e.length&1)throw new t("tlv.encode: unpadded data");let n=e.length/2,o=wr(n);if(o.length/2&128)throw new t("tlv.encode: long form length too big");let s=n>127?wr(o.length/2|128):"";return wr(r)+s+o+e},decode(r,e){let{Err:t}=xe;e=K(e,void 0,"DER data");let n=0;if(r<0||r>255)throw new t("tlv.encode: wrong tag");if(e.length<2||e[n++]!==r)throw new t("tlv.decode: wrong tlv");let o=e[n++],s=!!(o&128),i=0;if(!s)i=o;else{let f=o&127;if(!f)throw new t("tlv.decode(long): indefinite length not supported");if(f>4)throw new t("tlv.decode(long): byte length is too big");let c=e.subarray(n,n+f);if(c.length!==f)throw new t("tlv.decode: length bytes not complete");if(c[0]===0)throw new t("tlv.decode(long): zero leftmost byte");for(let u of c)i=i<<8|u;if(n+=f,i<128)throw new t("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+i);if(a.length!==i)throw new t("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+i)}}},_int:{encode(r){let{Err:e}=xe;if(hn(r),r<Be)throw new e("integer: negative integers are not allowed");let t=wr(r);if(Number.parseInt(t[0],16)&8&&(t="00"+t),t.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return t},decode(r){let{Err:e}=xe;if(r.length<1)throw new e("invalid signature integer: empty");if(r[0]&128)throw new e("invalid signature integer: negative");if(r.length>1&&r[0]===0&&!(r[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return st(r)}},toSig(r){let{Err:e,_int:t,_tlv:n}=xe,o=K(r,void 0,"signature"),{v:s,l:i}=n.decode(48,o);if(i.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:f}=n.decode(2,s),{v:c,l:u}=n.decode(2,f);if(u.length)throw new e("invalid signature: left bytes after parsing");return{r:t.decode(a),s:t.decode(c)}},hexFromSig(r){let{_tlv:e,_int:t}=xe,n=e.encode(2,t.encode(r.r)),o=e.encode(2,t.encode(r.s)),s=n+o;return e.encode(48,s)}};Object.freeze(xe._tlv);Object.freeze(xe._int);Object.freeze(xe);var Be=BigInt(0),Je=BigInt(1),Pc=BigInt(2),_n=BigInt(3),kl=BigInt(4);function Kc(r,e={}){let t=mn("weierstrass",r,e),n=t.Fp,o=t.Fn,s=t.CURVE,{h:i,n:a}=s;be(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:f,allowInfinityPoint:c}=e;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=Vc(n,o);function d(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function w(F,m,E){if(c&&m.is0())return Uint8Array.of(0);let{x:C,y:A}=m.toAffine(),v=n.toBytes(C);if(pe(E,"isCompressed"),E){d();let T=!n.isOdd(A);return W(zc(T),v)}else return W(Uint8Array.of(4),v,n.toBytes(A))}function y(F){K(F,void 0,"Point");let{publicKey:m,publicKeyUncompressed:E}=u,C=F.length,A=F[0],v=F.subarray(1);if(c&&C===1&&A===0)return{x:n.ZERO,y:n.ZERO};if(C===m&&(A===2||A===3)){let T=n.fromBytes(v);if(!n.isValid(T))throw new Error("bad point: is not on curve, wrong x");let _=l(T),U;try{U=n.sqrt(_)}catch(P){let z=P instanceof Error?": "+P.message:"";throw new Error("bad point: is not on curve, sqrt error"+z)}d();let R=n.isOdd(U);return(A&1)===1!==R&&(U=n.neg(U)),{x:T,y:U}}else if(C===E&&A===4){let T=n.BYTES,_=n.fromBytes(v.subarray(0,T)),U=n.fromBytes(v.subarray(T,T*2));if(!p(_,U))throw new Error("bad point: is not on curve");return{x:_,y:U}}else throw new Error(`bad point: got length ${C}, expected compressed=${m} or uncompressed=${E}`)}let h=e.toBytes===void 0?w:e.toBytes,b=e.fromBytes===void 0?y:e.fromBytes;function l(F){let m=n.sqr(F),E=n.mul(m,F);return n.add(n.add(E,n.mul(F,s.a)),s.b)}function p(F,m){let E=n.sqr(m),C=l(F);return n.eql(E,C)}if(!p(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let x=n.mul(n.pow(s.a,_n),kl),g=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(x,g)))throw new Error("bad curve params: a or b");function B(F,m,E=!1){if(!n.isValid(m)||E&&n.is0(m))throw new Error(`bad point coordinate ${F}`);return m}function I(F){if(!(F instanceof S))throw new Error("Weierstrass Point expected")}function L(F){if(!f||!f.basises)throw new Error("no endo");return Ml(F,f.basises,o.ORDER)}function D(F,m,E,C,A){return E=new S(n.mul(E.X,F),E.Y,E.Z),m=Ar(C,m),E=Ar(A,E),m.add(E)}class S{static BASE=new S(s.Gx,s.Gy,n.ONE);static ZERO=new S(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(m,E,C){this.X=B("x",m),this.Y=B("y",E,!0),this.Z=B("z",C),Object.freeze(this)}static CURVE(){return s}static fromAffine(m){let{x:E,y:C}=m||{};if(!m||!n.isValid(E)||!n.isValid(C))throw new Error("invalid affine point");if(m instanceof S)throw new Error("projective point not allowed");return n.is0(E)&&n.is0(C)?S.ZERO:new S(E,C,n.ONE)}static fromBytes(m){let E=S.fromAffine(b(K(m,void 0,"point")));return E.assertValidity(),E}static fromHex(m){return S.fromBytes(Ft(m))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=8,E=!0){return V.createCache(this,m),E||this.multiply(_n),this}assertValidity(){let m=this;if(m.is0()){if(e.allowInfinityPoint&&n.is0(m.X)&&n.eql(m.Y,n.ONE)&&n.is0(m.Z))return;throw new Error("bad point: ZERO")}let{x:E,y:C}=m.toAffine();if(!n.isValid(E)||!n.isValid(C))throw new Error("bad point: x or y not field elements");if(!p(E,C))throw new Error("bad point: equation left != right");if(!m.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:m}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(m)}equals(m){I(m);let{X:E,Y:C,Z:A}=this,{X:v,Y:T,Z:_}=m,U=n.eql(n.mul(E,_),n.mul(v,A)),R=n.eql(n.mul(C,_),n.mul(T,A));return U&&R}negate(){return new S(this.X,n.neg(this.Y),this.Z)}double(){let{a:m,b:E}=s,C=n.mul(E,_n),{X:A,Y:v,Z:T}=this,_=n.ZERO,U=n.ZERO,R=n.ZERO,N=n.mul(A,A),P=n.mul(v,v),z=n.mul(T,T),k=n.mul(A,v);return k=n.add(k,k),R=n.mul(A,T),R=n.add(R,R),_=n.mul(m,R),U=n.mul(C,z),U=n.add(_,U),_=n.sub(P,U),U=n.add(P,U),U=n.mul(_,U),_=n.mul(k,_),R=n.mul(C,R),z=n.mul(m,z),k=n.sub(N,z),k=n.mul(m,k),k=n.add(k,R),R=n.add(N,N),N=n.add(R,N),N=n.add(N,z),N=n.mul(N,k),U=n.add(U,N),z=n.mul(v,T),z=n.add(z,z),N=n.mul(z,k),_=n.sub(_,N),R=n.mul(z,P),R=n.add(R,R),R=n.add(R,R),new S(_,U,R)}add(m){I(m);let{X:E,Y:C,Z:A}=this,{X:v,Y:T,Z:_}=m,U=n.ZERO,R=n.ZERO,N=n.ZERO,P=s.a,z=n.mul(s.b,_n),k=n.mul(E,v),X=n.mul(C,T),J=n.mul(A,_),Q=n.add(E,C),Y=n.add(v,T);Q=n.mul(Q,Y),Y=n.add(k,X),Q=n.sub(Q,Y),Y=n.add(E,A);let ae=n.add(v,_);return Y=n.mul(Y,ae),ae=n.add(k,J),Y=n.sub(Y,ae),ae=n.add(C,A),U=n.add(T,_),ae=n.mul(ae,U),U=n.add(X,J),ae=n.sub(ae,U),N=n.mul(P,Y),U=n.mul(z,J),N=n.add(U,N),U=n.sub(X,N),N=n.add(X,N),R=n.mul(U,N),X=n.add(k,k),X=n.add(X,k),J=n.mul(P,J),Y=n.mul(z,Y),X=n.add(X,J),J=n.sub(k,J),J=n.mul(P,J),Y=n.add(Y,J),k=n.mul(X,Y),R=n.add(R,k),k=n.mul(ae,Y),U=n.mul(Q,U),U=n.sub(U,k),k=n.mul(Q,X),N=n.mul(ae,N),N=n.add(N,k),new S(U,R,N)}subtract(m){return I(m),this.add(m.negate())}is0(){return this.equals(S.ZERO)}multiply(m){let{endo:E}=e;if(!o.isValidNot0(m))throw new RangeError("invalid scalar: out of range");let C,A,v=T=>V.cached(this,T,_=>ct(S,_));if(E){let{k1neg:T,k1:_,k2neg:U,k2:R}=L(m),{p:N,f:P}=v(_),{p:z,f:k}=v(R);A=P.add(k),C=D(E.beta,N,z,T,U)}else{let{p:T,f:_}=v(m);C=T,A=_}return ct(S,[C,A])[0]}multiplyUnsafe(m){let{endo:E}=e,C=this,A=m;if(!o.isValid(A))throw new RangeError("invalid scalar: out of range");if(A===Be||C.is0())return S.ZERO;if(A===Je)return C;if(V.hasCache(this))return this.multiply(A);if(E){let{k1neg:v,k1:T,k2neg:_,k2:U}=L(A),{p1:R,p2:N}=uc(S,C,T,U);return D(E.beta,R,N,v,_)}else return V.unsafe(C,A)}toAffine(m){let E=this,C=m,{X:A,Y:v,Z:T}=E;if(n.eql(T,n.ONE))return{x:A,y:v};let _=E.is0();C==null&&(C=_?n.ONE:n.inv(T));let U=n.mul(A,C),R=n.mul(v,C),N=n.mul(T,C);if(_)return{x:n.ZERO,y:n.ZERO};if(!n.eql(N,n.ONE))throw new Error("invZ was invalid");return{x:U,y:R}}isTorsionFree(){let{isTorsionFree:m}=e;return i===Je?!0:m?m(S,this):V.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:m}=e;return i===Je?this:m?m(S,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===Je?this.is0():this.clearCofactor().is0()}toBytes(m=!0){return pe(m,"isCompressed"),this.assertValidity(),h(S,this,m)}toHex(m=!0){return Nt(this.toBytes(m))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let O=o.BITS,V=new zt(S,e.endo?Math.ceil(O/2):O);return O>=8&&S.BASE.precompute(8),Object.freeze(S.prototype),Object.freeze(S),S}function zc(r){return Uint8Array.of(r?2:3)}function Vc(r,e){return{secretKey:e.BYTES,publicKey:1+r.BYTES,publicKeyUncompressed:1+2*r.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function Pl(r,e={}){let{Fn:t}=r,n=e.randomBytes===void 0?gr:e.randomBytes,o=Object.assign(Vc(r.Fp,t),{seed:Math.max(as(t.ORDER),16)});function s(y){try{let h=t.fromBytes(y);return t.isValidNot0(h)}catch{return!1}}function i(y,h){let{publicKey:b,publicKeyUncompressed:l}=o;try{let p=y.length;return h===!0&&p!==b||h===!1&&p!==l?!1:!!r.fromBytes(y)}catch{return!1}}function a(y){return y=y===void 0?n(o.seed):y,cs(K(y,o.seed,"seed"),t.ORDER)}function f(y,h=!0){return r.BASE.multiply(t.fromBytes(y)).toBytes(h)}function c(y){let{secretKey:h,publicKey:b,publicKeyUncompressed:l}=o,p=t._lengths;if(!ot(y))return;let x=K(y,void 0,"key").length,g=x===b||x===l,B=x===h||!!p?.includes(x);if(!(g&&B))return g}function u(y,h,b=!0){if(c(y)===!0)throw new Error("first arg must be private key");if(c(h)===!1)throw new Error("second arg must be public key");let l=t.fromBytes(y);return r.fromBytes(h).multiply(l).toBytes(b)}let d={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},w=bn(a,f);return Object.freeze(d),Object.freeze(o),Object.freeze({getPublicKey:f,getSharedSecret:u,keygen:w,Point:r,utils:d,lengths:o})}function qc(r,e,t={}){let n=e;rn(n),be(t,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),t=Object.assign({},t);let o=t.randomBytes===void 0?gr:t.randomBytes,s=t.hmac===void 0?(A,v)=>Mc(n,A,v):t.hmac,{Fp:i,Fn:a}=r,{ORDER:f,BITS:c}=a,{keygen:u,getPublicKey:d,getSharedSecret:w,utils:y,lengths:h}=Pl(r,t),b={prehash:!0,lowS:typeof t.lowS=="boolean"?t.lowS:!0,format:"compact",extraEntropy:!1},l=f*Pc+Je<i.ORDER;function p(A){let v=f>>Je;return A>v}function x(A,v){if(!a.isValidNot0(v))throw new Error(`invalid signature ${A}: out of range 1..Point.Fn.ORDER`);return v}function g(){if(l)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function B(A,v){Ns(v);let T=h.signature,_=v==="compact"?T:v==="recovered"?T+1:void 0;return K(A,_)}class I{r;s;recovery;constructor(v,T,_){if(this.r=x("r",v),this.s=x("s",T),_!=null){if(g(),![0,1,2,3].includes(_))throw new Error("invalid recovery id");this.recovery=_}Object.freeze(this)}static fromBytes(v,T=b.format){B(v,T);let _;if(T==="der"){let{r:P,s:z}=xe.toSig(K(v));return new I(P,z)}T==="recovered"&&(_=v[0],T="compact",v=v.subarray(1));let U=h.signature/2,R=v.subarray(0,U),N=v.subarray(U,U*2);return new I(a.fromBytes(R),a.fromBytes(N),_)}static fromHex(v,T){return this.fromBytes(Ft(v),T)}assertRecovery(){let{recovery:v}=this;if(v==null)throw new Error("invalid recovery id: must be present");return v}addRecoveryBit(v){return new I(this.r,this.s,v)}recoverPublicKey(v){let{r:T,s:_}=this,U=this.assertRecovery(),R=U===2||U===3?T+f:T;if(!i.isValid(R))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let N=i.toBytes(R),P=r.fromBytes(W(zc((U&1)===0),N)),z=a.inv(R),k=D(K(v,void 0,"msgHash")),X=a.create(-k*z),J=a.create(_*z),Q=r.BASE.multiplyUnsafe(X).add(P.multiplyUnsafe(J));if(Q.is0())throw new Error("invalid recovery: point at infinify");return Q.assertValidity(),Q}hasHighS(){return p(this.s)}toBytes(v=b.format){if(Ns(v),v==="der")return Ft(xe.hexFromSig(this));let{r:T,s:_}=this,U=a.toBytes(T),R=a.toBytes(_);return v==="recovered"?(g(),W(Uint8Array.of(this.assertRecovery()),U,R)):W(U,R)}toHex(v){return Nt(this.toBytes(v))}}Object.freeze(I.prototype),Object.freeze(I);let L=t.bits2int===void 0?function(v){if(v.length>8192)throw new Error("input is too large");let T=st(v),_=v.length*8-c;return _>0?T>>BigInt(_):T}:t.bits2int,D=t.bits2int_modN===void 0?function(v){return a.create(L(v))}:t.bits2int_modN,S=vr(c);function O(A){return Mt("num < 2^"+c,A,Be,S),a.toBytes(A)}function V(A,v){return K(A,void 0,"message"),v?K(n(A),void 0,"prehashed message"):A}function F(A,v,T){let{lowS:_,prehash:U,extraEntropy:R}=Os(T,b);A=V(A,U);let N=D(A),P=a.fromBytes(v);if(!a.isValidNot0(P))throw new Error("invalid private key");let z=[O(P),O(N)];if(R!=null&&R!==!1){let Q=R===!0?o(h.secretKey):R;z.push(K(Q,void 0,"extraEntropy"))}let k=W(...z),X=N;function J(Q){let Y=L(Q);if(!a.isValidNot0(Y))return;let ae=a.inv(Y),ht=r.BASE.multiply(Y).toAffine(),Wt=a.create(ht.x);if(Wt===Be)return;let zr=a.create(ae*a.create(X+Wt*P));if(zr===Be)return;let fi=(ht.x===Wt?0:2)|Number(ht.y&Je),ui=zr;return _&&p(zr)&&(ui=a.neg(zr),fi^=1),new I(Wt,ui,l?void 0:fi)}return{seed:k,k2sig:J}}function m(A,v,T={}){let{seed:_,k2sig:U}=F(A,v,T);return Za(n.outputLen,a.BYTES,s)(_,U).toBytes(T.format)}function E(A,v,T,_={}){let{lowS:U,prehash:R,format:N}=Os(_,b);if(T=K(T,void 0,"publicKey"),v=V(v,R),!ot(A)){let P=A instanceof I?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+P)}B(A,N);try{let P=I.fromBytes(A,N),z=r.fromBytes(T);if(U&&P.hasHighS())return!1;let{r:k,s:X}=P,J=D(v),Q=a.inv(X),Y=a.create(J*Q),ae=a.create(k*Q),ht=r.BASE.multiplyUnsafe(Y).add(z.multiplyUnsafe(ae));return ht.is0()?!1:a.create(ht.x)===k}catch{return!1}}function C(A,v,T={}){let{prehash:_}=Os(T,b);return v=V(v,_),I.fromBytes(A,"recovered").recoverPublicKey(v).toBytes()}return Object.freeze({keygen:u,getPublicKey:d,getSharedSecret:w,utils:y,lengths:h,Point:r,sign:m,verify:E,recoverPublicKey:C,Signature:I,hash:n})}var ks={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Kl={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Hc=BigInt(2);function zl(r){let e=ks.p,t=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),f=BigInt(88),c=r*r*r%e,u=c*c*r%e,d=q(u,t,e)*u%e,w=q(d,t,e)*u%e,y=q(w,Hc,e)*c%e,h=q(y,o,e)*y%e,b=q(h,s,e)*h%e,l=q(b,a,e)*b%e,p=q(l,f,e)*l%e,x=q(p,a,e)*b%e,g=q(x,t,e)*u%e,B=q(g,i,e)*h%e,I=q(B,n,e)*c%e,L=q(I,Hc,e);if(!Ms.eql(Ms.sqr(L),r))throw new Error("Cannot find square root");return L}var Ms=Pt(ks.p,{sqrt:zl}),Vl=Kc(ks,{Fp:Ms,endo:Kl}),qt=qc(Vl,Ha);function jc(r,e,t,n){let o=No.digest(t instanceof Uint8Array?t:t.subarray());if(En(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),qt.verify(e,s,r,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new Ir(String(s))});try{return n?.signal?.throwIfAborted(),qt.verify(e,o.digest,r,{prehash:!1,format:"der"})}catch(s){throw new Ir(String(s))}}var Rn=class{type="secp256k1";raw;_key;constructor(e){this._key=Zc(e),this.raw=$c(this._key)}toMultihash(){return tt.digest(Rt(this))}toCID(){return ve.createV1(114,this.toMultihash())}toString(){return ne.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ke(this.raw,e.raw)}verify(e,t,n){return jc(this._key,t,e,n)}};function Yc(r){return new Rn(r)}function $c(r){return qt.Point.fromBytes(r).toBytes()}function Zc(r){try{return qt.Point.fromBytes(r),r}catch(e){throw new Yr(String(e))}}function Gc(r){let{Type:e,Data:t}=Ur.decode(r.digest),n=t??new Uint8Array;switch(e){case ie.Ed25519:return vc(n);case ie.secp256k1:return Yc(n);case ie.ECDSA:return Da(n);default:throw new ar}}function Rt(r){return Ur.encode({Type:ie[r.type],Data:r.raw})}var qs={};M(qs,{base58btc:()=>ce,base58flickr:()=>Gl});var Aw=new Uint8Array(0);function Xc(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function Fe(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 Wc(r){return new TextEncoder().encode(r)}function Jc(r){return new TextDecoder().decode(r)}function ql(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(t[i]!==255)throw new TypeError(s+" is ambiguous");t[i]=o}var a=r.length,f=r.charAt(0),c=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function d(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var b=0,l=0,p=0,x=h.length;p!==x&&h[p]===0;)p++,b++;for(var g=(x-p)*u+1>>>0,B=new Uint8Array(g);p!==x;){for(var I=h[p],L=0,D=g-1;(I!==0||L<l)&&D!==-1;D--,L++)I+=256*B[D]>>>0,B[D]=I%a>>>0,I=I/a>>>0;if(I!==0)throw new Error("Non-zero carry");l=L,p++}for(var S=g-l;S!==g&&B[S]===0;)S++;for(var O=f.repeat(b);S<g;++S)O+=r.charAt(B[S]);return O}function w(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;var b=0;if(h[b]!==" "){for(var l=0,p=0;h[b]===f;)l++,b++;for(var x=(h.length-b)*c+1>>>0,g=new Uint8Array(x);h[b];){var B=t[h.charCodeAt(b)];if(B===255)return;for(var I=0,L=x-1;(B!==0||I<p)&&L!==-1;L--,I++)B+=a*g[L]>>>0,g[L]=B%256>>>0,B=B/256>>>0;if(B!==0)throw new Error("Non-zero carry");p=I,b++}if(h[b]!==" "){for(var D=x-p;D!==x&&g[D]===0;)D++;for(var S=new Uint8Array(l+(x-D)),O=l;D!==x;)S[O++]=g[D++];return S}}}function y(h){var b=w(h);if(b)return b;throw new Error(`Non-${e} character`)}return{encode:d,decodeUnsafe:w,decode:y}}var Hl=ql,jl=Hl,ef=jl;var Ps=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Ks=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let o=t.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return tf(this,e)}},zs=class{decoders;constructor(e){this.decoders=e}or(e){return tf(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function tf(r,e){return new zs({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Vs=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new Ps(e,t,n),this.decoder=new Ks(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Ht({name:r,prefix:e,encode:t,decode:n}){return new Vs(r,e,t,n)}function Qe({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=ef(t,r);return Ht({prefix:e,name:r,encode:n,decode:s=>Fe(o(s))})}function $l(r,e,t,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*t/8|0),i=0,a=0,f=0;for(let c=0;c<o;++c){let u=e[r[c]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|u,i+=t,i>=8&&(i-=8,s[f++]=255&a>>i)}if(i>=t||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Zl(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,a=0;for(let f=0;f<r.length;++f)for(a=a<<8|r[f],i+=8;i>t;)i-=t,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<t-i]),n)for(;(s.length*t&7)!==0;)s+="=";return s}function Yl(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}function Z({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let o=Yl(n);return Ht({prefix:e,name:r,encode(s){return Zl(s,n,t)},decode(s){return $l(s,o,t,r)}})}var ce=Qe({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Gl=Qe({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Hs={};M(Hs,{base32:()=>jt,base32hex:()=>Ql,base32hexpad:()=>tp,base32hexpadupper:()=>rp,base32hexupper:()=>ep,base32pad:()=>Wl,base32padupper:()=>Jl,base32upper:()=>Xl,base32z:()=>np});var jt=Z({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Xl=Z({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Wl=Z({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Jl=Z({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ql=Z({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),ep=Z({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),tp=Z({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),rp=Z({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),np=Z({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var js={};M(js,{base36:()=>_r,base36upper:()=>op});var _r=Qe({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),op=Qe({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var sp=of,rf=128,ip=127,ap=~ip,cp=Math.pow(2,31);function of(r,e,t){e=e||[],t=t||0;for(var n=t;r>=cp;)e[t++]=r&255|rf,r/=128;for(;r≈)e[t++]=r&255|rf,r>>>=7;return e[t]=r|0,of.bytes=t-n+1,e}var fp=$s,up=128,nf=127;function $s(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw $s.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&nf)<<o:(i&nf)*Math.pow(2,o),o+=7}while(i>=up);return $s.bytes=s-n,t}var hp=Math.pow(2,7),dp=Math.pow(2,14),lp=Math.pow(2,21),pp=Math.pow(2,28),mp=Math.pow(2,35),bp=Math.pow(2,42),yp=Math.pow(2,49),xp=Math.pow(2,56),gp=Math.pow(2,63),wp=function(r){return r<hp?1:r<dp?2:r<lp?3:r<pp?4:r<mp?5:r<bp?6:r<yp?7:r<xp?8:r<gp?9:10},Ep={encode:sp,decode:fp,encodingLength:wp},vp=Ep,Rr=vp;function Or(r,e=0){return[Rr.decode(r,e),Rr.decode.bytes]}function $t(r,e,t=0){return Rr.encode(r,e,t),e}function Zt(r){return Rr.encodingLength(r)}function Gt(r,e){let t=e.byteLength,n=Zt(r),o=n+Zt(t),s=new Uint8Array(o+t);return $t(r,s,0),$t(t,s,n),s.set(e,o),new Yt(r,t,e,s)}function Nr(r){let e=Fe(r),[t,n]=Or(e),[o,s]=Or(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Yt(t,o,i,e)}function sf(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Xc(r.bytes,t.bytes)}}var Yt=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function af(r,e){let{bytes:t,version:n}=r;return n===0?Ap(t,Zs(r),e??ce.encoder):Bp(t,Zs(r),e??jt.encoder)}var cf=new WeakMap;function Zs(r){let e=cf.get(r);if(e==null){let t=new Map;return cf.set(r,t),t}return e}var Me=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,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:e,multihash:t}=this;if(e!==Fr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Ip)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}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:e,digest:t}=this.multihash,n=Gt(e,t);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(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&sf(e.multihash,n.multihash)}toString(e){return af(this,e)}toJSON(){return{"/":af(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:s,bytes:i}=t;return new r(n,o,s,i??ff(n,o,s.bytes))}else if(t[Dp]===!0){let{version:n,multihash:o,code:s}=t,i=Nr(o);return r.create(n,s,i)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==Fr)throw new Error(`Version 0 CID must use dag-pb (code: ${Fr}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=ff(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Fr,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=Fe(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let s=o.subarray(t.multihashSize-t.digestSize),i=new Yt(t.multihashCode,t.digestSize,s,o);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[d,w]=Or(e.subarray(t));return t+=w,d},o=n(),s=Fr;if(o===18?(o=0,t=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=t,a=n(),f=n(),c=t+f,u=c-i;return{version:o,codec:s,multihashCode:a,digestSize:f,multihashSize:u,size:c}}static parse(e,t){let[n,o]=Sp(e,t),s=r.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Zs(s).set(n,e),s}};function Sp(r,e){switch(r[0]){case"Q":{let t=e??ce;return[ce.prefix,t.decode(`${ce.prefix}${r}`)]}case ce.prefix:{let t=e??ce;return[ce.prefix,t.decode(r)]}case jt.prefix:{let t=e??jt;return[jt.prefix,t.decode(r)]}case _r.prefix:{let t=e??_r;return[_r.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function Ap(r,e,t){let{prefix:n}=t;if(n!==ce.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let s=t.encode(r).slice(1);return e.set(n,s),s}else return o}function Bp(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let s=t.encode(r);return e.set(n,s),s}else return o}var Fr=112,Ip=18;function ff(r,e,t){let n=Zt(r),o=n+Zt(e),s=new Uint8Array(o+t.byteLength);return $t(r,s,0),$t(e,s,n),s.set(t,o),s}var Dp=Symbol.for("@ipld/js-cid/CID");var Ys={};M(Ys,{identity:()=>Mr});var uf=0,Cp="identity",hf=Fe;function Tp(r,e){if(e?.truncate!=null&&e.truncate!==r.byteLength){if(e.truncate<0||e.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e.truncate)}return Gt(uf,hf(r))}var Mr={code:uf,name:Cp,encode:hf,digest:Tp};var Js={};M(Js,{sha256:()=>Ws,sha512:()=>Up});var Lp=20;function Xs({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:o}){return new Gs(r,e,t,n,o)}var Gs=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,o,s){this.name=e,this.code=t,this.encode=n,this.minDigestLength=o??Lp,this.maxDigestLength=s}digest(e,t){if(t?.truncate!=null){if(t.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&t.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?df(n,this.code,t?.truncate):n.then(o=>df(o,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function df(r,e,t){if(t!=null&&t!==r.byteLength){if(t>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t)}return Gt(e,r)}function pf(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var Ws=Xs({name:"sha2-256",code:18,encode:pf("SHA-256")}),Up=Xs({name:"sha2-512",code:19,encode:pf("SHA-512")});var Qs={};M(Qs,{base10:()=>_p});var _p=Qe({prefix:"9",name:"base10",alphabet:"0123456789"});var ei={};M(ei,{base16:()=>Rp,base16upper:()=>Op});var Rp=Z({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Op=Z({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ti={};M(ti,{base2:()=>Np});var Np=Z({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ri={};M(ri,{base256emoji:()=>Kp});var mf=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}"),Fp=mf.reduce((r,e,t)=>(r[t]=e,r),[]),Mp=mf.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function kp(r){return r.reduce((e,t)=>(e+=Fp[t],e),"")}function Pp(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=Mp[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var Kp=Ht({prefix:"\u{1F680}",name:"base256emoji",encode:kp,decode:Pp});var ni={};M(ni,{base64:()=>zp,base64pad:()=>Vp,base64url:()=>qp,base64urlpad:()=>Hp});var zp=Z({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Vp=Z({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),qp=Z({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Hp=Z({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var oi={};M(oi,{base8:()=>jp});var jp=Z({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var si={};M(si,{identity:()=>$p});var $p=Ht({prefix:"\0",name:"identity",encode:r=>Jc(r),decode:r=>Wc(r)});var Ww=new TextEncoder,Jw=new TextDecoder;var ii={...si,...ti,...oi,...Qs,...ei,...Hs,...js,...qs,...ni,...ri},f2={...Js,...Ys};function bf(r=0){return new Uint8Array(r)}function xf(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var yf=xf("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),ai=xf("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=bf(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Gp={utf8:yf,"utf-8":yf,hex:ii.base16,latin1:ai,ascii:ai,binary:ai,...ii},Nn=Gp;function kr(r,e="utf8"){let t=Nn[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}function ci(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function gf(r,e="utf8"){let t=Nn[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}var wf=Symbol.for("nodejs.util.inspect.custom"),Xp=114,Pr=class{type;multihash;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[mo]=!0;toString(){return this.string==null&&(this.string=ce.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return Me.createV1(Xp,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return ci(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return ci(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[wf](){return`PeerId(${this.toString()})`}},Fn=class extends Pr{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Mn=class extends Pr{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},kn=class extends Pr{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},Wp=2336,Kr=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=Mr.digest(gf(this.url))}[wf](){return`PeerId(${this.url})`}[mo]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return Me.createV1(Wp,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=kr(e)),e.toString()===this.toString())}};var Jp=114,Ef=2336;function vf(r,e){let t;if(r.charAt(0)==="1"||r.charAt(0)==="Q")t=Nr(ce.decode(`z${r}`));else{if(r.startsWith("k51qzi5uqu5")||r.startsWith("kzwfwjn5ji4")||r.startsWith("k2k4r8")||r.startsWith("bafz"))return Qp(Me.parse(r));if(e==null)throw new Ee('Please pass a multibase decoder for strings that do not start with "1" or "Q"');t=Nr(e.decode(r))}return Sf(t)}function Sf(r){if(t0(r))return new Fn({multihash:r});if(e0(r))try{let e=Gc(r);if(e.type==="Ed25519")return new Mn({multihash:r,publicKey:e});if(e.type==="secp256k1")return new kn({multihash:r,publicKey:e})}catch{let t=kr(r.digest);return new Kr(new URL(t))}throw new Xr("Supplied PeerID Multihash is invalid")}function Qp(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==Jp&&r.code!==Ef)throw new Gr("Supplied PeerID CID is invalid");if(r.code===Ef){let e=kr(r.multihash.digest);return new Kr(new URL(e))}return Sf(r.multihash)}function e0(r){return r.code===Mr.code}function t0(r){return r.code===Ws.code}var Af=(r,e)=>{let[,t,n,...o]=r.split("/");if(t!=="ipns")throw new gt(`Namespace ${t} was not "ipns"`);try{return{namespace:"ipns",peerId:vf(n),path:o.length>0?`/${o.join("/")}`:"",answer:e}}catch{return{namespace:"dnslink",value:n,path:o.length>0?`/${o.join("/")}`:"",answer:e}}};var Pn=class{dns;log;namespaces;cache;cacheMaxAnswers;constructor(e,t={}){this.dns=e.dns,this.log=e.logger.forComponent("helia:dnslink"),this.namespaces={ipfs:Ji,ipns:Af,...t.namespaces},this.cache=new xt({maxSize:t.cacheSize??1e3,maxAge:t.cacheMaxAge??3e4}),this.cacheMaxAnswers=t.cacheMaxAnswers??10}async resolve(e,t={}){if(t.nocache!==!0){let i=this.cache.get(e);if(i!=null){let a=[...i.values()];if(a.length>0)return a}}let n=await this.recursiveResolveDomain(e,t.maxRecursiveDepth??Mi,t),o=new xt({maxSize:this.cacheMaxAnswers});n.forEach((i,a)=>{o.set(a,i,{maxAge:i.answer.TTL*1e3})});let s=n.reduce((i,a)=>{let f=a.answer.TTL*1e3;return f>i?f:i},0);return this.cache.maxAge<s&&(s=this.cache.maxAge),this.cache.set(e,o,{maxAge:s}),n}async recursiveResolveDomain(e,t,n={}){if(t===0)throw new Error("recursion limit exceeded");e.startsWith("_dnslink.")||(e=`_dnslink.${e}`);try{return await this.recursiveResolveDnslink(e,t,n)}catch(o){if(o.code!=="ENOTFOUND"&&o.code!=="ENODATA"&&o.name!=="DNSLinkNotFoundError"&&o.name!=="NotFoundError")throw o;return e.startsWith("_dnslink.")?e=e.replace("_dnslink.",""):e=`_dnslink.${e}`,this.recursiveResolveDnslink(e,t,n)}}async recursiveResolveDnslink(e,t,n={}){if(t===0)throw new Error("recursion limit exceeded");this.log("query %s for TXT and CNAME records",e);let s=((await this.dns.query(e,{...n,types:[Ie.TXT]}))?.Answer??[]).sort((c,u)=>c.data.localeCompare(u.data));this.log("found %d TXT records for %s",s.length,e);let i=[];for(let c of s)try{let u=c.data;if(u.startsWith('"')&&u.endsWith('"')&&(u=u.substring(1,u.length-1)),!u.startsWith("dnslink="))continue;this.log("%s TXT %s",c.name,u),u=u.replace("dnslink=","");let[,d,w]=u.split("/");if(d==="dnslink"){i.push(...await this.recursiveResolveDomain(w,t-1,n));continue}let y=this.namespaces[d];if(y==null){this.log('unknown protocol "%s" in DNSLink record for domain: %s',d,e);continue}let h=y(u,c);if(h.namespace==="dnslink"){i.push(...await this.recursiveResolveDomain(h.value,t-1,n));continue}i.push(y(u,c))}catch(u){this.log.error("could not parse DNS link record for domain %s, %s - %e",e,c.data,u)}if(i.length>0)return i;this.log("no DNSLink records found for %s, falling back to CNAME",e);let f=((await this.dns.query(e,{...n,types:[Ie.CNAME]}))?.Answer??[]).sort((c,u)=>c.data.localeCompare(u.data));this.log("found %d CNAME records for %s",f.length,e);for(let c of f)try{return await this.recursiveResolveDomain(c.data,t-1,n)}catch(u){this.log.error("domain %s cname %s had no DNSLink records - %e",e,c.data,u)}throw new jr(`No DNSLink records found for domain: ${e}`)}};function r0(r,e={}){return new Pn(r,e)}return _f(n0);})();
|
|
2
|
+
"use strict";var HeliaDnslink=(()=>{var vi=Object.create;var Je=Object.defineProperty;var Bi=Object.getOwnPropertyDescriptor;var Ti=Object.getOwnPropertyNames;var Ii=Object.getPrototypeOf,_i=Object.prototype.hasOwnProperty;var Di=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),ct=(r,t)=>{for(var e in t)Je(r,e,{get:t[e],enumerable:!0})},bo=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ti(t))!_i.call(r,o)&&o!==e&&Je(r,o,{get:()=>t[o],enumerable:!(n=Bi(t,o))||n.enumerable});return r};var Li=(r,t,e)=>(e=r!=null?vi(Ii(r)):{},bo(t||!r||!r.__esModule?Je(e,"default",{value:r,enumerable:!0}):e,r)),Ri=r=>bo(Je({},"__esModule",{value:!0}),r);var Mo=Di((Au,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 df={};ct(df,{dnsLink:()=>lf});var Yr={};ct(Yr,{base10:()=>Pi});var xf=new Uint8Array(0);function go(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 jt(r);if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return jt(new Uint8Array(r.buffer,r.byteOffset,r.byteLength));throw new Error("Unknown type, must be binary type")}function xo(r){return new TextEncoder().encode(r)}function wo(r){return new TextDecoder().decode(r)}function Ci(r){return r?.buffer instanceof ArrayBuffer}function jt(r){return Ci(r)?r:r.slice()}function Oi(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 Fi=Oi,Ui=Fi,So=Ui;var zr=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")}},jr=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 Ao(this,t)}},Zr=class{decoders;constructor(t){this.decoders=t}or(t){return Ao(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 Ao(r,t){return new Zr({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var $r=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 zr(t,e,n),this.decoder=new jr(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function re({name:r,prefix:t,encode:e,decode:n}){return new $r(r,t,e,n)}function Ct({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=So(e,r);return re({prefix:t,name:r,encode:n,decode:s=>Bt(o(s))})}function Ni(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 Ki(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 ki(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=ki(n);return re({prefix:t,name:r,encode(s){return Ki(s,n,e)},decode(s){return Ni(s,o,e,r)}})}var Pi=Ct({prefix:"9",name:"base10",alphabet:"0123456789"});var Gr={};ct(Gr,{base16:()=>Mi,base16upper:()=>Hi});var Mi=V({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Hi=V({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Xr={};ct(Xr,{base2:()=>qi});var qi=V({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Wr={};ct(Wr,{base256emoji:()=>$i});var vo=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}"),Vi=vo.reduce((r,t,e)=>(r[e]=t,r),[]),zi=vo.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function ji(r){return r.reduce((t,e)=>(t+=Vi[e],t),"")}function Zi(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=zi[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var $i=re({prefix:"\u{1F680}",name:"base256emoji",encode:ji,decode:Zi});var Qr={};ct(Qr,{base32:()=>ne,base32hex:()=>Wi,base32hexpad:()=>Ji,base32hexpadupper:()=>tc,base32hexupper:()=>Qi,base32pad:()=>Gi,base32padupper:()=>Xi,base32upper:()=>Yi,base32z:()=>ec});var ne=V({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Yi=V({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Gi=V({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Xi=V({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Wi=V({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Qi=V({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ji=V({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),tc=V({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ec=V({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Jr={};ct(Jr,{base36:()=>ve,base36upper:()=>rc});var ve=Ct({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),rc=Ct({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var tn={};ct(tn,{base58btc:()=>$,base58flickr:()=>nc});var $=Ct({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),nc=Ct({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var en={};ct(en,{base64:()=>oc,base64pad:()=>sc,base64url:()=>ic,base64urlpad:()=>cc});var oc=V({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),sc=V({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),ic=V({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),cc=V({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var rn={};ct(rn,{base8:()=>ac});var ac=V({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var nn={};ct(nn,{identity:()=>fc});var fc=re({prefix:"\0",name:"identity",encode:r=>wo(r),decode:r=>xo(r)});var Uf=new TextEncoder,Nf=new TextDecoder;var sn={};ct(sn,{identity:()=>lt});var lc=Io,Bo=128,dc=127,pc=~dc,mc=Math.pow(2,31);function Io(r,t,e){t=t||[],e=e||0;for(var n=e;r>=mc;)t[e++]=r&255|Bo,r/=128;for(;r&pc;)t[e++]=r&255|Bo,r>>>=7;return t[e]=r|0,Io.bytes=e-n+1,t}var yc=on,bc=128,To=127;function on(r,n){var e=0,n=n||0,o=0,s=n,i,c=r.length;do{if(s>=c)throw on.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>=bc);return on.bytes=s-n,e}var gc=Math.pow(2,7),xc=Math.pow(2,14),wc=Math.pow(2,21),Ec=Math.pow(2,28),Sc=Math.pow(2,35),Ac=Math.pow(2,42),vc=Math.pow(2,49),Bc=Math.pow(2,56),Tc=Math.pow(2,63),Ic=function(r){return r<gc?1:r<xc?2:r<wc?3:r<Ec?4:r<Sc?5:r<Ac?6:r<vc?7:r<Bc?8:r<Tc?9:10},_c={encode:lc,decode:yc,encodingLength:Ic},Dc=_c,Be=Dc;function Te(r,t=0){return[Be.decode(r,t),Be.decode.bytes]}function oe(r,t,e=0){return Be.encode(r,t,e),t}function se(r){return Be.encodingLength(r)}function ce(r,t){let e=t.byteLength,n=se(r),o=n+se(e),s=new Uint8Array(o+e);return oe(r,s,0),oe(e,s,n),s.set(t,o),new ie(r,e,t,s)}function Ie(r){let t=Bt(r),[e,n]=Te(t),[o,s]=Te(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new ie(e,o,i,t)}function _o(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&go(r.bytes,e.bytes)}}var ie=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=jt(n),this.bytes=jt(o)}};var Do=0,Lc="identity",Lo=Bt;function Rc(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 ce(Do,Lo(r))}var lt={code:Do,name:Lc,encode:Lo,digest:Rc};var fn={};ct(fn,{sha256:()=>_e,sha512:()=>Oc});var Cc=20;function an({name:r,code:t,encode:e,minDigestLength:n,maxDigestLength:o}){return new cn(r,t,e,n,o)}var cn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,e,n,o,s){this.name=t,this.code=e,this.encode=n,this.minDigestLength=o??Cc,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?Ro(n,this.code,e?.truncate):n.then(o=>Ro(o,this.code,e?.truncate))}else throw Error("Unknown type, must be binary type")}};function Ro(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 ce(t,r)}function Oo(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var _e=an({name:"sha2-256",code:18,encode:Oo("SHA-256")}),Oc=an({name:"sha2-512",code:19,encode:Oo("SHA-512")});function Fo(r,t){let{bytes:e,version:n}=r;return n===0?Uc(e,un(r),t??$.encoder):Nc(e,un(r),t??ne.encoder)}var Uo=new WeakMap;function un(r){let t=Uo.get(r);if(t==null){let e=new Map;return Uo.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=jt(o),this["/"]=this.bytes}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!==De)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Kc)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=ce(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&&_o(t.multihash,n.multihash)}toString(t){return Fo(this,t)}toJSON(){return{"/":Fo(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??No(n,o,s.bytes))}else if(e[kc]===!0){let{version:n,multihash:o,code:s}=e,i=Ie(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!==De)throw new Error(`Version 0 CID must use dag-pb (code: ${De}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=No(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,De,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 ie(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]=Te(t.subarray(e));return e+=w,h},o=n(),s=De;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]=Fc(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 un(s).set(n,t),s}};function Fc(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 ne.prefix:{let e=t??ne;return[ne.prefix,e.decode(r)]}case ve.prefix:{let e=t??ve;return[ve.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 Uc(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 Nc(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 De=112,Kc=18;function No(r,t,e){let n=se(r),o=n+se(t),s=new Uint8Array(o+e.byteLength);return oe(r,s,0),oe(t,s,n),s.set(e,o),s}var kc=Symbol.for("@ipld/js-cid/CID");var hn={...nn,...Xr,...rn,...Yr,...Gr,...Qr,...Jr,...tn,...en,...Wr},ou={...fn,...sn};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 Ko=ko("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),ln=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}),Pc={utf8:Ko,"utf-8":Ko,hex:hn.base16,latin1:ln,ascii:ln,binary:ln,...hn},er=Pc;function it(r,t="utf8"){let e=er[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Vc=Li(Mo(),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 Ho=32;var fe=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 rr=class extends Error{static name="DNSLinkNotFoundError";constructor(t="DNSLink not found"){super(t),this.name="DNSLinkNotFoundError"}},ue=class extends Error{static name="InvalidNamespaceError";constructor(t="Invalid namespace"){super(t),this.name="InvalidNamespaceError"}};var qo=(r,t)=>{let[,e,n,...o]=r.split("/");if(e!=="ipfs")throw new ue(`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"}},nr=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var or=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},sr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Le=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var dn=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}async function Vo(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}function zc(r){return r?.buffer instanceof ArrayBuffer}function zo(r){if(zc(r))return r;let t=r.slice();return new Uint8Array(t.buffer,0,t.byteLength)}function ir(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 zo(e)}var Zo=Symbol.for("@achingbrain/uint8arraylist");function jo(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 cr(r){return!!r?.[Zo]}var ft=class r{bufs;length;[Zo]=!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(cr(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(cr(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=jo(this.bufs,t);return e.buf[e.index]}set(t,e){let n=jo(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(cr(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 ir(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:ir(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(!cr(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=er[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}var jc=parseInt("11111",2),pn=parseInt("10000000",2),Zc=parseInt("01111111",2),$o={0:Re,1:Re,2:$c,3:Xc,4:Wc,5:Gc,6:Yc,16:Re,22:Re,48:Re};function mn(r,t={offset:0}){let e=r[t.offset]&jc;if(t.offset++,$o[e]!=null)return $o[e](r,t);throw new Error("No decoder for tag "+e)}function Ce(r,t){let e=0;if((r[t.offset]&pn)===pn){let n=r[t.offset]&Zc,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 Re(r,t){Ce(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=mn(r,t);if(n===null)break;e.push(n)}return e}function $c(r,t){let e=Ce(r,t),n=t.offset,o=t.offset+e,s=[];for(let i=n;i<o;i++)i===n&&r[i]===0||s.push(r[i]);return t.offset+=e,Uint8Array.from(s)}function Yc(r,t){let e=Ce(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 Gc(r,t){return t.offset++,null}function Xc(r,t){let e=Ce(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=Ce(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function Qc(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 yn(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=Qc(r.byteLength);return new ft(Uint8Array.from([t.byteLength|pn]),t)}function Yo(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]),yn(t),t)}function Go(r){let t=Uint8Array.from([0]),e=new ft(t,r);return new ft(Uint8Array.from([3]),yn(e),e)}function ar(r,t=48){let e=new ft;for(let n of r)e.append(n);return new ft(Uint8Array.from([t]),yn(e),e)}var Jc=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),ta=Uint8Array.from([6,5,43,129,4,0,34]),ea=Uint8Array.from([6,5,43,129,4,0,35]),ra={ext:!0,kty:"EC",crv:"P-256"},na={ext:!0,kty:"EC",crv:"P-384"},oa={ext:!0,kty:"EC",crv:"P-521"},bn=32,gn=48,xn=66;function Xo(r){let t=mn(r);return Wo(t)}function Wo(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===bn*2+1)return n=it(t.subarray(e,e+bn),"base64url"),o=it(t.subarray(e+bn),"base64url"),new he({...ra,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 he({...na,key_ops:["verify"],x:n,y:o});if(t.byteLength===xn*2+1)return n=it(t.subarray(e,e+xn),"base64url"),o=it(t.subarray(e+xn),"base64url"),new he({...oa,key_ops:["verify"],x:n,y:o});throw new wt(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Qo(r){return ar([Yo(Uint8Array.from([1])),ar([sa(r.crv)],160),ar([Go(new ft(Uint8Array.from([4]),Ot(r.x??"","base64url"),Ot(r.y??"","base64url")))],161)]).subarray()}function sa(r){if(r==="P-256")return Jc;if(r==="P-384")return ta;if(r==="P-521")return ea;throw new wt(`Invalid curve ${r}`)}var he=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Qo(this.jwk)),this._raw}toMultihash(){return lt.digest(le(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 Vo(this.jwk,e,t,n)}};function wn(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=wn(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 fr(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 de(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 ur(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 hr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function pt(r,t){return r<<32-t|r>>>t}var ts=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",ia=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function lr(r){if(ut(r),ts)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=ia[r[e]];return t}var It={_0:48,_9:57,A:65,F:70,a:97,f:102};function Jo(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 Oe(r){if(typeof r!="string")throw new TypeError("hex string expected, got "+typeof r);if(ts)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=Jo(r.charCodeAt(s)),c=Jo(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 En(...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 Sn(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 es(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 An=r=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,r])});function rs(r,t,e){return r&t^~r&e}function ns(r,t,e){return r&t^r&e^t&e}var Fe=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=hr(this.buffer)}update(t){de(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=hr(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){de(this),ur(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=hr(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 dr=BigInt(4294967295),os=BigInt(32);function ca(r,t=!1){return t?{h:Number(r&dr),l:Number(r>>os&dr)}:{h:Number(r>>os&dr)|0,l:Number(r&dr)|0}}function ss(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}=ca(r[s],t);[n[s],o[s]]=[i,c]}return[n,o]}var vn=(r,t,e)=>r>>>e,Bn=(r,t,e)=>r<<32-e|t>>>e,Zt=(r,t,e)=>r>>>e|t<<32-e,$t=(r,t,e)=>r<<32-e|t>>>e,Ue=(r,t,e)=>r<<64-e|t>>>e-32,Ne=(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 is=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),cs=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,as=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),fs=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,us=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),hs=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var fa=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),Tn=class extends Fe{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+rs(c,f,a)+fa[h]+Ut[h]|0,S=(pt(n,2)^pt(n,13)^pt(n,22))+ns(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)}},In=class extends Tn{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 ls=ss(["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))),ua=ls[0],ha=ls[1],Nt=new Uint32Array(80),Kt=new Uint32Array(80),_n=class extends Fe{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=Zt(R,D,1)^Zt(R,D,8)^vn(R,D,7),C=$t(R,D,1)^$t(R,D,8)^Bn(R,D,7),I=Nt[B-2]|0,U=Kt[B-2]|0,H=Zt(I,U,19)^Ue(I,U,61)^vn(I,U,6),N=$t(I,U,19)^Ne(I,U,61)^Bn(I,U,6),l=as(C,N,Kt[B-7],Kt[B-16]),m=fs(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=Zt(h,w,14)^Zt(h,w,18)^Ue(h,w,41),D=$t(h,w,14)^$t(h,w,18)^Ne(h,w,41),F=h&p^~h&S,C=w&b^~w&d,I=us(A,D,C,ha[B],Kt[B]),U=hs(I,x,R,F,ua[B],Nt[B]),H=I|0,N=Zt(n,o,28)^Ue(n,o,34)^Ue(n,o,39),l=$t(n,o,28)^Ne(n,o,34)^Ne(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=is(H,l,E);n=cs(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)}},Dn=class extends _n{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 ds=Sn(()=>new In,An(1));var pr=Sn(()=>new Dn,An(3));var P=(r,t,e)=>ut(r,t,e),Rn=Ft,pe=lr,G=(...r)=>En(...r),me=r=>Oe(r),Yt=wn,Ke=r=>es(r),yr=BigInt(0),Ln=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 br(r){if(typeof r=="bigint"){if(!mr(r))throw new RangeError("positive bigint expected, got "+r)}else Rn(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=br(r).toString(16);return t.length&1?"0"+t:t}function ps(r){if(typeof r!="string")throw new TypeError("hex string expected, got "+typeof r);return r===""?yr:BigInt("0x"+r)}function Gt(r){return ps(lr(r))}function St(r){return ps(lr(Pe(ut(r)).reverse()))}function gr(r,t){if(Ft(t),t===0)throw new RangeError("zero length");r=br(r);let e=r.toString(16);if(e.length>t*2)throw new RangeError("number too large");return Oe(e.padStart(t*2,"0"))}function Cn(r,t){return gr(r,t).reverse()}function ms(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 Pe(r){return Uint8Array.from(P(r))}function xr(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 mr=r=>typeof r=="bigint"&&yr<=r;function la(r,t,e){return mr(r)&&mr(t)&&mr(e)&&t<=r&&r<e}function ye(r,t,e,n){if(!la(t,e,n))throw new RangeError("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function be(r){if(r<yr)throw new Error("expected non-negative bigint, got "+r);let t;for(t=0;r>yr;r>>=Ln,t+=1);return t}var Me=r=>(Ln<<BigInt(r))-Ln;function ys(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 On=()=>{throw new Error("not implemented")};var et=BigInt(0),z=BigInt(1),Xt=BigInt(2),ws=BigInt(3),Es=BigInt(4),Ss=BigInt(5),da=BigInt(7),As=BigInt(8),pa=BigInt(9),vs=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 bs(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 Fn(r,t,e){let n=r;if(!n.eql(n.sqr(t),e))throw new Error("Cannot find square root")}function Bs(r,t){let e=r,n=(e.ORDER+z)/Es,o=e.pow(t,n);return Fn(e,o,t),o}function ma(r,t){let e=r,n=(e.ORDER-Ss)/As,o=e.mul(t,Xt),s=e.pow(o,n),i=e.mul(t,s),c=e.mul(e.mul(i,Xt),s),f=e.mul(i,e.sub(c,e.ONE));return Fn(e,f,t),f}function ya(r){let t=ge(r),e=Ts(r),n=e(t,t.neg(t.ONE)),o=e(t,n),s=e(t,t.neg(n)),i=(r+da)/vs;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 Fn(a,x,f),x})}function Ts(r){if(r<ws)throw new Error("sqrt is not defined for small field");let t=r-z,e=0;for(;t%Xt===et;)t/=Xt,e++;let n=Xt,o=ge(r);for(;gs(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return Bs;let s=o.pow(n,t),i=(t+z)/Xt;return function(f,a){let u=f;if(u.is0(a))return a;if(gs(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 ba(r){return r%Es===ws?Bs:r%As===Ss?ma:r%vs===pa?ya(r):Ts(r)}var Lt=(r,t)=>(Z(r,t)&z)===z,ga=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Un(r){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},e=ga.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 xa(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 He(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 gs(r,t){let e=r,n=(e.ORDER-z)/Xt,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 wa(r,t){if(t!==void 0&&Rn(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=be(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 xs=new WeakMap,wr=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}=wa(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 xa(this,t,e)}div(t,e){return Z(t*bs(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 bs(t,this.ORDER)}sqrt(t){let e=xs.get(this);return e||xs.set(this,e=ba(this.ORDER)),e(this,t)}toBytes(t){return this.isLE?Cn(t,this.BYTES):gr(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):Gt(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 He(this,t)}cmov(t,e,n){return mt(n,"condition"),n?e:t}};Object.freeze(wr.prototype);function ge(r,t={}){return new wr(r,t)}function Is(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=be(r-z);return Math.ceil(t/8)}function Nn(r){let t=Is(r);return t+Math.ceil(t/2)}function Kn(r,t,e=!1){P(r);let n=r.length,o=Is(t),s=Math.max(Nn(t),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?St(r):Gt(r),c=Z(i,t-z)+z;return e?Cn(c,o):gr(c,o)}var xe=BigInt(0),Wt=BigInt(1);function qe(r,t){let e=t.negate();return r?e:t}function Qt(r,t){let e=He(r.Fp,t.map(n=>n.Z));return t.map((n,o)=>r.fromAffine(n.toAffine(e[o])))}function Rs(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){Rs(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=Me(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function _s(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+=Wt);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 Pn=new WeakMap,Cs=new WeakMap;function Mn(r){return Cs.get(r)||1}function Ds(r){if(r!==xe)throw new Error("invalid wNAF")}var we=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>xe;)e&Wt&&(n=n.add(o)),o=o.double(),e>>=Wt;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}=_s(n,c,i);n=f,u?s=s.add(qe(w,e[p])):o=o.add(qe(h,e[a]))}return Ds(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!==xe;i++){let{nextN:c,offset:f,isZero:a,isNeg:u}=_s(n,i,s);if(n=c,!a){let h=e[f];o=o.add(u?h.negate():h)}}return Ds(n),o}getPrecomputes(t,e,n){let o=Pn.get(e);return o||(o=this.precomputeWindow(e,t),t!==1&&(typeof n=="function"&&(o=n(o)),Pn.set(e,o))),o}cached(t,e,n){let o=Mn(t);return this.wNAF(o,this.getPrecomputes(o,t,n),e)}unsafe(t,e,n,o){let s=Mn(t);return s===1?this._unsafeLadder(t,e,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),e,o)}createCache(t,e){Rs(e,this.bits),Cs.set(t,e),Pn.delete(t)}hasCache(t){return Mn(t)!==1}};function Os(r,t,e,n){let o=t,s=r.ZERO,i=r.ZERO;for(;e>xe||n>xe;)e&Wt&&(s=s.add(o)),n&Wt&&(i=i.add(o)),o=o.double(),e>>=Wt,n>>=Wt;return{p1:s,p2:i}}function Ls(r,t,e){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Un(t),t}else return ge(r,{isLE:e})}function Er(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>xe))throw new Error(`CURVE.${f} must be positive bigint`)}let o=Ls(t.p,e.Fp,n),s=Ls(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 Sr(r,t){return function(n){let o=r(n);return{secretKey:o,publicKey:t(o)}}}var kt=BigInt(0),Q=BigInt(1),Hn=BigInt(2),Ea=BigInt(8);function Sa(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 Fs(r,t={}){let e=t,n=Er("edwards",r,e,e.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:c}=i;bt(e,{},{uvRatio:"function"});let f=Hn<<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(!Sa(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 ye("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=Pe(P(d,A,"point")),mt(x,"zip215");let D=Pe(d),F=d[A-1];D[A-1]=F&-129;let C=St(D),I=x?f:o.ORDER;ye("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(me(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(Hn),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(Hn*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=>Qt(p,B));return Qt(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=>Qt(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?Ea: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 pe(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let b=new we(p,s.BITS);return s.BITS>=8&&p.BASE.precompute(8),Object.freeze(p.prototype),Object.freeze(p),p}var Ar=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(t){this.ep=t}static fromBytes(t){On()}static fromHex(t){On()}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 pe(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 Us(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?Ke: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 Yt(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:Sr(I,x),getPublicKey:x,sign:B,verify:D,utils:N,Point:r,lengths:C})}function Ve(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 Aa(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 va(r){if(!Yt(r)&&typeof r!="string")throw new Error("DST must be Uint8Array or ascii string");let t=typeof r=="string"?xr(r):r;if(t.length===0)throw new Error("DST must be non-empty");return t}function qn(r,t,e,n){P(r),yt(e),t=va(t),t.length>255&&(t=n(G(xr("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,Ve(t.length,1)),f=new Uint8Array(s),a=Ve(e,2),u=new Array(i),h=n(G(f,r,a,Ve(0,1),c));u[0]=n(G(h,Ve(1,1),c));for(let p=1;p<i;p++){let b=[Aa(h,u[p-1]),Ve(p+1,1),c];u[p]=n(G(...b))}return G(...u).slice(0,e)}var Ns="HashToScalar-";var Ba=BigInt(0),Rt=BigInt(1),Ks=BigInt(2);var Ta=BigInt(5),Ia=BigInt(8),Ee=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Zn={p:Ee,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Ia,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function _a(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=Ee,c=r*r%s*r%s,f=q(c,Ks,s)*c%s,a=q(f,Rt,s)*r%s,u=q(a,Ta,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,Ks,s)*r%s,b2:c}}function Da(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var Vn=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function $n(r,t){let e=Ee,n=Z(t*t*t,e),o=Z(n*n*t,e),s=_a(r*o).pow_p_5_8,i=Z(r*n*s,e),c=Z(t*i*i,e),f=i,a=Z(i*Vn,e),u=c===r,h=c===Z(-r,e),w=c===Z(-r*Vn,e);return u&&(i=f),(h||w)&&(i=a),Lt(i,e)&&(i=Z(-i,e)),{isValid:u||h,value:i}}var Mt=Fs(Zn,{uvRatio:$n}),Pt=Mt.Fp,Ms=Mt.Fn;function La(r){return Us(Mt,pr,Object.assign({adjustScalarBytes:Da,zip215:!0},r))}var Hs=La({});var zn=Vn,Ra=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Ca=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Oa=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Fa=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),ks=r=>$n(Rt,r),Ua=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),jn=r=>Pt.create(St(r)&Ua);function Ps(r){let{d:t}=Zn,e=Ee,n=x=>Pt.create(x),o=n(zn*r*r),s=n((o+Rt)*Oa),i=BigInt(-1),c=n((i-t*o)*n(o+t)),{isValid:f,value:a}=$n(s,c),u=n(a*r);Lt(u,e)||(u=n(-u)),f||(a=u),f||(i=o);let h=n(i*(o-Rt)*Fa-c),w=a*a,p=n((a+a)*c),b=n(h*Ra),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 Ar{static BASE=new r(Mt.BASE);static ZERO=new r(Mt.ZERO);static Fp=Pt;static Fn=Ms;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}=Zn,o=Ee,s=R=>Pt.create(R),i=jn(t);if(!ms(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}=ks(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===Ba)throw new Error("invalid ristretto255 encoding 2");return new r(new Mt(x,A,Rt,B))}static fromHex(t){return r.fromBytes(Oe(t))}toBytes(){let{X:t,Y:e,Z:n,T:o}=this.ep,s=Ee,i=d=>Pt.create(d),c=i(i(n+e)*i(n-e)),f=i(t*e),a=i(f*f),{value:u}=ks(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*zn),x=i(t*zn);t=d,e=x,b=i(h*Ca)}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 Na=Object.freeze({Point:Ht,hashToCurve(r,t){let e=t?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":t.DST,n=qn(r,e,64,pr);return Na.deriveToCurve(n)},hashToScalar(r,t={DST:Ns}){let e=qn(r,t.DST,64,pr);return Ms.create(St(e))},deriveToCurve(r){ut(r,64);let t=jn(r.subarray(0,32)),e=Ps(t),n=jn(r.subarray(32,64)),o=Ps(n);return new Ht(e.add(o))}});var ze=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},vr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var qs={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new vr("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 Br=qs;var Tr=32;var Yn,Ka=(async()=>{try{return await Br.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function ka(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await Br.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await Br.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 Pa(r,t,e){return Hs.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function Vs(r,t,e){return Yn==null&&(Yn=await Ka),Yn?ka(r,t,e):Pa(r,t,e)}function Ir(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var _r=class{type="Ed25519";raw;constructor(t){this.raw=Gn(t,Tr)}toMultihash(){return lt.digest(le(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=Vs(this.raw,e,t);return Ir(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function js(r){return r=Gn(r,Tr),new _r(r)}function Gn(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 Ha=Math.pow(2,7),qa=Math.pow(2,14),Va=Math.pow(2,21),Zs=Math.pow(2,28),$s=Math.pow(2,35),Ys=Math.pow(2,42),Gs=Math.pow(2,49),nt=128,qt=127;function je(r){if(r<Ha)return 1;if(r<qa)return 2;if(r<Va)return 3;if(r<Zs)return 4;if(r<$s)return 5;if(r<Ys)return 6;if(r<Gs)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Xs(r,t,e=0){switch(je(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 Ws(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)*$s,e<nt)||(e=r[t+6],n+=(e&qt)*Ys,e<nt)||(e=r[t+7],n+=(e&qt)*Gs,e<nt))return n;throw new RangeError("Could not decode varint")}var Xn=new Float32Array([-0]),Vt=new Uint8Array(Xn.buffer);function Qs(r,t,e){Xn[0]=r,t[e]=Vt[0],t[e+1]=Vt[1],t[e+2]=Vt[2],t[e+3]=Vt[3]}function Js(r,t){return Vt[0]=r[t],Vt[1]=r[t+1],Vt[2]=r[t+2],Vt[3]=r[t+3],Xn[0]}var Wn=new Float64Array([-0]),rt=new Uint8Array(Wn.buffer);function ti(r,t,e){Wn[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 ei(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],Wn[0]}var za=BigInt(Number.MAX_SAFE_INTEGER),ja=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 Jt;if(t<za&&t>ja)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>ri&&(o=0n,++n>ri&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return Jt;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):Jt}},Jt=new ht(0,0);Jt.toBigInt=function(){return 0n};Jt.zzEncode=Jt.zzDecode=function(){return this};Jt.length=function(){return 1};var ri=4294967296n;function ni(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 oi(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 Qn(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 Dr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Jn=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 Dr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw gt(this,4);return Dr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw gt(this,4);let t=Js(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw gt(this,4);let t=ei(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 oi(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=Dr(this.buf,this.pos+=4),e=Dr(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=Ws(this.buf,this.pos);return this.pos+=je(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 Ze(r){return new Jn(r instanceof Uint8Array?r:r.subarray())}function Lr(r,t,e){let n=Ze(r);return t.decode(n,void 0,e)}function to(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 te=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function eo(){}var no=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Za=to();function $a(r){return globalThis.Buffer!=null?at(r):Za(r)}var Ye=class{len;head;tail;states;constructor(){this.len=0,this.head=new te(eo,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new te(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new oo((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(Rr,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(Rr,e.length(),e)}uint64Number(t){return this._push(Xs,je(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(Rr,e.length(),e)}sint64Number(t){let e=ht.fromNumber(t).zzEncode();return this._push(Rr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(ro,1,t?1:0)}fixed32(t){return this._push($e,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=ht.fromBigInt(t);return this._push($e,4,e.lo)._push($e,4,e.hi)}fixed64Number(t){let e=ht.fromNumber(t);return this._push($e,4,e.lo)._push($e,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(Qs,4,t)}double(t){return this._push(ti,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(ro,1,0):this.uint32(e)._push(Ga,e,t)}string(t){let e=ni(t);return e!==0?this.uint32(e)._push(Qn,e,t):this._push(ro,1,0)}fork(){return this.states=new no(this),this.head=this.tail=new te(eo,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 te(eo,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=$a(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function ro(r,t,e){t[e]=r&255}function Ya(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var oo=class extends te{next;constructor(t,e){super(Ya,t,e),this.next=void 0}};function Rr(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 $e(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 Ga(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Ye.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Xa,t,r),this},Ye.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Wa,t,r),this});function Xa(r,t,e){t.set(r,e)}function Wa(r,t,e){r.length<40?Qn(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(Ot(r),e)}function so(){return new Ye}function Cr(r,t){let e=so();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}function*Or(r,t,e){let n=Ze(r);yield*t.stream(n,void 0,"$",e)}var Fr={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Ur(r,t,e,n,o){return{name:r,type:t,encode:e,decode:n,stream:o}}function io(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 Ur("enum",Fr.VARINT,e,n,o)}function Nr(r,t,e){return Ur("message",Fr.LENGTH_DELIMITED,r,t,e)}var ot;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(ot||(ot={}));var co;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(co||(co={}));(function(r){r.codec=()=>io(co)})(ot||(ot={}));var Ge;(function(r){let t;r.codec=()=>(t==null&&(t=Nr((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 Cr(s,r.codec())}r.encode=e;function n(s,i){return Lr(s,r.codec(),i)}r.decode=n;function o(s,i){return Or(s,r.codec(),i)}r.stream=o})(Ge||(Ge={}));var ao;(function(r){let t;r.codec=()=>(t==null&&(t=Nr((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 Cr(s,r.codec())}r.encode=e;function n(s,i){return Lr(s,r.codec(),i)}r.decode=n;function o(s,i){return Or(s,r.codec(),i)}r.stream=o})(ao||(ao={}));var Kr=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,e){if(fr(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 de(this),this.iHash.update(t),this}digestInto(t){de(this),ur(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()}},ii=(()=>{let r=((t,e,n)=>new Kr(t,e).update(n).digest());return r.create=(t,e)=>new Kr(t,e),r})();var ci=(r,t)=>(r+(r>=0?t:-t)/ai)/t;function Ja(r,t,e){ye("scalar",r,At,e);let[[n,o],[s,i]]=t,c=ci(i*r,e),f=ci(-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=Me(Math.ceil(be(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 uo(r){if(!["compact","recovered","der"].includes(r))throw new Error('Signature format must be "compact", "recovered", or "der"');return r}function fo(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&&uo(e.format),e}var ho=class extends Error{constructor(t=""){super(t)}},xt={Err:ho,_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(br(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 Gt(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),ai=BigInt(2),kr=BigInt(3),tf=BigInt(4);function fi(r,t={}){let e=Er("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=hi(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(ui(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),tf),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 Ja(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=qe(E,l),m=qe(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(me(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,_=>Qt(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 Qt(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}=Os(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 pe(this.toBytes(l))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let U=o.BITS,H=new we(I,t.endo?Math.ceil(U/2):U);return U>=8&&I.BASE.precompute(8),Object.freeze(I.prototype),Object.freeze(I),I}function ui(r){return Uint8Array.of(r?2:3)}function hi(r,t){return{secretKey:t.BYTES,publicKey:1+r.BYTES,publicKeyUncompressed:1+2*r.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function ef(r,t={}){let{Fn:e}=r,n=t.randomBytes===void 0?Ke:t.randomBytes,o=Object.assign(hi(r.Fp,e),{seed:Math.max(Nn(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,Kn(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(!Yt(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=Sr(c,f);return Object.freeze(h),Object.freeze(o),Object.freeze({getPublicKey:f,getSharedSecret:u,keygen:w,Point:r,utils:h,lengths:o})}function li(r,t,e={}){let n=t;fr(n),bt(e,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),e=Object.assign({},e);let o=e.randomBytes===void 0?Ke:e.randomBytes,s=e.hmac===void 0?(g,y)=>ii(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}=ef(r,e),S={prehash:!0,lowS:typeof e.lowS=="boolean"?e.lowS:!0,format:"compact",extraEntropy:!1},d=f*ai+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){uo(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(me(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(ui((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(uo(y),y==="der")return me(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 pe(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=Gt(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=Me(a);function U(g){return ye("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}=fo(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),ee=r.BASE.multiply(j).toAffine(),Ae=c.create(ee.x);if(Ae===At)return;let Qe=c.create(st*c.create(Y+Ae*k));if(Qe===At)return;let mo=(ee.x===Ae?0:2)|Number(ee.y&zt),yo=Qe;return _&&x(Qe)&&(yo=c.neg(Qe),mo^=1),new D(Ae,yo,d?void 0:mo)}return{seed:K,k2sig:X}}function l(g,y,v={}){let{seed:_,k2sig:T}=N(g,y,v);return ys(n.outputLen,c.BYTES,s)(_,T).toBytes(v.format)}function m(g,y,v,_={}){let{lowS:T,prehash:L,format:O}=fo(_,S);if(v=P(v,void 0,"publicKey"),y=H(y,L),!Yt(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),ee=r.BASE.multiplyUnsafe(j).add(M.multiplyUnsafe(st));return ee.is0()?!1:c.create(ee.x)===K}catch{return!1}}function E(g,y,v={}){let{prehash:_}=fo(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 po={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},rf={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var di=BigInt(2);function nf(r){let t=po.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,di,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,di,t);if(!lo.eql(lo.sqr(F),r))throw new Error("Cannot find square root");return F}var lo=ge(po.p,{sqrt:nf}),of=fi(po,{Fp:lo,endo:rf}),Se=li(of,ds);function pi(r,t,e,n){let o=_e.digest(e instanceof Uint8Array?e:e.subarray());if(Ir(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Se.verify(t,s,r,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new ze(String(s))});try{return n?.signal?.throwIfAborted(),Se.verify(t,o.digest,r,{prehash:!1,format:"der"})}catch(s){throw new ze(String(s))}}var Pr=class{type="secp256k1";raw;_key;constructor(t){this._key=yi(t),this.raw=mi(this._key)}toMultihash(){return lt.digest(le(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 pi(this._key,e,t,n)}};function bi(r){return new Pr(r)}function mi(r){return Se.Point.fromBytes(r).toBytes()}function yi(r){try{return Se.Point.fromBytes(r),r}catch(t){throw new nr(String(t))}}function gi(r){let{Type:t,Data:e}=Ge.decode(r.digest),n=e??new Uint8Array;switch(t){case ot.Ed25519:return js(n);case ot.secp256k1:return bi(n);case ot.ECDSA:return Xo(n);default:throw new Le}}function le(r){return Ge.encode({Type:ot[r.type],Data:r.raw})}var xi=Symbol.for("nodejs.util.inspect.custom"),sf=114,Xe=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()})`}[dn]=!0;toString(){return this.string==null&&(this.string=$.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return J.createV1(sf,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")}[xi](){return`PeerId(${this.toString()})`}},Mr=class extends Xe{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Hr=class extends Xe{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},qr=class extends Xe{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},cf=2336,We=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=lt.digest(Ot(this.url))}[xi](){return`PeerId(${this.url})`}[dn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return J.createV1(cf,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=it(t)),t.toString()===this.toString())}};var af=114,wi=2336;function Ei(r,t){let e;if(r.charAt(0)==="1"||r.charAt(0)==="Q")e=Ie($.decode(`z${r}`));else{if(r.startsWith("k51qzi5uqu5")||r.startsWith("kzwfwjn5ji4")||r.startsWith("k2k4r8")||r.startsWith("bafz"))return ff(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=Ie(t.decode(r))}return Si(e)}function Si(r){if(hf(r))return new Mr({multihash:r});if(uf(r))try{let t=gi(r);if(t.type==="Ed25519")return new Hr({multihash:r,publicKey:t});if(t.type==="secp256k1")return new qr({multihash:r,publicKey:t})}catch{let e=it(r.digest);return new We(new URL(e))}throw new sr("Supplied PeerID Multihash is invalid")}function ff(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==af&&r.code!==wi)throw new or("Supplied PeerID CID is invalid");if(r.code===wi){let t=it(r.multihash.digest);return new We(new URL(t))}return Si(r.multihash)}function uf(r){return r.code===lt.code}function hf(r){return r.code===_e.code}var Ai=(r,t)=>{let[,e,n,...o]=r.split("/");if(e!=="ipns")throw new ue(`Namespace ${e} was not "ipns"`);try{return{namespace:"ipns",peerId:Ei(n),path:o.length>0?`/${o.join("/")}`:"",answer:t}}catch{return{namespace:"dnslink",value:n,path:o.length>0?`/${o.join("/")}`:"",answer:t}}};var Vr=class{dns;log;namespaces;cache;cacheMaxAnswers;constructor(t,e={}){this.dns=t.dns,this.log=t.logger.forComponent("helia:dnslink"),this.namespaces={ipfs:qo,ipns:Ai,...e.namespaces},this.cache=new fe({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??Ho,e),o=new fe({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 rr(`No DNSLink records found for domain: ${t}`)}};function lf(r,t={}){return new Vr(r,t)}return Ri(df);})();
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
@noble/curves/utils.js:
|