@libp2p/floodsub 11.0.22-b7c6dc0f2 → 11.0.23-a34745c01
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 +10 -10
package/dist/index.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PFloodsub = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var Libp2PFloodsub=(()=>{var Wc=Object.create;var Jr=Object.defineProperty;var Jc=Object.getOwnPropertyDescriptor;var Qc=Object.getOwnPropertyNames;var eu=Object.getPrototypeOf,tu=Object.prototype.hasOwnProperty;var ru=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),H=(t,e)=>{for(var r in e)Jr(t,r,{get:e[r],enumerable:!0})},bi=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Qc(e))!tu.call(t,s)&&s!==r&&Jr(t,s,{get:()=>e[s],enumerable:!(n=Jc(e,s))||n.enumerable});return t};var nu=(t,e,r)=>(r=t!=null?Wc(eu(t)):{},bi(e||!t||!t.__esModule?Jr(r,"default",{value:t,enumerable:!0}):r,t)),ou=t=>bi(Jr({},"__esModule",{value:!0}),t);var zc=ru((Rw,fi)=>{"use strict";var ud=Object.prototype.hasOwnProperty,me="~";function Vr(){}Object.create&&(Vr.prototype=Object.create(null),new Vr().__proto__||(me=!1));function fd(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function Vc(t,e,r,n,s){if(typeof r!="function")throw new TypeError("The listener must be a function");var o=new fd(r,n||t,s),i=me?me+e:e;return t._events[i]?t._events[i].fn?t._events[i]=[t._events[i],o]:t._events[i].push(o):(t._events[i]=o,t._eventsCount++),t}function qn(t,e){--t._eventsCount===0?t._events=new Vr:delete t._events[e]}function pe(){this._events=new Vr,this._eventsCount=0}pe.prototype.eventNames=function(){var e=[],r,n;if(this._eventsCount===0)return e;for(n in r=this._events)ud.call(r,n)&&e.push(me?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(r)):e};pe.prototype.listeners=function(e){var r=me?me+e:e,n=this._events[r];if(!n)return[];if(n.fn)return[n.fn];for(var s=0,o=n.length,i=new Array(o);s<o;s++)i[s]=n[s].fn;return i};pe.prototype.listenerCount=function(e){var r=me?me+e:e,n=this._events[r];return n?n.fn?1:n.length:0};pe.prototype.emit=function(e,r,n,s,o,i){var a=me?me+e:e;if(!this._events[a])return!1;var c=this._events[a],u=arguments.length,f,h;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),u){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,r),!0;case 3:return c.fn.call(c.context,r,n),!0;case 4:return c.fn.call(c.context,r,n,s),!0;case 5:return c.fn.call(c.context,r,n,s,o),!0;case 6:return c.fn.call(c.context,r,n,s,o,i),!0}for(h=1,f=new Array(u-1);h<u;h++)f[h-1]=arguments[h];c.fn.apply(c.context,f)}else{var l=c.length,d;for(h=0;h<l;h++)switch(c[h].once&&this.removeListener(e,c[h].fn,void 0,!0),u){case 1:c[h].fn.call(c[h].context);break;case 2:c[h].fn.call(c[h].context,r);break;case 3:c[h].fn.call(c[h].context,r,n);break;case 4:c[h].fn.call(c[h].context,r,n,s);break;default:if(!f)for(d=1,f=new Array(u-1);d<u;d++)f[d-1]=arguments[d];c[h].fn.apply(c[h].context,f)}}return!0};pe.prototype.on=function(e,r,n){return Vc(this,e,r,n,!1)};pe.prototype.once=function(e,r,n){return Vc(this,e,r,n,!0)};pe.prototype.removeListener=function(e,r,n,s){var o=me?me+e:e;if(!this._events[o])return this;if(!r)return qn(this,o),this;var i=this._events[o];if(i.fn)i.fn===r&&(!s||i.once)&&(!n||i.context===n)&&qn(this,o);else{for(var a=0,c=[],u=i.length;a<u;a++)(i[a].fn!==r||s&&!i[a].once||n&&i[a].context!==n)&&c.push(i[a]);c.length?this._events[o]=c.length===1?c[0]:c:qn(this,o)}return this};pe.prototype.removeAllListeners=function(e){var r;return e?(r=me?me+e:e,this._events[r]&&qn(this,r)):(this._events=new Vr,this._eventsCount=0),this};pe.prototype.off=pe.prototype.removeListener;pe.prototype.addListener=pe.prototype.on;pe.prefixed=me;pe.EventEmitter=pe;typeof fi<"u"&&(fi.exports=pe)});var xd={};H(xd,{StrictNoSign:()=>yd,StrictSign:()=>bd,TopicValidatorResult:()=>rr,floodsub:()=>wd,isPubSub:()=>gd,protocol:()=>di,pubSubSymbol:()=>or});var or=Symbol.for("@libp2p/pubsub");var $=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},Dt=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var Qr=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var ee=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var en=class extends Error{static name="NotStartedError";constructor(e="Not started"){super(e),this.name="NotStartedError"}};var ht=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var $n=Symbol.for("@libp2p/peer-id");function su(t){return typeof t?.handleEvent=="function"}function iu(t){return(t!==!0&&t!==!1&&t?.once)??!1}var _t=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let r=this.#e.get(e);return r==null?0:r.length}addEventListener(e,r,n){let s=iu(n);super.addEventListener(e,i=>{if(s){let a=this.#e.get(i.type);a!=null&&(a=a.filter(({callback:c})=>c!==r),this.#e.set(i.type,a))}su(r)?r.handleEvent(i):r(i)},n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:r,once:s})}removeEventListener(e,r,n){super.removeEventListener(e.toString(),r??null,n);let s=this.#e.get(e);s!=null&&(s=s.filter(({callback:o})=>o!==r),this.#e.set(e,s))}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};var yi=Symbol.for("@libp2p/service-capabilities"),gi=Symbol.for("@libp2p/service-dependencies");var Xn={};H(Xn,{base58btc:()=>Y,base58flickr:()=>du});var Wd=new Uint8Array(0);function wi(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function Me(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}function xi(t){return new TextEncoder().encode(t)}function Ei(t){return new TextDecoder().decode(t)}function au(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var s=0;s<t.length;s++){var o=t.charAt(s),i=o.charCodeAt(0);if(r[i]!==255)throw new TypeError(o+" is ambiguous");r[i]=s}var a=t.length,c=t.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function h(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var g=0,b=0,y=0,v=p.length;y!==v&&p[y]===0;)y++,g++;for(var S=(v-y)*f+1>>>0,L=new Uint8Array(S);y!==v;){for(var T=p[y],R=0,k=S-1;(T!==0||R<b)&&k!==-1;k--,R++)T+=256*L[k]>>>0,L[k]=T%a>>>0,T=T/a>>>0;if(T!==0)throw new Error("Non-zero carry");b=R,y++}for(var B=S-b;B!==S&&L[B]===0;)B++;for(var N=c.repeat(g);B<S;++B)N+=t.charAt(L[B]);return N}function l(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var g=0;if(p[g]!==" "){for(var b=0,y=0;p[g]===c;)b++,g++;for(var v=(p.length-g)*u+1>>>0,S=new Uint8Array(v);p[g];){var L=r[p.charCodeAt(g)];if(L===255)return;for(var T=0,R=v-1;(L!==0||T<y)&&R!==-1;R--,T++)L+=a*S[R]>>>0,S[R]=L%256>>>0,L=L/256>>>0;if(L!==0)throw new Error("Non-zero carry");y=T,g++}if(p[g]!==" "){for(var k=v-y;k!==v&&S[k]===0;)k++;for(var B=new Uint8Array(b+(v-k)),N=b;k!==v;)B[N++]=S[k++];return B}}}function d(p){var g=l(p);if(g)return g;throw new Error(`Non-${e} character`)}return{encode:h,decodeUnsafe:l,decode:d}}var cu=au,uu=cu,Si=uu;var jn=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,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,r,n){this.name=e,this.prefix=r;let s=r.codePointAt(0);if(s===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=s,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 Ai(this,e)}},Yn=class{decoders;constructor(e){this.decoders=e}or(e){return Ai(this,e)}decode(e){let r=e[0],n=this.decoders[r];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 Ai(t,e){return new Yn({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Gn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,s){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=s,this.encoder=new jn(e,r,n),this.decoder=new Zn(e,r,s)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function kt({name:t,prefix:e,encode:r,decode:n}){return new Gn(t,e,r,n)}function We({name:t,prefix:e,alphabet:r}){let{encode:n,decode:s}=Si(r,t);return kt({prefix:e,name:t,encode:n,decode:o=>Me(s(o))})}function fu(t,e,r,n){let s=t.length;for(;t[s-1]==="=";)--s;let o=new Uint8Array(s*r/8|0),i=0,a=0,c=0;for(let u=0;u<s;++u){let f=e[t[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,o[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return o}function lu(t,e,r){let n=e[e.length-1]==="=",s=(1<<r)-1,o="",i=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],i+=8;i>r;)i-=r,o+=e[s&a>>i];if(i!==0&&(o+=e[s&a<<r-i]),n)for(;(o.length*r&7)!==0;)o+="=";return o}function hu(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function X({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let s=hu(n);return kt({prefix:e,name:t,encode(o){return lu(o,n,r)},decode(o){return fu(o,s,r,t)}})}var Y=We({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),du=We({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Wn={};H(Wn,{base32:()=>Ct,base32hex:()=>yu,base32hexpad:()=>wu,base32hexpadupper:()=>xu,base32hexupper:()=>gu,base32pad:()=>mu,base32padupper:()=>bu,base32upper:()=>pu,base32z:()=>Eu});var Ct=X({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),pu=X({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),mu=X({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),bu=X({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),yu=X({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),gu=X({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),wu=X({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),xu=X({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Eu=X({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Jn={};H(Jn,{base36:()=>sr,base36upper:()=>vu});var sr=We({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),vu=We({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Su=Ti,Ii=128,Au=127,Iu=~Au,Bu=Math.pow(2,31);function Ti(t,e,r){e=e||[],r=r||0;for(var n=r;t>=Bu;)e[r++]=t&255|Ii,t/=128;for(;t&Iu;)e[r++]=t&255|Ii,t>>>=7;return e[r]=t|0,Ti.bytes=r-n+1,e}var Tu=Qn,Lu=128,Bi=127;function Qn(t,n){var r=0,n=n||0,s=0,o=n,i,a=t.length;do{if(o>=a)throw Qn.bytes=0,new RangeError("Could not decode varint");i=t[o++],r+=s<28?(i&Bi)<<s:(i&Bi)*Math.pow(2,s),s+=7}while(i>=Lu);return Qn.bytes=o-n,r}var Du=Math.pow(2,7),_u=Math.pow(2,14),ku=Math.pow(2,21),Cu=Math.pow(2,28),Ru=Math.pow(2,35),Pu=Math.pow(2,42),Nu=Math.pow(2,49),Ou=Math.pow(2,56),Uu=Math.pow(2,63),Fu=function(t){return t<Du?1:t<_u?2:t<ku?3:t<Cu?4:t<Ru?5:t<Pu?6:t<Nu?7:t<Ou?8:t<Uu?9:10},Ku={encode:Su,decode:Tu,encodingLength:Fu},Mu=Ku,ir=Mu;function ar(t,e=0){return[ir.decode(t,e),ir.decode.bytes]}function Rt(t,e,r=0){return ir.encode(t,e,r),e}function Pt(t){return ir.encodingLength(t)}function Re(t,e){let r=e.byteLength,n=Pt(t),s=n+Pt(r),o=new Uint8Array(s+r);return Rt(t,o,0),Rt(r,o,n),o.set(e,s),new Nt(t,r,e,o)}function Je(t){let e=Me(t),[r,n]=ar(e),[s,o]=ar(e.subarray(n)),i=e.subarray(n+o);if(i.byteLength!==s)throw new Error("Incorrect length");return new Nt(r,s,i,e)}function Li(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&wi(t.bytes,r.bytes)}}var Nt=class{code;size;digest;bytes;constructor(e,r,n,s){this.code=e,this.size=r,this.digest=n,this.bytes=s}};function Di(t,e){let{bytes:r,version:n}=t;return n===0?Vu(r,eo(t),e??Y.encoder):zu(r,eo(t),e??Ct.encoder)}var _i=new WeakMap;function eo(t){let e=_i.get(t);if(e==null){let r=new Map;return _i.set(t,r),r}return e}var le=class t{code;version;multihash;bytes;"/";constructor(e,r,n,s){this.code=r,this.version=e,this.multihash=n,this.bytes=s,this["/"]=s}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:r}=this;if(e!==cr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Hu)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:r}=this.multihash,n=Re(e,r);return t.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 t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&Li(e.multihash,n.multihash)}toString(e){return Di(this,e)}toJSON(){return{"/":Di(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 r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:s,multihash:o,bytes:i}=r;return new t(n,s,o,i??ki(n,s,o.bytes))}else if(r[$u]===!0){let{version:n,multihash:s,code:o}=r,i=Je(s);return t.create(n,o,i)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==cr)throw new Error(`Version 0 CID must use dag-pb (code: ${cr}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let s=ki(e,r,n.bytes);return new t(e,r,n,s)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,cr,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,s=Me(e.subarray(n,n+r.multihashSize));if(s.byteLength!==r.multihashSize)throw new Error("Incorrect length");let o=s.subarray(r.multihashSize-r.digestSize),i=new Nt(r.multihashCode,r.digestSize,o,s);return[r.version===0?t.createV0(i):t.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[h,l]=ar(e.subarray(r));return r+=l,h},s=n(),o=cr;if(s===18?(s=0,r=0):o=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let i=r,a=n(),c=n(),u=r+c,f=u-i;return{version:s,codec:o,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(e,r){let[n,s]=qu(e,r),o=t.decode(s);if(o.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return eo(o).set(n,e),o}};function qu(t,e){switch(t[0]){case"Q":{let r=e??Y;return[Y.prefix,r.decode(`${Y.prefix}${t}`)]}case Y.prefix:{let r=e??Y;return[Y.prefix,r.decode(t)]}case Ct.prefix:{let r=e??Ct;return[Ct.prefix,r.decode(t)]}case sr.prefix:{let r=e??sr;return[sr.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function Vu(t,e,r){let{prefix:n}=r;if(n!==Y.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let s=e.get(n);if(s==null){let o=r.encode(t).slice(1);return e.set(n,o),o}else return s}function zu(t,e,r){let{prefix:n}=r,s=e.get(n);if(s==null){let o=r.encode(t);return e.set(n,o),o}else return s}var cr=112,Hu=18;function ki(t,e,r){let n=Pt(t),s=n+Pt(e),o=new Uint8Array(s+r.byteLength);return Rt(t,o,0),Rt(e,o,n),o.set(r,s),o}var $u=Symbol.for("@ipld/js-cid/CID");var to={};H(to,{identity:()=>Be});var Ci=0,ju="identity",Ri=Me;function Zu(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return Re(Ci,Ri(t))}var Be={code:Ci,name:ju,encode:Ri,digest:Zu};function Ae(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function Yu(t){return t.buffer instanceof ArrayBuffer}function Pe(t){return Yu(t)?t:t.slice()}async function Pi(t,e,r,n){let s=await crypto.subtle.importKey("jwk",t,{name:"ECDSA",namedCurve:t.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let o=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},s,Pe(e),Pe(r.subarray()));return n?.signal?.throwIfAborted(),o}function qe(t=0){return new Uint8Array(t)}function ur(t=0){return new Uint8Array(t)}function ro(t,e){e==null&&(e=t.reduce((s,o)=>s+o.length,0));let r=ur(e),n=0;for(let s of t)r.set(s,n),n+=s.length;return r}function Ni(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}var Ui=Symbol.for("@achingbrain/uint8arraylist");function Oi(t,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let r=0;for(let n of t){let s=r+n.byteLength;if(e<s)return{buf:n,index:e-r};r=s}throw new RangeError("index is out of bounds")}function rn(t){return!!t?.[Ui]}var ae=class t{bufs;length;[Ui]=!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 r=0;for(let n of e)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(rn(n)){r+=n.byteLength;for(let s of n.bufs)this.bufs.push(s)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...e){this.prependAll(e)}prependAll(e){let r=0;for(let n of e.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(rn(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(e){let r=Oi(this.bufs,e);return r.buf[r.index]}set(e,r){let n=Oi(this.bufs,e);n.buf[n.index]=r}write(e,r=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(r+n,e[n]);else if(rn(e))for(let n=0;n<e.length;n++)this.set(r+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,r){let{bufs:n,length:s}=this._subList(e,r);return ro(n,s)}subarray(e,r){let{bufs:n,length:s}=this._subList(e,r);return n.length===1?n[0]:ro(n,s)}sublist(e,r){let{bufs:n,length:s}=this._subList(e,r),o=new t;return o.length=s,o.bufs=n,o}_subList(e,r){if(e=e??0,r=r??this.length,e<0&&(e=this.length+e),r<0&&(r=this.length+r),e<0||r>this.length)throw new RangeError("index is out of bounds");if(e===r)return{bufs:[],length:0};if(e===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],s=0;for(let o=0;o<this.bufs.length;o++){let i=this.bufs[o],a=s,c=a+i.byteLength;if(s=c,e>=c)continue;let u=e>=a&&e<c,f=r>a&&r<=c;if(u&&f){if(e===a&&r===c){n.push(i);break}let h=e-a;n.push(i.subarray(h,h+(r-e)));break}if(u){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(f){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-e}}indexOf(e,r=0){if(!rn(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(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),e.length===0)return r>this.length?this.length:r;let s=n.byteLength;if(s===0)throw new TypeError("search must be at least 1 byte long");let o=256,i=new Int32Array(o);for(let h=0;h<o;h++)i[h]=-1;for(let h=0;h<s;h++)i[n[h]]=h;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let h=r;h<=c;h+=f){f=0;for(let l=u;l>=0;l--){let d=this.get(h+l);if(n[l]!==d){f=Math.max(1,l-a[d]);break}}if(f===0)return h}return-1}getInt8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(e,r){let n=ur(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,e)}getInt16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(e,r,n){let s=qe(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,r,n),this.write(s,e)}getInt32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(e,r,n){let s=qe(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,r,n),this.write(s,e)}getBigInt64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(e,r,n){let s=qe(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,r,n),this.write(s,e)}getUint8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(e,r){let n=ur(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,e)}getUint16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(e,r,n){let s=qe(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,r,n),this.write(s,e)}getUint32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(e,r,n){let s=qe(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,r,n),this.write(s,e)}getBigUint64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(e,r,n){let s=qe(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,r,n),this.write(s,e)}getFloat32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(e,r,n){let s=qe(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,r,n),this.write(s,e)}getFloat64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(e,r,n){let s=qe(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,r,n),this.write(s,e)}equals(e){if(e==null||!(e instanceof t)||e.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!Ni(this.bufs[r],e.bufs[r]))return!1;return!0}static fromUint8Arrays(e,r){let n=new t;return n.bufs=e,r==null&&(r=e.reduce((s,o)=>s+o.byteLength,0)),n.length=r,n}};var ao={};H(ao,{base10:()=>rf});var _p=new Uint8Array(0);function Fi(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function Ve(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return dt(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return dt(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function Ki(t){return new TextEncoder().encode(t)}function Mi(t){return new TextDecoder().decode(t)}function Gu(t){return t?.buffer instanceof ArrayBuffer}function dt(t){return Gu(t)?t:t.slice()}function Xu(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var s=0;s<t.length;s++){var o=t.charAt(s),i=o.charCodeAt(0);if(r[i]!==255)throw new TypeError(o+" is ambiguous");r[i]=s}var a=t.length,c=t.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function h(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var g=0,b=0,y=0,v=p.length;y!==v&&p[y]===0;)y++,g++;for(var S=(v-y)*f+1>>>0,L=new Uint8Array(S);y!==v;){for(var T=p[y],R=0,k=S-1;(T!==0||R<b)&&k!==-1;k--,R++)T+=256*L[k]>>>0,L[k]=T%a>>>0,T=T/a>>>0;if(T!==0)throw new Error("Non-zero carry");b=R,y++}for(var B=S-b;B!==S&&L[B]===0;)B++;for(var N=c.repeat(g);B<S;++B)N+=t.charAt(L[B]);return N}function l(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var g=0;if(p[g]!==" "){for(var b=0,y=0;p[g]===c;)b++,g++;for(var v=(p.length-g)*u+1>>>0,S=new Uint8Array(v);p[g];){var L=r[p.charCodeAt(g)];if(L===255)return;for(var T=0,R=v-1;(L!==0||T<y)&&R!==-1;R--,T++)L+=a*S[R]>>>0,S[R]=L%256>>>0,L=L/256>>>0;if(L!==0)throw new Error("Non-zero carry");y=T,g++}if(p[g]!==" "){for(var k=v-y;k!==v&&S[k]===0;)k++;for(var B=new Uint8Array(b+(v-k)),N=b;k!==v;)B[N++]=S[k++];return B}}}function d(p){var g=l(p);if(g)return g;throw new Error(`Non-${e} character`)}return{encode:h,decodeUnsafe:l,decode:d}}var Wu=Xu,Ju=Wu,Vi=Ju;var no=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},oo=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let s=r.codePointAt(0);if(s===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=s,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 zi(this,e)}},so=class{decoders;constructor(e){this.decoders=e}or(e){return zi(this,e)}decode(e){let r=e[0],n=this.decoders[r];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 zi(t,e){return new so({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var io=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,s){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=s,this.encoder=new no(e,r,n),this.decoder=new oo(e,r,s)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Ot({name:t,prefix:e,encode:r,decode:n}){return new io(t,e,r,n)}function et({name:t,prefix:e,alphabet:r}){let{encode:n,decode:s}=Vi(r,t);return Ot({prefix:e,name:t,encode:n,decode:o=>Ve(s(o))})}function Qu(t,e,r,n){let s=t.length;for(;t[s-1]==="=";)--s;let o=new Uint8Array(s*r/8|0),i=0,a=0,c=0;for(let u=0;u<s;++u){let f=e[t[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,o[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return o}function ef(t,e,r){let n=e[e.length-1]==="=",s=(1<<r)-1,o="",i=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],i+=8;i>r;)i-=r,o+=e[s&a>>i];if(i!==0&&(o+=e[s&a<<r-i]),n)for(;(o.length*r&7)!==0;)o+="=";return o}function tf(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function W({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let s=tf(n);return Ot({prefix:e,name:t,encode(o){return ef(o,n,r)},decode(o){return Qu(o,s,r,t)}})}var rf=et({prefix:"9",name:"base10",alphabet:"0123456789"});var co={};H(co,{base16:()=>nf,base16upper:()=>of});var nf=W({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),of=W({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var uo={};H(uo,{base2:()=>sf});var sf=W({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var fo={};H(fo,{base256emoji:()=>lf});var Hi=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}"),af=Hi.reduce((t,e,r)=>(t[r]=e,t),[]),cf=Hi.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function uf(t){return t.reduce((e,r)=>(e+=af[r],e),"")}function ff(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let s=cf[n];if(s==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(s)}return new Uint8Array(e)}var lf=Ot({prefix:"\u{1F680}",name:"base256emoji",encode:uf,decode:ff});var lo={};H(lo,{base32:()=>Ut,base32hex:()=>mf,base32hexpad:()=>yf,base32hexpadupper:()=>gf,base32hexupper:()=>bf,base32pad:()=>df,base32padupper:()=>pf,base32upper:()=>hf,base32z:()=>wf});var Ut=W({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),hf=W({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),df=W({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),pf=W({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),mf=W({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),bf=W({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),yf=W({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),gf=W({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),wf=W({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ho={};H(ho,{base36:()=>fr,base36upper:()=>xf});var fr=et({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),xf=et({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var po={};H(po,{base58btc:()=>Ne,base58flickr:()=>Ef});var Ne=et({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ef=et({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var mo={};H(mo,{base64:()=>vf,base64pad:()=>Sf,base64url:()=>Af,base64urlpad:()=>If});var vf=W({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Sf=W({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Af=W({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),If=W({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var bo={};H(bo,{base8:()=>Bf});var Bf=W({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var yo={};H(yo,{identity:()=>Tf});var Tf=Ot({prefix:"\0",name:"identity",encode:t=>Mi(t),decode:t=>Ki(t)});var jp=new TextEncoder,Zp=new TextDecoder;var wo={};H(wo,{identity:()=>Xf});var _f=Zi,$i=128,kf=127,Cf=~kf,Rf=Math.pow(2,31);function Zi(t,e,r){e=e||[],r=r||0;for(var n=r;t>=Rf;)e[r++]=t&255|$i,t/=128;for(;t&Cf;)e[r++]=t&255|$i,t>>>=7;return e[r]=t|0,Zi.bytes=r-n+1,e}var Pf=go,Nf=128,ji=127;function go(t,n){var r=0,n=n||0,s=0,o=n,i,a=t.length;do{if(o>=a)throw go.bytes=0,new RangeError("Could not decode varint");i=t[o++],r+=s<28?(i&ji)<<s:(i&ji)*Math.pow(2,s),s+=7}while(i>=Nf);return go.bytes=o-n,r}var Of=Math.pow(2,7),Uf=Math.pow(2,14),Ff=Math.pow(2,21),Kf=Math.pow(2,28),Mf=Math.pow(2,35),qf=Math.pow(2,42),Vf=Math.pow(2,49),zf=Math.pow(2,56),Hf=Math.pow(2,63),$f=function(t){return t<Of?1:t<Uf?2:t<Ff?3:t<Kf?4:t<Mf?5:t<qf?6:t<Vf?7:t<zf?8:t<Hf?9:10},jf={encode:_f,decode:Pf,encodingLength:$f},Zf=jf,lr=Zf;function hr(t,e=0){return[lr.decode(t,e),lr.decode.bytes]}function Ft(t,e,r=0){return lr.encode(t,e,r),e}function Kt(t){return lr.encodingLength(t)}function qt(t,e){let r=e.byteLength,n=Kt(t),s=n+Kt(r),o=new Uint8Array(s+r);return Ft(t,o,0),Ft(r,o,n),o.set(e,s),new Mt(t,r,e,o)}function Yi(t){let e=Ve(t),[r,n]=hr(e),[s,o]=hr(e.subarray(n)),i=e.subarray(n+o);if(i.byteLength!==s)throw new Error("Incorrect length");return new Mt(r,s,i,e)}function Gi(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&Fi(t.bytes,r.bytes)}}var Mt=class{code;size;digest;bytes;constructor(e,r,n,s){this.code=e,this.size=r,this.digest=dt(n),this.bytes=dt(s)}};var Xi=0,Yf="identity",Wi=Ve;function Gf(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return qt(Xi,Wi(t))}var Xf={code:Xi,name:Yf,encode:Wi,digest:Gf};var vo={};H(vo,{sha256:()=>Jf,sha512:()=>Qf});var Wf=20;function Eo({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:s}){return new xo(t,e,r,n,s)}var xo=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,s,o){this.name=e,this.code=r,this.encode=n,this.minDigestLength=s??Wf,this.maxDigestLength=o}digest(e,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?Ji(n,this.code,r?.truncate):n.then(s=>Ji(s,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Ji(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return qt(e,t)}function ea(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Jf=Eo({name:"sha2-256",code:18,encode:ea("SHA-256")}),Qf=Eo({name:"sha2-512",code:19,encode:ea("SHA-512")});function ta(t,e){let{bytes:r,version:n}=t;return n===0?tl(r,So(t),e??Ne.encoder):rl(r,So(t),e??Ut.encoder)}var ra=new WeakMap;function So(t){let e=ra.get(t);if(e==null){let r=new Map;return ra.set(t,r),r}return e}var on=class t{code;version;multihash;bytes;"/";constructor(e,r,n,s){this.code=r,this.version=e,this.multihash=n,this.bytes=dt(s),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:r}=this;if(e!==pr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==nl)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:r}=this.multihash,n=qt(e,r);return t.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 t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&Gi(e.multihash,n.multihash)}toString(e){return ta(this,e)}toJSON(){return{"/":ta(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 r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:s,multihash:o,bytes:i}=r;return new t(n,s,o,i??na(n,s,o.bytes))}else if(r[ol]===!0){let{version:n,multihash:s,code:o}=r,i=Yi(s);return t.create(n,o,i)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==pr)throw new Error(`Version 0 CID must use dag-pb (code: ${pr}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let s=na(e,r,n.bytes);return new t(e,r,n,s)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,pr,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,s=Ve(e.subarray(n,n+r.multihashSize));if(s.byteLength!==r.multihashSize)throw new Error("Incorrect length");let o=s.subarray(r.multihashSize-r.digestSize),i=new Mt(r.multihashCode,r.digestSize,o,s);return[r.version===0?t.createV0(i):t.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[h,l]=hr(e.subarray(r));return r+=l,h},s=n(),o=pr;if(s===18?(s=0,r=0):o=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let i=r,a=n(),c=n(),u=r+c,f=u-i;return{version:s,codec:o,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(e,r){let[n,s]=el(e,r),o=t.decode(s);if(o.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return So(o).set(n,e),o}};function el(t,e){switch(t[0]){case"Q":{let r=e??Ne;return[Ne.prefix,r.decode(`${Ne.prefix}${t}`)]}case Ne.prefix:{let r=e??Ne;return[Ne.prefix,r.decode(t)]}case Ut.prefix:{let r=e??Ut;return[Ut.prefix,r.decode(t)]}case fr.prefix:{let r=e??fr;return[fr.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function tl(t,e,r){let{prefix:n}=r;if(n!==Ne.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let s=e.get(n);if(s==null){let o=r.encode(t).slice(1);return e.set(n,o),o}else return s}function rl(t,e,r){let{prefix:n}=r,s=e.get(n);if(s==null){let o=r.encode(t);return e.set(n,o),o}else return s}var pr=112,nl=18;function na(t,e,r){let n=Kt(t),s=n+Kt(e),o=new Uint8Array(s+r.byteLength);return Ft(t,o,0),Ft(e,o,n),o.set(r,s),o}var ol=Symbol.for("@ipld/js-cid/CID");var Ao={...yo,...uo,...bo,...ao,...co,...lo,...ho,...po,...mo,...fo},mm={...vo,...wo};function sn(t=0){return new Uint8Array(t)}function sa(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var oa=sa("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Io=sa("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=sn(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),sl={utf8:oa,"utf-8":oa,hex:Ao.base16,latin1:Io,ascii:Io,binary:Io,...Ao},an=sl;function j(t,e="utf8"){let r=an[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function z(t,e="utf8"){let r=an[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var il=parseInt("11111",2),Bo=parseInt("10000000",2),al=parseInt("01111111",2),ia={0:mr,1:mr,2:cl,3:ll,4:hl,5:fl,6:ul,16:mr,22:mr,48:mr};function ze(t,e={offset:0}){let r=t[e.offset]&il;if(e.offset++,ia[r]!=null)return ia[r](t,e);throw new Error("No decoder for tag "+r)}function br(t,e){let r=0;if((t[e.offset]&Bo)===Bo){let n=t[e.offset]&al,s="0x";e.offset++;for(let o=0;o<n;o++,e.offset++)s+=t[e.offset].toString(16).padStart(2,"0");r=parseInt(s,16)}else r=t[e.offset],e.offset++;return r}function mr(t,e){br(t,e);let r=[];for(;!(e.offset>=t.byteLength);){let n=ze(t,e);if(n===null)break;r.push(n)}return r}function cl(t,e){let r=br(t,e),n=e.offset,s=e.offset+r,o=[];for(let i=n;i<s;i++)i===n&&t[i]===0||o.push(t[i]);return e.offset+=r,Uint8Array.from(o)}function ul(t,e){let r=br(t,e),n=e.offset+r,s=t[e.offset];e.offset++;let o=0,i=0;s<40?(o=0,i=s):s<80?(o=1,i=s-40):(o=2,i=s-80);let a=`${o}.${i}`,c=[];for(;e.offset<n;){let u=t[e.offset];if(e.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let h=0;h<c.length;h++)f+=c[h]<<h*7;a+=`.${f}`,c=[]}}return a}function fl(t,e){return e.offset++,null}function ll(t,e){let r=br(t,e),n=t[e.offset];e.offset++;let s=t.subarray(e.offset,e.offset+r-1);if(e.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return s}function hl(t,e){let r=br(t,e),n=t.subarray(e.offset,e.offset+r);return e.offset+=r,n}function dl(t){let e=t.toString(16);e.length%2===1&&(e="0"+e);let r=new ae;for(let n=0;n<e.length;n+=2)r.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return r}function To(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=dl(t.byteLength);return new ae(Uint8Array.from([e.byteLength|Bo]),e)}function ye(t){let e=new ae,r=128;return(t.subarray()[0]&r)===r&&e.append(Uint8Array.from([0])),e.append(t),new ae(Uint8Array.from([2]),To(e),e)}function cn(t){let e=Uint8Array.from([0]),r=new ae(e,t);return new ae(Uint8Array.from([3]),To(r),r)}function tt(t,e=48){let r=new ae;for(let n of t)r.append(n);return new ae(Uint8Array.from([e]),To(r),r)}var pl=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),ml=Uint8Array.from([6,5,43,129,4,0,34]),bl=Uint8Array.from([6,5,43,129,4,0,35]),yl={ext:!0,kty:"EC",crv:"P-256"},gl={ext:!0,kty:"EC",crv:"P-384"},wl={ext:!0,kty:"EC",crv:"P-521"},Lo=32,Do=48,_o=66;function ko(t){let e=ze(t);return aa(e)}function aa(t){let e=t[1][1][0],r=1,n,s;if(e.byteLength===Lo*2+1)return n=z(e.subarray(r,r+Lo),"base64url"),s=z(e.subarray(r+Lo),"base64url"),new Vt({...yl,key_ops:["verify"],x:n,y:s});if(e.byteLength===Do*2+1)return n=z(e.subarray(r,r+Do),"base64url"),s=z(e.subarray(r+Do),"base64url"),new Vt({...gl,key_ops:["verify"],x:n,y:s});if(e.byteLength===_o*2+1)return n=z(e.subarray(r,r+_o),"base64url"),s=z(e.subarray(r+_o),"base64url"),new Vt({...wl,key_ops:["verify"],x:n,y:s});throw new $(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function ca(t){return tt([ye(Uint8Array.from([1])),tt([xl(t.crv)],160),tt([cn(new ae(Uint8Array.from([4]),j(t.x??"","base64url"),j(t.y??"","base64url")))],161)]).subarray()}function xl(t){if(t==="P-256")return pl;if(t==="P-384")return ml;if(t==="P-521")return bl;throw new $(`Invalid curve ${t}`)}var Vt=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=ca(this.jwk)),this._raw}toMultihash(){return Be.digest(He(this))}toCID(){return le.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ae(this.raw,e.raw)}async verify(e,r,n){return Pi(this.jwk,r,e,n)}};function Co(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}function rt(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(`${r}expected number, got ${typeof t}`)}if(!Number.isSafeInteger(t)||t<0){let r=e&&`"${e}" `;throw new RangeError(`${r}expected integer >= 0, got ${t}`)}}function ve(t,e,r=""){let n=Co(t),s=t?.length,o=e!==void 0;if(!n||o&&s!==e){let i=r&&`"${r}" `,a=o?` of length ${e}`:"",c=n?`length=${s}`:`type=${typeof t}`,u=i+"expected Uint8Array"+a+", got "+c;throw n?new RangeError(u):new TypeError(u)}return t}function un(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(rt(t.outputLen),rt(t.blockLen),t.outputLen<1)throw new Error('"outputLen" must be >= 1');if(t.blockLen<1)throw new Error('"blockLen" must be >= 1')}function zt(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function fn(t,e){ve(t,void 0,"digestInto() output");let r=e.outputLen;if(t.length<r)throw new RangeError('"digestInto() output" expected to be of length >='+r)}function je(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function ln(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Te(t,e){return t<<32-e|t>>>e}var fa=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",El=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function hn(t){if(ve(t),fa)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=El[t[r]];return e}var $e={_0:48,_9:57,A:65,F:70,a:97,f:102};function ua(t){if(t>=$e._0&&t<=$e._9)return t-$e._0;if(t>=$e.A&&t<=$e.F)return t-($e.A-10);if(t>=$e.a&&t<=$e.f)return t-($e.a-10)}function yr(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(fa)try{return Uint8Array.fromHex(t)}catch(s){throw s instanceof SyntaxError?new RangeError(s.message):s}let e=t.length,r=e/2;if(e%2)throw new RangeError("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let s=0,o=0;s<r;s++,o+=2){let i=ua(t.charCodeAt(o)),a=ua(t.charCodeAt(o+1));if(i===void 0||a===void 0){let c=t[o]+t[o+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+o)}n[s]=i*16+a}return n}function Ro(...t){let e=0;for(let n=0;n<t.length;n++){let s=t[n];ve(s),e+=s.length}let r=new Uint8Array(e);for(let n=0,s=0;n<t.length;n++){let o=t[n];r.set(o,s),s+=o.length}return r}function Po(t,e={}){let r=(s,o)=>t(o).update(s).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=s=>t(s),Object.assign(r,e),Object.freeze(r)}function dn(t=32){rt(t,"bytesLength");let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(t>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${t}`);return e.getRandomValues(new Uint8Array(t))}var No=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function la(t,e,r){return t&e^~t&r}function ha(t,e,r){return t&e^t&r^e&r}var gr=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,r,n,s){this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=s,this.buffer=new Uint8Array(e),this.view=ln(this.buffer)}update(e){zt(this),ve(e);let{view:r,buffer:n,blockLen:s}=this,o=e.length;for(let i=0;i<o;){let a=Math.min(s-this.pos,o-i);if(a===s){let c=ln(e);for(;s<=o-i;i+=s)this.process(c,i);continue}n.set(e.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===s&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){zt(this),fn(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:s,isLE:o}=this,{pos:i}=this;r[i++]=128,je(this.buffer.subarray(i)),this.padOffset>s-i&&(this.process(n,0),i=0);for(let h=i;h<s;h++)r[h]=0;n.setBigUint64(s-8,BigInt(this.length*8),o),this.process(n,0);let a=ln(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=c/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<u;h++)a.setUint32(4*h,f[h],o)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());let{blockLen:r,buffer:n,length:s,finished:o,destroyed:i,pos:a}=this;return e.destroyed=i,e.finished=o,e.length=s,e.pos=a,s%r&&e.buffer.set(n),e}clone(){return this._cloneInto()}},Ze=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ue=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var pn=BigInt(4294967295),da=BigInt(32);function vl(t,e=!1){return e?{h:Number(t&pn),l:Number(t>>da&pn)}:{h:Number(t>>da&pn)|0,l:Number(t&pn)|0}}function pa(t,e=!1){let r=t.length,n=new Uint32Array(r),s=new Uint32Array(r);for(let o=0;o<r;o++){let{h:i,l:a}=vl(t[o],e);[n[o],s[o]]=[i,a]}return[n,s]}var Oo=(t,e,r)=>t>>>r,Uo=(t,e,r)=>t<<32-r|e>>>r,pt=(t,e,r)=>t>>>r|e<<32-r,mt=(t,e,r)=>t<<32-r|e>>>r,wr=(t,e,r)=>t<<64-r|e>>>r-32,xr=(t,e,r)=>t>>>r-32|e<<64-r;function Oe(t,e,r,n){let s=(e>>>0)+(n>>>0);return{h:t+r+(s/2**32|0)|0,l:s|0}}var ma=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),ba=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,ya=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),ga=(t,e,r,n,s)=>e+r+n+s+(t/2**32|0)|0,wa=(t,e,r,n,s)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(s>>>0),xa=(t,e,r,n,s,o)=>e+r+n+s+o+(t/2**32|0)|0;var Al=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]),nt=new Uint32Array(64),Fo=class extends gr{constructor(e){super(64,e,8,!1)}get(){let{A:e,B:r,C:n,D:s,E:o,F:i,G:a,H:c}=this;return[e,r,n,s,o,i,a,c]}set(e,r,n,s,o,i,a,c){this.A=e|0,this.B=r|0,this.C=n|0,this.D=s|0,this.E=o|0,this.F=i|0,this.G=a|0,this.H=c|0}process(e,r){for(let h=0;h<16;h++,r+=4)nt[h]=e.getUint32(r,!1);for(let h=16;h<64;h++){let l=nt[h-15],d=nt[h-2],p=Te(l,7)^Te(l,18)^l>>>3,g=Te(d,17)^Te(d,19)^d>>>10;nt[h]=g+nt[h-7]+p+nt[h-16]|0}let{A:n,B:s,C:o,D:i,E:a,F:c,G:u,H:f}=this;for(let h=0;h<64;h++){let l=Te(a,6)^Te(a,11)^Te(a,25),d=f+l+la(a,c,u)+Al[h]+nt[h]|0,g=(Te(n,2)^Te(n,13)^Te(n,22))+ha(n,s,o)|0;f=u,u=c,c=a,a=i+d|0,i=o,o=s,s=n,n=d+g|0}n=n+this.A|0,s=s+this.B|0,o=o+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,s,o,i,a,c,u,f)}roundClean(){je(nt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),je(this.buffer)}},Ko=class extends Fo{A=Ze[0]|0;B=Ze[1]|0;C=Ze[2]|0;D=Ze[3]|0;E=Ze[4]|0;F=Ze[5]|0;G=Ze[6]|0;H=Ze[7]|0;constructor(){super(32)}};var Ea=pa(["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(t=>BigInt(t))),Il=Ea[0],Bl=Ea[1],ot=new Uint32Array(80),st=new Uint32Array(80),Mo=class extends gr{constructor(e){super(128,e,16,!1)}get(){let{Ah:e,Al:r,Bh:n,Bl:s,Ch:o,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:h,Fl:l,Gh:d,Gl:p,Hh:g,Hl:b}=this;return[e,r,n,s,o,i,a,c,u,f,h,l,d,p,g,b]}set(e,r,n,s,o,i,a,c,u,f,h,l,d,p,g,b){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=s|0,this.Ch=o|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=h|0,this.Fl=l|0,this.Gh=d|0,this.Gl=p|0,this.Hh=g|0,this.Hl=b|0}process(e,r){for(let S=0;S<16;S++,r+=4)ot[S]=e.getUint32(r),st[S]=e.getUint32(r+=4);for(let S=16;S<80;S++){let L=ot[S-15]|0,T=st[S-15]|0,R=pt(L,T,1)^pt(L,T,8)^Oo(L,T,7),k=mt(L,T,1)^mt(L,T,8)^Uo(L,T,7),B=ot[S-2]|0,N=st[S-2]|0,V=pt(B,N,19)^wr(B,N,61)^Oo(B,N,6),O=mt(B,N,19)^xr(B,N,61)^Uo(B,N,6),m=ya(k,O,st[S-7],st[S-16]),w=ga(m,R,V,ot[S-7],ot[S-16]);ot[S]=w|0,st[S]=m|0}let{Ah:n,Al:s,Bh:o,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:h,El:l,Fh:d,Fl:p,Gh:g,Gl:b,Hh:y,Hl:v}=this;for(let S=0;S<80;S++){let L=pt(h,l,14)^pt(h,l,18)^wr(h,l,41),T=mt(h,l,14)^mt(h,l,18)^xr(h,l,41),R=h&d^~h&g,k=l&p^~l&b,B=wa(v,T,k,Bl[S],st[S]),N=xa(B,y,L,R,Il[S],ot[S]),V=B|0,O=pt(n,s,28)^wr(n,s,34)^wr(n,s,39),m=mt(n,s,28)^xr(n,s,34)^xr(n,s,39),w=n&o^n&a^o&a,A=s&i^s&c^i&c;y=g|0,v=b|0,g=d|0,b=p|0,d=h|0,p=l|0,{h,l}=Oe(u|0,f|0,N|0,V|0),u=a|0,f=c|0,a=o|0,c=i|0,o=n|0,i=s|0;let E=ma(V,m,A);n=ba(E,N,O,w),s=E|0}({h:n,l:s}=Oe(this.Ah|0,this.Al|0,n|0,s|0)),{h:o,l:i}=Oe(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=Oe(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=Oe(this.Dh|0,this.Dl|0,u|0,f|0),{h,l}=Oe(this.Eh|0,this.El|0,h|0,l|0),{h:d,l:p}=Oe(this.Fh|0,this.Fl|0,d|0,p|0),{h:g,l:b}=Oe(this.Gh|0,this.Gl|0,g|0,b|0),{h:y,l:v}=Oe(this.Hh|0,this.Hl|0,y|0,v|0),this.set(n,s,o,i,a,c,u,f,h,l,d,p,g,b,y,v)}roundClean(){je(ot,st)}destroy(){this.destroyed=!0,je(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},qo=class extends Mo{Ah=ue[0]|0;Al=ue[1]|0;Bh=ue[2]|0;Bl=ue[3]|0;Ch=ue[4]|0;Cl=ue[5]|0;Dh=ue[6]|0;Dl=ue[7]|0;Eh=ue[8]|0;El=ue[9]|0;Fh=ue[10]|0;Fl=ue[11]|0;Gh=ue[12]|0;Gl=ue[13]|0;Hh=ue[14]|0;Hl=ue[15]|0;constructor(){super(64)}};var Ht=Po(()=>new Ko,No(1));var mn=Po(()=>new qo,No(3));var K=(t,e,r)=>ve(t,e,r),zo=rt,$t=hn,oe=(...t)=>Ro(...t),jt=t=>yr(t),bt=Co,Er=t=>dn(t),yn=BigInt(0),Vo=BigInt(1);function Le(t,e=""){if(typeof t!="boolean"){let r=e&&`"${e}" `;throw new TypeError(r+"expected boolean, got type="+typeof t)}return t}function gn(t){if(typeof t=="bigint"){if(!bn(t))throw new RangeError("positive bigint expected, got "+t)}else zo(t);return t}function De(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(r+"expected number, got type="+typeof t)}if(!Number.isSafeInteger(t)){let r=e&&`"${e}" `;throw new RangeError(r+"expected safe integer, got "+t)}}function vr(t){let e=gn(t).toString(16);return e.length&1?"0"+e:e}function va(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?yn:BigInt("0x"+t)}function yt(t){return va(hn(t))}function Ue(t){return va(hn(Sr(ve(t)).reverse()))}function wn(t,e){if(rt(e),e===0)throw new RangeError("zero length");t=gn(t);let r=t.toString(16);if(r.length>e*2)throw new RangeError("number too large");return yr(r.padStart(e*2,"0"))}function Ho(t,e){return wn(t,e).reverse()}function Sa(t,e){if(t=K(t),e=K(e),t.length!==e.length)return!1;let r=0;for(let n=0;n<t.length;n++)r|=t[n]^e[n];return r===0}function Sr(t){return Uint8Array.from(K(t))}function xn(t){if(typeof t!="string")throw new TypeError("ascii string expected, got "+typeof t);return Uint8Array.from(t,(e,r)=>{let n=e.charCodeAt(0);if(e.length!==1||n>127)throw new RangeError(`string contains non-ASCII character "${t[r]}" with code ${n} at position ${r}`);return n})}var bn=t=>typeof t=="bigint"&&yn<=t;function Tl(t,e,r){return bn(t)&&bn(e)&&bn(r)&&e<=t&&t<r}function Zt(t,e,r,n){if(!Tl(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function Yt(t){if(t<yn)throw new Error("expected non-negative bigint, got "+t);let e;for(e=0;t>yn;t>>=Vo,e+=1);return e}var Ar=t=>(Vo<<BigInt(t))-Vo;function Aa(t,e,r){if(rt(t,"hashLen"),rt(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=b=>new Uint8Array(b),s=Uint8Array.of(),o=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(t),u=n(t),f=0,h=()=>{c.fill(1),u.fill(0),f=0},l=(...b)=>r(u,oe(c,...b)),d=(b=s)=>{u=l(o,b),c=l(),b.length!==0&&(u=l(i,b),c=l())},p=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let b=0,y=[];for(;b<e;){c=l();let v=c.slice();y.push(v),b+=c.length}return oe(...y)};return(b,y)=>{h(),d(b);let v;for(;(v=y(p()))===void 0;)d();return h(),v}}function _e(t,e={},r={}){if(Object.prototype.toString.call(t)!=="[object Object]")throw new TypeError("expected valid options object");function n(o,i,a){if(!a&&i!=="function"&&!Object.hasOwn(t,o))throw new TypeError(`param "${o}" is invalid: expected own property`);let c=t[o];if(a&&c===void 0)return;let u=typeof c;if(u!==i||c===null)throw new TypeError(`param "${o}" is invalid: expected ${i}, got ${u}`)}let s=(o,i)=>Object.entries(o).forEach(([a,c])=>n(a,c,i));s(e,!1),s(r,!0)}var $o=()=>{throw new Error("not implemented")};var fe=BigInt(0),J=BigInt(1),gt=BigInt(2),La=BigInt(3),Da=BigInt(4),_a=BigInt(5),Ll=BigInt(7),ka=BigInt(8),Dl=BigInt(9),Ca=BigInt(16);function te(t,e){if(e<=fe)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=fe?r:e+r}function Z(t,e,r){if(e<fe)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >fe;)n*=n,n%=r;return n}function Ia(t,e){if(t===fe)throw new Error("invert: expected non-zero number");if(e<=fe)throw new Error("invert: expected positive modulus, got "+e);let r=te(t,e),n=e,s=fe,o=J,i=J,a=fe;for(;r!==fe;){let u=n/r,f=n-r*u,h=s-i*u,l=o-a*u;n=r,r=f,s=i,o=a,i=h,a=l}if(n!==J)throw new Error("invert: does not exist");return te(s,e)}function jo(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function Ra(t,e){let r=t,n=(r.ORDER+J)/Da,s=r.pow(e,n);return jo(r,s,e),s}function _l(t,e){let r=t,n=(r.ORDER-_a)/ka,s=r.mul(e,gt),o=r.pow(s,n),i=r.mul(e,o),a=r.mul(r.mul(i,gt),o),c=r.mul(i,r.sub(a,r.ONE));return jo(r,c,e),c}function kl(t){let e=Gt(t),r=Pa(t),n=r(e,e.neg(e.ONE)),s=r(e,n),o=r(e,e.neg(n)),i=(t+Ll)/Ca;return((a,c)=>{let u=a,f=u.pow(c,i),h=u.mul(f,n),l=u.mul(f,s),d=u.mul(f,o),p=u.eql(u.sqr(h),c),g=u.eql(u.sqr(l),c);f=u.cmov(f,h,p),h=u.cmov(d,l,g);let b=u.eql(u.sqr(h),c),y=u.cmov(f,h,b);return jo(u,y,c),y})}function Pa(t){if(t<La)throw new Error("sqrt is not defined for small field");let e=t-J,r=0;for(;e%gt===fe;)e/=gt,r++;let n=gt,s=Gt(t);for(;Ba(s,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Ra;let o=s.pow(n,e),i=(e+J)/gt;return function(c,u){let f=c;if(f.is0(u))return u;if(Ba(f,u)!==1)throw new Error("Cannot find square root");let h=r,l=f.mul(f.ONE,o),d=f.pow(u,e),p=f.pow(u,i);for(;!f.eql(d,f.ONE);){if(f.is0(d))return f.ZERO;let g=1,b=f.sqr(d);for(;!f.eql(b,f.ONE);)if(g++,b=f.sqr(b),g===h)throw new Error("Cannot find square root");let y=J<<BigInt(h-g-1),v=f.pow(l,y);h=g,l=f.sqr(v),d=f.mul(d,l),p=f.mul(p,v)}return p}}function Cl(t){return t%Da===La?Ra:t%ka===_a?_l:t%Ca===Dl?kl(t):Pa(t)}var Ye=(t,e)=>(te(t,e)&J)===J,Rl=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Zo(t){let e={ORDER:"bigint",BYTES:"number",BITS:"number"},r=Rl.reduce((n,s)=>(n[s]="function",n),e);if(_e(t,r),De(t.BYTES,"BYTES"),De(t.BITS,"BITS"),t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=J)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function Pl(t,e,r){let n=t;if(r<fe)throw new Error("invalid exponent, negatives unsupported");if(r===fe)return n.ONE;if(r===J)return e;let s=n.ONE,o=e;for(;r>fe;)r&J&&(s=n.mul(s,o)),o=n.sqr(o),r>>=J;return s}function Ir(t,e,r=!1){let n=t,s=new Array(e.length).fill(r?n.ZERO:void 0),o=e.reduce((a,c,u)=>n.is0(c)?a:(s[u]=a,n.mul(a,c)),n.ONE),i=n.inv(o);return e.reduceRight((a,c,u)=>n.is0(c)?a:(s[u]=n.mul(a,s[u]),n.mul(a,c)),i),s}function Ba(t,e){let r=t,n=(r.ORDER-J)/gt,s=r.pow(e,n),o=r.eql(s,r.ONE),i=r.eql(s,r.ZERO),a=r.eql(s,r.neg(r.ONE));if(!o&&!i&&!a)throw new Error("invalid Legendre symbol result");return o?1:i?0:-1}function Nl(t,e){if(e!==void 0&&zo(e),t<=fe)throw new Error("invalid n length: expected positive n, got "+t);if(e!==void 0&&e<1)throw new Error("invalid n length: expected positive bit length, got "+e);let r=Yt(t);if(e!==void 0&&e<r)throw new Error(`invalid n length: expected bit length (${r}) >= n.length (${e})`);let n=e!==void 0?e:r,s=Math.ceil(n/8);return{nBitLength:n,nByteLength:s}}var Ta=new WeakMap,En=class{ORDER;BITS;BYTES;isLE;ZERO=fe;ONE=J;_lengths;_mod;constructor(e,r={}){if(e<=J)throw new Error("invalid field: expected ORDER > 1, got "+e);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:s,nByteLength:o}=Nl(e,n);if(o>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=s,this.BYTES=o,Object.freeze(this)}create(e){return te(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return fe<=e&&e<this.ORDER}is0(e){return e===fe}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&J)===J}neg(e){return te(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return te(e*e,this.ORDER)}add(e,r){return te(e+r,this.ORDER)}sub(e,r){return te(e-r,this.ORDER)}mul(e,r){return te(e*r,this.ORDER)}pow(e,r){return Pl(this,e,r)}div(e,r){return te(e*Ia(r,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,r){return e+r}subN(e,r){return e-r}mulN(e,r){return e*r}inv(e){return Ia(e,this.ORDER)}sqrt(e){let r=Ta.get(this);return r||Ta.set(this,r=Cl(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?Ho(e,this.BYTES):wn(e,this.BYTES)}fromBytes(e,r=!1){K(e);let{_lengths:n,BYTES:s,isLE:o,ORDER:i,_mod:a}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>s)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let u=new Uint8Array(s);u.set(e,o?0:u.length-e.length),e=u}if(e.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+e.length);let c=o?Ue(e):yt(e);if(a&&(c=te(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return Ir(this,e)}cmov(e,r,n){return Le(n,"condition"),n?r:e}};Object.freeze(En.prototype);function Gt(t,e={}){return new En(t,e)}function Na(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=J)throw new Error("field order must be greater than 1");let e=Yt(t-J);return Math.ceil(e/8)}function Yo(t){let e=Na(t);return e+Math.ceil(e/2)}function Go(t,e,r=!1){K(t);let n=t.length,s=Na(e),o=Math.max(Yo(e),16);if(n<o||n>1024)throw new Error("expected "+o+"-1024 bytes of input, got "+n);let i=r?Ue(t):yt(t),a=te(i,e-J)+J;return r?Ho(a,s):wn(a,s)}var Xt=BigInt(0),wt=BigInt(1);function Br(t,e){let r=e.negate();return t?r:e}function xt(t,e){let r=Ir(t.Fp,e.map(n=>n.Z));return e.map((n,s)=>t.fromAffine(n.toAffine(r[s])))}function Ka(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function Xo(t,e){Ka(t,e);let r=Math.ceil(e/t)+1,n=2**(t-1),s=2**t,o=Ar(t),i=BigInt(t);return{windows:r,windowSize:n,mask:o,maxNumber:s,shiftBy:i}}function Oa(t,e,r){let{windowSize:n,mask:s,maxNumber:o,shiftBy:i}=r,a=Number(t&s),c=t>>i;a>n&&(a-=o,c+=wt);let u=e*n,f=u+Math.abs(a)-1,h=a===0,l=a<0,d=e%2!==0;return{nextN:c,offset:f,isZero:h,isNeg:l,isNegF:d,offsetF:u}}var Wo=new WeakMap,Ma=new WeakMap;function Jo(t){return Ma.get(t)||1}function Ua(t){if(t!==Xt)throw new Error("invalid wNAF")}var Wt=class{BASE;ZERO;Fn;bits;constructor(e,r){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=r}_unsafeLadder(e,r,n=this.ZERO){let s=e;for(;r>Xt;)r&wt&&(n=n.add(s)),s=s.double(),r>>=wt;return n}precomputeWindow(e,r){let{windows:n,windowSize:s}=Xo(r,this.bits),o=[],i=e,a=i;for(let c=0;c<n;c++){a=i,o.push(a);for(let u=1;u<s;u++)a=a.add(i),o.push(a);i=a.double()}return o}wNAF(e,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let s=this.ZERO,o=this.BASE,i=Xo(e,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:u,isZero:f,isNeg:h,isNegF:l,offsetF:d}=Oa(n,a,i);n=c,f?o=o.add(Br(l,r[d])):s=s.add(Br(h,r[u]))}return Ua(n),{p:s,f:o}}wNAFUnsafe(e,r,n,s=this.ZERO){let o=Xo(e,this.bits);for(let i=0;i<o.windows&&n!==Xt;i++){let{nextN:a,offset:c,isZero:u,isNeg:f}=Oa(n,i,o);if(n=a,!u){let h=r[c];s=s.add(f?h.negate():h)}}return Ua(n),s}getPrecomputes(e,r,n){let s=Wo.get(r);return s||(s=this.precomputeWindow(r,e),e!==1&&(typeof n=="function"&&(s=n(s)),Wo.set(r,s))),s}cached(e,r,n){let s=Jo(e);return this.wNAF(s,this.getPrecomputes(s,e,n),r)}unsafe(e,r,n,s){let o=Jo(e);return o===1?this._unsafeLadder(e,r,s):this.wNAFUnsafe(o,this.getPrecomputes(o,e,n),r,s)}createCache(e,r){Ka(r,this.bits),Ma.set(e,r),Wo.delete(e)}hasCache(e){return Jo(e)!==1}};function qa(t,e,r,n){let s=e,o=t.ZERO,i=t.ZERO;for(;r>Xt||n>Xt;)r&wt&&(o=o.add(s)),n&wt&&(i=i.add(s)),s=s.double(),r>>=wt,n>>=wt;return{p1:o,p2:i}}function Fa(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Zo(e),e}else return Gt(t,{isLE:r})}function vn(t,e,r={},n){if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);for(let c of["p","n","h"]){let u=e[c];if(!(typeof u=="bigint"&&u>Xt))throw new Error(`CURVE.${c} must be positive bigint`)}let s=Fa(e.p,r.Fp,n),o=Fa(e.n,r.Fn,n),a=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let c of a)if(!s.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:s,Fn:o}}function Sn(t,e){return function(n){let s=t(n);return{secretKey:s,publicKey:e(s)}}}var it=BigInt(0),ce=BigInt(1),Qo=BigInt(2),Ol=BigInt(8);function Ul(t,e,r,n){let s=t.sqr(r),o=t.sqr(n),i=t.add(t.mul(e.a,s),o),a=t.add(t.ONE,t.mul(e.d,t.mul(s,o)));return t.eql(i,a)}function Va(t,e={}){let r=e,n=vn("edwards",t,r,r.FpFnLE),{Fp:s,Fn:o}=n,i=n.CURVE,{h:a}=i;_e(r,{},{uvRatio:"function"});let c=Qo<<BigInt(o.BYTES*8)-ce,u=g=>s.create(g),f=r.uvRatio===void 0?(g,b)=>{try{return{isValid:!0,value:s.sqrt(s.div(g,b))}}catch{return{isValid:!1,value:it}}}:r.uvRatio;if(!Ul(s,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function h(g,b,y=!1){let v=y?ce:it;return Zt("coordinate "+g,b,v,c),b}function l(g){if(!(g instanceof d))throw new Error("EdwardsPoint expected")}class d{static BASE=new d(i.Gx,i.Gy,ce,u(i.Gx*i.Gy));static ZERO=new d(it,ce,ce,it);static Fp=s;static Fn=o;X;Y;Z;T;constructor(b,y,v,S){this.X=h("x",b),this.Y=h("y",y),this.Z=h("z",v,!0),this.T=h("t",S),Object.freeze(this)}static CURVE(){return i}static fromAffine(b){if(b instanceof d)throw new Error("extended point not allowed");let{x:y,y:v}=b||{};return h("x",y),h("y",v),new d(y,v,ce,u(y*v))}static fromBytes(b,y=!1){let v=s.BYTES,{a:S,d:L}=i;b=Sr(K(b,v,"point")),Le(y,"zip215");let T=Sr(b),R=b[v-1];T[v-1]=R&-129;let k=Ue(T),B=y?c:s.ORDER;Zt("point.y",k,it,B);let N=u(k*k),V=u(N-ce),O=u(L*N-S),{isValid:m,value:w}=f(V,O);if(!m)throw new Error("bad point: invalid y coordinate");let A=(w&ce)===ce,E=(R&128)!==0;if(!y&&w===it&&E)throw new Error("bad point: x=0 and x_0=1");return E!==A&&(w=u(-w)),d.fromAffine({x:w,y:k})}static fromHex(b,y=!1){return d.fromBytes(jt(b),y)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=8,y=!0){return p.createCache(this,b),y||this.multiply(Qo),this}assertValidity(){let b=this,{a:y,d:v}=i;if(b.is0())throw new Error("bad point: ZERO");let{X:S,Y:L,Z:T,T:R}=b,k=u(S*S),B=u(L*L),N=u(T*T),V=u(N*N),O=u(k*y),m=u(N*u(O+B)),w=u(V+u(v*u(k*B)));if(m!==w)throw new Error("bad point: equation left != right (1)");let A=u(S*L),E=u(T*R);if(A!==E)throw new Error("bad point: equation left != right (2)")}equals(b){l(b);let{X:y,Y:v,Z:S}=this,{X:L,Y:T,Z:R}=b,k=u(y*R),B=u(L*S),N=u(v*R),V=u(T*S);return k===B&&N===V}is0(){return this.equals(d.ZERO)}negate(){return new d(u(-this.X),this.Y,this.Z,u(-this.T))}double(){let{a:b}=i,{X:y,Y:v,Z:S}=this,L=u(y*y),T=u(v*v),R=u(Qo*u(S*S)),k=u(b*L),B=y+v,N=u(u(B*B)-L-T),V=k+T,O=V-R,m=k-T,w=u(N*O),A=u(V*m),E=u(N*m),x=u(O*V);return new d(w,A,x,E)}add(b){l(b);let{a:y,d:v}=i,{X:S,Y:L,Z:T,T:R}=this,{X:k,Y:B,Z:N,T:V}=b,O=u(S*k),m=u(L*B),w=u(R*v*V),A=u(T*N),E=u((S+L)*(k+B)-O-m),x=A-w,I=A+w,_=u(m-y*O),D=u(E*x),C=u(I*_),P=u(E*_),F=u(x*I);return new d(D,C,F,P)}subtract(b){return l(b),this.add(b.negate())}multiply(b){if(!o.isValidNot0(b))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:y,f:v}=p.cached(this,b,S=>xt(d,S));return xt(d,[y,v])[0]}multiplyUnsafe(b){if(!o.isValid(b))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return b===it?d.ZERO:this.is0()||b===ce?this:p.unsafe(this,b,y=>xt(d,y))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return p.unsafe(this,i.n).is0()}toAffine(b){let y=this,v=b,{X:S,Y:L,Z:T}=y,R=y.is0();v==null&&(v=R?Ol:s.inv(T));let k=u(S*v),B=u(L*v),N=s.mul(T,v);if(R)return{x:it,y:ce};if(N!==ce)throw new Error("invZ was invalid");return{x:k,y:B}}clearCofactor(){return a===ce?this:this.multiplyUnsafe(a)}toBytes(){let{x:b,y}=this.toAffine(),v=s.toBytes(y);return v[v.length-1]|=b&ce?128:0,v}toHex(){return $t(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let p=new Wt(d,o.BITS);return o.BITS>=8&&d.BASE.precompute(8),Object.freeze(d.prototype),Object.freeze(d),d}var An=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(e){this.ep=e}static fromBytes(e){$o()}static fromHex(e){$o()}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 $t(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,r){return this.ep.precompute(e,r),this}};function za(t,e,r={}){if(typeof e!="function")throw new Error('"hash" function param is required');let n=e,s=r;_e(s,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function"});let{prehash:o}=s,{BASE:i,Fp:a,Fn:c}=t,u=n.outputLen,f=2*a.BYTES;if(u!==void 0&&(De(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let h=s.randomBytes===void 0?Er:s.randomBytes,l=s.adjustScalarBytes===void 0?m=>m:s.adjustScalarBytes,d=s.domain===void 0?(m,w,A)=>{if(Le(A,"phflag"),w.length||A)throw new Error("Contexts/pre-hash are not supported");return m}:s.domain;function p(m){return c.create(Ue(m))}function g(m){let w=k.secretKey;K(m,k.secretKey,"secretKey");let A=K(n(m),2*w,"hashedSecretKey"),E=l(A.slice(0,w)),x=A.slice(w,2*w),I=p(E);return{head:E,prefix:x,scalar:I}}function b(m){let{head:w,prefix:A,scalar:E}=g(m),x=i.multiply(E),I=x.toBytes();return{head:w,prefix:A,scalar:E,point:x,pointBytes:I}}function y(m){return b(m).pointBytes}function v(m=Uint8Array.of(),...w){let A=oe(...w);return p(n(d(A,K(m,void 0,"context"),!!o)))}function S(m,w,A={}){m=K(m,void 0,"message"),o&&(m=o(m));let{prefix:E,scalar:x,pointBytes:I}=b(w),_=v(A.context,E,m),D=i.multiply(_).toBytes(),C=v(A.context,D,I,m),P=c.create(_+C*x);if(!c.isValid(P))throw new Error("sign failed: invalid s");let F=oe(D,c.toBytes(P));return K(F,k.signature,"result")}let L={zip215:s.zip215};function T(m,w,A,E=L){let{context:x}=E,I=E.zip215===void 0?!!L.zip215:E.zip215,_=k.signature;m=K(m,_,"signature"),w=K(w,void 0,"message"),A=K(A,k.publicKey,"publicKey"),I!==void 0&&Le(I,"zip215"),o&&(w=o(w));let D=_/2,C=m.subarray(0,D),P=Ue(m.subarray(D,_)),F,M,U;try{F=t.fromBytes(A,I),M=t.fromBytes(C,I),U=i.multiplyUnsafe(P)}catch{return!1}if(!I&&F.isSmallOrder())return!1;let ne=v(x,C,A,w);return M.add(F.multiplyUnsafe(ne)).subtract(U).clearCofactor().is0()}let R=a.BYTES,k={secretKey:R,publicKey:R,signature:2*R,seed:R};function B(m){return m=m===void 0?h(k.seed):m,K(m,k.seed,"seed")}function N(m){return bt(m)&&m.length===k.secretKey}function V(m,w){try{return!!t.fromBytes(m,w===void 0?L.zip215:w)}catch{return!1}}let O={getExtendedPublicKey:b,randomSecretKey:B,isValidSecretKey:N,isValidPublicKey:V,toMontgomery(m){let{y:w}=t.fromBytes(m),A=k.publicKey,E=A===32;if(!E&&A!==57)throw new Error("only defined for 25519 and 448");let x=E?a.div(ce+w,ce-w):a.div(w-ce,w+ce);return a.toBytes(x)},toMontgomerySecret(m){let w=k.secretKey;K(m,w);let A=n(m.subarray(0,w));return l(A).subarray(0,w)}};return Object.freeze(k),Object.freeze(O),Object.freeze({keygen:Sn(B,y),getPublicKey:y,sign:S,verify:T,utils:O,Point:t,lengths:k})}function Tr(t,e){if(De(t),De(e),e<0||e>4)throw new Error("invalid I2OSP length: "+e);if(t<0||t>2**(8*e)-1)throw new Error("invalid I2OSP input: "+t);let r=Array.from({length:e}).fill(0);for(let n=e-1;n>=0;n--)r[n]=t&255,t>>>=8;return new Uint8Array(r)}function Fl(t,e){let r=new Uint8Array(t.length);for(let n=0;n<t.length;n++)r[n]=t[n]^e[n];return r}function Kl(t){if(!bt(t)&&typeof t!="string")throw new Error("DST must be Uint8Array or ascii string");let e=typeof t=="string"?xn(t):t;if(e.length===0)throw new Error("DST must be non-empty");return e}function es(t,e,r,n){K(t),De(r),e=Kl(e),e.length>255&&(e=n(oe(xn("H2C-OVERSIZE-DST-"),e)));let{outputLen:s,blockLen:o}=n,i=Math.ceil(r/s);if(r>65535||i>255)throw new Error("expand_message_xmd: invalid lenInBytes");let a=oe(e,Tr(e.length,1)),c=new Uint8Array(o),u=Tr(r,2),f=new Array(i),h=n(oe(c,t,u,Tr(0,1),a));f[0]=n(oe(h,Tr(1,1),a));for(let d=1;d<i;d++){let p=[Fl(h,f[d-1]),Tr(d+1,1),a];f[d]=n(oe(...p))}return oe(...f).slice(0,r)}var Ha="HashToScalar-";var Ml=BigInt(0),Ge=BigInt(1),$a=BigInt(2);var ql=BigInt(5),Vl=BigInt(8),Jt=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),os={p:Jt,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Vl,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function zl(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),s=BigInt(80),o=Jt,a=t*t%o*t%o,c=Z(a,$a,o)*a%o,u=Z(c,Ge,o)*t%o,f=Z(u,ql,o)*u%o,h=Z(f,e,o)*f%o,l=Z(h,r,o)*h%o,d=Z(l,n,o)*l%o,p=Z(d,s,o)*d%o,g=Z(p,s,o)*d%o,b=Z(g,e,o)*f%o;return{pow_p_5_8:Z(b,$a,o)*t%o,b2:a}}function Hl(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var ts=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function ss(t,e){let r=Jt,n=te(e*e*e,r),s=te(n*n*e,r),o=zl(t*s).pow_p_5_8,i=te(t*n*o,r),a=te(e*i*i,r),c=i,u=te(i*ts,r),f=a===t,h=a===te(-t,r),l=a===te(-t*ts,r);return f&&(i=c),(h||l)&&(i=u),Ye(i,r)&&(i=te(-i,r)),{isValid:f||h,value:i}}var ct=Va(os,{uvRatio:ss}),at=ct.Fp,Ya=ct.Fn;function $l(t){return za(ct,mn,Object.assign({adjustScalarBytes:Hl,zip215:!0},t))}var Ga=$l({});var rs=ts,jl=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Zl=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Yl=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Gl=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),ja=t=>ss(Ge,t),Xl=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),ns=t=>at.create(Ue(t)&Xl);function Za(t){let{d:e}=os,r=Jt,n=y=>at.create(y),s=n(rs*t*t),o=n((s+Ge)*Yl),i=BigInt(-1),a=n((i-e*s)*n(s+e)),{isValid:c,value:u}=ss(o,a),f=n(u*t);Ye(f,r)||(f=n(-f)),c||(u=f),c||(i=s);let h=n(i*(s-Ge)*Gl-a),l=u*u,d=n((u+u)*a),p=n(h*jl),g=n(Ge-l),b=n(Ge+l);return new ct(n(d*b),n(g*p),n(p*b),n(d*g))}var ut=class t extends An{static BASE=new t(ct.BASE);static ZERO=new t(ct.ZERO);static Fp=at;static Fn=Ya;constructor(e){super(e)}static fromAffine(e){return new t(ct.fromAffine(e))}assertSame(e){if(!(e instanceof t))throw new Error("RistrettoPoint expected")}init(e){return new t(e)}static fromBytes(e){ve(e,32);let{a:r,d:n}=os,s=Jt,o=L=>at.create(L),i=ns(e);if(!Sa(at.toBytes(i),e)||Ye(i,s))throw new Error("invalid ristretto255 encoding 1");let a=o(i*i),c=o(Ge+r*a),u=o(Ge-r*a),f=o(c*c),h=o(u*u),l=o(r*n*f-h),{isValid:d,value:p}=ja(o(l*h)),g=o(p*u),b=o(p*g*l),y=o((i+i)*g);Ye(y,s)&&(y=o(-y));let v=o(c*b),S=o(y*v);if(!d||Ye(S,s)||v===Ml)throw new Error("invalid ristretto255 encoding 2");return new t(new ct(y,v,Ge,S))}static fromHex(e){return t.fromBytes(yr(e))}toBytes(){let{X:e,Y:r,Z:n,T:s}=this.ep,o=Jt,i=b=>at.create(b),a=i(i(n+r)*i(n-r)),c=i(e*r),u=i(c*c),{value:f}=ja(i(a*u)),h=i(f*a),l=i(f*c),d=i(h*l*s),p;if(Ye(s*d,o)){let b=i(r*rs),y=i(e*rs);e=b,r=y,p=i(h*Zl)}else p=l;Ye(e*d,o)&&(r=i(-r));let g=i((n-r)*p);return Ye(g,o)&&(g=i(-g)),at.toBytes(g)}equals(e){this.assertSame(e);let{X:r,Y:n}=this.ep,{X:s,Y:o}=e.ep,i=u=>at.create(u),a=i(r*o)===i(n*s),c=i(n*o)===i(r*s);return a||c}is0(){return this.equals(t.ZERO)}};Object.freeze(ut.BASE);Object.freeze(ut.ZERO);Object.freeze(ut.prototype);Object.freeze(ut);var Wl=Object.freeze({Point:ut,hashToCurve(t,e){let r=e?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":e.DST,n=es(t,r,64,mn);return Wl.deriveToCurve(n)},hashToScalar(t,e={DST:Ha}){let r=es(t,e.DST,64,mn);return Ya.create(Ue(r))},deriveToCurve(t){ve(t,64);let e=ns(t.subarray(0,32)),r=Za(e),n=ns(t.subarray(32,64)),s=Za(n);return new ut(r.add(s))}});var Lr=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},In=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var Ie={get(t=globalThis){let e=t.crypto;if(e?.subtle==null)throw new In("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 Bn=32;var is,Jl=(async()=>{try{return await Ie.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Ql(t,e,r){if(t.buffer instanceof ArrayBuffer){let n=await Ie.get().subtle.importKey("raw",t.buffer,{name:"Ed25519"},!1,["verify"]);return await Ie.get().subtle.verify({name:"Ed25519"},n,Pe(e),Pe(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function eh(t,e,r){return Ga.verify(e,r instanceof Uint8Array?r:r.subarray(),t)}async function Xa(t,e,r){return is==null&&(is=await Jl),is?Ql(t,e,r):eh(t,e,r)}function th(t){return t?.buffer instanceof ArrayBuffer}function Ja(t){if(th(t))return t;let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function Tn(t,e){e==null&&(e=t.reduce((s,o)=>s+o.length,0));let r=sn(e),n=0;for(let s of t)r.set(s,n),n+=s.length;return Ja(r)}function Ln(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var Dn=class{type="Ed25519";raw;constructor(e){this.raw=as(e,Bn)}toMultihash(){return Be.digest(He(this))}toCID(){return le.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ae(this.raw,e.raw)}verify(e,r,n){n?.signal?.throwIfAborted();let s=Xa(this.raw,r,e);return Ln(s)?s.then(o=>(n?.signal?.throwIfAborted(),o)):s}};function cs(t){return t=as(t,Bn),new Dn(t)}function as(t,e){if(t=Uint8Array.from(t??[]),t.length!==e)throw new $(`Key must be a Uint8Array of length ${e}, got ${t.length}`);return t}function Qa(t=0){return new Uint8Array(t)}var nh=Math.pow(2,7),oh=Math.pow(2,14),sh=Math.pow(2,21),us=Math.pow(2,28),fs=Math.pow(2,35),ls=Math.pow(2,42),hs=Math.pow(2,49),q=128,he=127;function Xe(t){if(t<nh)return 1;if(t<oh)return 2;if(t<sh)return 3;if(t<us)return 4;if(t<fs)return 5;if(t<ls)return 6;if(t<hs)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ds(t,e,r=0){switch(Xe(t)){case 8:e[r++]=t&255|q,t/=128;case 7:e[r++]=t&255|q,t/=128;case 6:e[r++]=t&255|q,t/=128;case 5:e[r++]=t&255|q,t/=128;case 4:e[r++]=t&255|q,t>>>=7;case 3:e[r++]=t&255|q,t>>>=7;case 2:e[r++]=t&255|q,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function ih(t,e,r=0){switch(Xe(t)){case 8:e.set(r++,t&255|q),t/=128;case 7:e.set(r++,t&255|q),t/=128;case 6:e.set(r++,t&255|q),t/=128;case 5:e.set(r++,t&255|q),t/=128;case 4:e.set(r++,t&255|q),t>>>=7;case 3:e.set(r++,t&255|q),t>>>=7;case 2:e.set(r++,t&255|q),t>>>=7;case 1:{e.set(r++,t&255),t>>>=7;break}default:throw new Error("unreachable")}return e}function ps(t,e){let r=t[e],n=0;if(n+=r&he,r<q||(r=t[e+1],n+=(r&he)<<7,r<q)||(r=t[e+2],n+=(r&he)<<14,r<q)||(r=t[e+3],n+=(r&he)<<21,r<q)||(r=t[e+4],n+=(r&he)*us,r<q)||(r=t[e+5],n+=(r&he)*fs,r<q)||(r=t[e+6],n+=(r&he)*ls,r<q)||(r=t[e+7],n+=(r&he)*hs,r<q))return n;throw new RangeError("Could not decode varint")}function ah(t,e){let r=t.get(e),n=0;if(n+=r&he,r<q||(r=t.get(e+1),n+=(r&he)<<7,r<q)||(r=t.get(e+2),n+=(r&he)<<14,r<q)||(r=t.get(e+3),n+=(r&he)<<21,r<q)||(r=t.get(e+4),n+=(r&he)*us,r<q)||(r=t.get(e+5),n+=(r&he)*fs,r<q)||(r=t.get(e+6),n+=(r&he)*ls,r<q)||(r=t.get(e+7),n+=(r&he)*hs,r<q))return n;throw new RangeError("Could not decode varint")}function ec(t,e,r=0){return e==null&&(e=Qa(Xe(t))),e instanceof Uint8Array?ds(t,e,r):ih(t,e,r)}function tc(t,e=0){return t instanceof Uint8Array?ps(t,e):ah(t,e)}var ms=new Float32Array([-0]),ft=new Uint8Array(ms.buffer);function rc(t,e,r){ms[0]=t,e[r]=ft[0],e[r+1]=ft[1],e[r+2]=ft[2],e[r+3]=ft[3]}function nc(t,e){return ft[0]=t[e],ft[1]=t[e+1],ft[2]=t[e+2],ft[3]=t[e+3],ms[0]}var bs=new Float64Array([-0]),de=new Uint8Array(bs.buffer);function oc(t,e,r){bs[0]=t,e[r]=de[0],e[r+1]=de[1],e[r+2]=de[2],e[r+3]=de[3],e[r+4]=de[4],e[r+5]=de[5],e[r+6]=de[6],e[r+7]=de[7]}function sc(t,e){return de[0]=t[e],de[1]=t[e+1],de[2]=t[e+2],de[3]=t[e+3],de[4]=t[e+4],de[5]=t[e+5],de[6]=t[e+6],de[7]=t[e+7],bs[0]}var uh=BigInt(Number.MAX_SAFE_INTEGER),fh=BigInt(Number.MIN_SAFE_INTEGER),Se=class t{lo;hi;constructor(e,r){this.lo=e|0,this.hi=r|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(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,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?e<16384?e<128?1:2:e<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return Et;if(e<uh&&e>fh)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,s=e-(n<<32n);return r&&(n=~n|0n,s=~s|0n,++s>ic&&(s=0n,++n>ic&&(n=0n))),new t(Number(s),Number(n))}static fromNumber(e){if(e===0)return Et;let r=e<0;r&&(e=-e);let n=e>>>0,s=(e-n)/4294967296>>>0;return r&&(s=~s>>>0,n=~n>>>0,++n>4294967295&&(n=0,++s>4294967295&&(s=0))),new t(n,s)}static from(e){return typeof e=="number"?t.fromNumber(e):typeof e=="bigint"?t.fromBigInt(e):typeof e=="string"?t.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new t(e.low>>>0,e.high>>>0):Et}},Et=new Se(0,0);Et.toBigInt=function(){return 0n};Et.zzEncode=Et.zzDecode=function(){return this};Et.length=function(){return 1};var ic=4294967296n;function ac(t){let e=0,r=0;for(let n=0;n<t.length;++n)r=t.charCodeAt(n),r<128?e+=1:r<2048?e+=2:(r&64512)===55296&&(t.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function cc(t,e,r){if(r-e<1)return"";let s,o=[],i=0,a;for(;e<r;)a=t[e++],a<128?o[i++]=a:a>191&&a<224?o[i++]=(a&31)<<6|t[e++]&63:a>239&&a<365?(a=((a&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,o[i++]=55296+(a>>10),o[i++]=56320+(a&1023)):o[i++]=(a&15)<<12|(t[e++]&63)<<6|t[e++]&63,i>8191&&((s??(s=[])).push(String.fromCharCode.apply(String,o)),i=0);return s!=null?(i>0&&s.push(String.fromCharCode.apply(String,o.slice(0,i))),s.join("")):String.fromCharCode.apply(String,o.slice(0,i))}function ys(t,e,r){let n=r,s,o;for(let i=0;i<t.length;++i)s=t.charCodeAt(i),s<128?e[r++]=s:s<2048?(e[r++]=s>>6|192,e[r++]=s&63|128):(s&64512)===55296&&((o=t.charCodeAt(i+1))&64512)===56320?(s=65536+((s&1023)<<10)+(o&1023),++i,e[r++]=s>>18|240,e[r++]=s>>12&63|128,e[r++]=s>>6&63|128,e[r++]=s&63|128):(e[r++]=s>>12|224,e[r++]=s>>6&63|128,e[r++]=s&63|128);return r-n}function ke(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function _n(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var gs=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,ke(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 ke(this,4);return _n(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw ke(this,4);return _n(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw ke(this,4);let e=nc(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw ke(this,4);let e=sc(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),r=this.pos,n=this.pos+e;if(n>this.len)throw ke(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return cc(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw ke(this,e);this.pos+=e}else do if(this.pos>=this.len)throw ke(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 Se(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*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;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw ke(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,e}if(this.len-this.pos>4){for(;r<5;++r)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;r<5;++r){if(this.pos>=this.len)throw ke(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw ke(this,8);let e=_n(this.buf,this.pos+=4),r=_n(this.buf,this.pos+=4);return new Se(e,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=ps(this.buf,this.pos);return this.pos+=Xe(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 Dr(t){return new gs(t instanceof Uint8Array?t:t.subarray())}function ge(t,e,r){let n=Dr(t);return e.decode(n,void 0,r)}function vt(t=0){return new Uint8Array(t)}var ws={};H(ws,{base10:()=>lh});var lh=We({prefix:"9",name:"base10",alphabet:"0123456789"});var xs={};H(xs,{base16:()=>hh,base16upper:()=>dh});var hh=X({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),dh=X({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Es={};H(Es,{base2:()=>ph});var ph=X({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var vs={};H(vs,{base256emoji:()=>wh});var fc=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}"),mh=fc.reduce((t,e,r)=>(t[r]=e,t),[]),bh=fc.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function yh(t){return t.reduce((e,r)=>(e+=mh[r],e),"")}function gh(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let s=bh[n];if(s==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(s)}return new Uint8Array(e)}var wh=kt({prefix:"\u{1F680}",name:"base256emoji",encode:yh,decode:gh});var Ss={};H(Ss,{base64:()=>xh,base64pad:()=>Eh,base64url:()=>vh,base64urlpad:()=>Sh});var xh=X({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Eh=X({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),vh=X({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Sh=X({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var As={};H(As,{base8:()=>Ah});var Ah=X({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Is={};H(Is,{identity:()=>Ih});var Ih=kt({prefix:"\0",name:"identity",encode:t=>Ei(t),decode:t=>xi(t)});var mb=new TextEncoder,bb=new TextDecoder;var Ls={};H(Ls,{sha256:()=>St,sha512:()=>Dh});var Lh=20;function Ts({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:s}){return new Bs(t,e,r,n,s)}var Bs=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,s,o){this.name=e,this.code=r,this.encode=n,this.minDigestLength=s??Lh,this.maxDigestLength=o}digest(e,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?lc(n,this.code,r?.truncate):n.then(s=>lc(s,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function lc(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return Re(e,t)}function dc(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var St=Ts({name:"sha2-256",code:18,encode:dc("SHA-256")}),Dh=Ts({name:"sha2-512",code:19,encode:dc("SHA-512")});var Ds={...Is,...Es,...As,...ws,...xs,...Wn,...Jn,...Xn,...Ss,...vs},Lb={...Ls,...to};function mc(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var pc=mc("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),_s=mc("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=vt(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),_h={utf8:pc,"utf-8":pc,hex:Ds.base16,latin1:_s,ascii:_s,binary:_s,...Ds},bc=_h;function yc(t,e="utf8"){let r=bc[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function ks(t){let e=t??8192,r=e>>>1,n,s=e;return function(i){if(i<1||i>r)return vt(i);s+i>e&&(n=vt(e),s=0);let a=n.subarray(s,s+=i);return(s&7)!==0&&(s=(s|7)+1),a}}var At=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function Cs(){}var Ps=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},kh=ks();function Ch(t){return globalThis.Buffer!=null?vt(t):kh(t)}var kr=class{len;head;tail;states;constructor(){this.len=0,this.head=new At(Cs,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new At(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Ns((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(kn,10,Se.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=Se.fromBigInt(e);return this._push(kn,r.length(),r)}uint64Number(e){return this._push(ds,Xe(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 r=Se.fromBigInt(e).zzEncode();return this._push(kn,r.length(),r)}sint64Number(e){let r=Se.fromNumber(e).zzEncode();return this._push(kn,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Rs,1,e?1:0)}fixed32(e){return this._push(_r,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=Se.fromBigInt(e);return this._push(_r,4,r.lo)._push(_r,4,r.hi)}fixed64Number(e){let r=Se.fromNumber(e);return this._push(_r,4,r.lo)._push(_r,4,r.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(rc,4,e)}double(e){return this._push(oc,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(Rs,1,0):this.uint32(r)._push(Ph,r,e)}string(e){let r=ac(e);return r!==0?this.uint32(r)._push(ys,r,e):this._push(Rs,1,0)}fork(){return this.states=new Ps(this),this.head=this.tail=new At(Cs,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 At(Cs,0,0),this.len=0),this}ldelim(){let e=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=r,this.len+=n),this}finish(){let e=this.head.next,r=Ch(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function Rs(t,e,r){e[r]=t&255}function Rh(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var Ns=class extends At{next;constructor(e,r){super(Rh,e,r),this.next=void 0}};function kn(t,e,r){for(;t.hi!==0;)e[r++]=t.lo&127|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;t.lo>127;)e[r++]=t.lo&127|128,t.lo=t.lo>>>7;e[r++]=t.lo}function _r(t,e,r){e[r]=t&255,e[r+1]=t>>>8&255,e[r+2]=t>>>16&255,e[r+3]=t>>>24}function Ph(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(kr.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(Nh,e,t),this},kr.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(Oh,e,t),this});function Nh(t,e,r){e.set(t,r)}function Oh(t,e,r){t.length<40?ys(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(yc(t),r)}function Os(){return new kr}function we(t,e){let r=Os();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*xe(t,e,r){let n=Dr(t);yield*e.stream(n,void 0,"$",r)}var Cn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Rn(t,e,r,n,s){return{name:t,type:e,encode:r,decode:n,stream:s}}function Us(t){function e(o){if(t[o.toString()]==null)throw new Error("Invalid enum value");return t[o]}let r=function(i,a){let c=e(i);a.int32(c)},n=function(i){let a=i.int32();return e(a)},s=function*(i){let a=i.int32();yield e(a)};return Rn("enum",Cn.VARINT,r,n,s)}function Ee(t,e,r){return Rn("message",Cn.LENGTH_DELIMITED,t,e,r)}var re=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var G;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.ECDSA="ECDSA"})(G||(G={}));var Fs;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(Fs||(Fs={}));(function(t){t.codec=()=>Us(Fs)})(G||(G={}));var Fe;(function(t){let e;t.codec=()=>(e==null&&(e=Ee((o,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),o.Type!=null&&(i.uint32(8),G.codec().encode(o.Type,i)),o.Data!=null&&(i.uint32(18),i.bytes(o.Data)),a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{c.Type=G.codec().decode(o);break}case 2:{c.Data=o.bytes();break}default:{o.skipType(f&7);break}}}return c},function*(o,i,a,c={}){let u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:G.codec().decode(o)};break}case 2:{yield{field:`${a}.Data`,value:o.bytes()};break}default:{o.skipType(f&7);break}}}})),e);function r(o){return we(o,t.codec())}t.encode=r;function n(o,i){return ge(o,t.codec(),i)}t.decode=n;function s(o,i){return xe(o,t.codec(),i)}t.stream=s})(Fe||(Fe={}));var Ks;(function(t){let e;t.codec=()=>(e==null&&(e=Ee((o,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),o.Type!=null&&(i.uint32(8),G.codec().encode(o.Type,i)),o.Data!=null&&(i.uint32(18),i.bytes(o.Data)),a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{c.Type=G.codec().decode(o);break}case 2:{c.Data=o.bytes();break}default:{o.skipType(f&7);break}}}return c},function*(o,i,a,c={}){let u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:G.codec().decode(o)};break}case 2:{yield{field:`${a}.Data`,value:o.bytes()};break}default:{o.skipType(f&7);break}}}})),e);function r(o){return we(o,t.codec())}t.encode=r;function n(o,i){return ge(o,t.codec(),i)}t.decode=n;function s(o,i){return xe(o,t.codec(),i)}t.stream=s})(Ks||(Ks={}));function Pn(t){if(isNaN(t)||t<=0)throw new $("random bytes length must be a Number bigger than 0");return dn(t)}var Rr={};H(Rr,{MAX_RSA_KEY_SIZE:()=>Ms,generateRSAKeyPair:()=>vc,jwkToJWKKeyPair:()=>Sc,jwkToPkcs1:()=>Mh,jwkToPkix:()=>Hs,jwkToRSAPrivateKey:()=>Ys,pkcs1MessageToJwk:()=>Vs,pkcs1MessageToRSAPrivateKey:()=>$s,pkcs1ToJwk:()=>Kh,pkcs1ToRSAPrivateKey:()=>Ec,pkixMessageToJwk:()=>zs,pkixMessageToRSAPublicKey:()=>Zs,pkixToJwk:()=>qh,pkixToRSAPublicKey:()=>js});var Qt=class{type="RSA";jwk;_raw;_multihash;constructor(e,r){this.jwk=e,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Rr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return le.createV1(114,this._multihash)}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ae(this.raw,e.raw)}verify(e,r,n){return xc(this.jwk,r,e,n)}},Cr=class{type="RSA";jwk;_raw;publicKey;constructor(e,r){this.jwk=e,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Rr.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ae(this.raw,e.raw)}sign(e,r){return wc(this.jwk,e,r)}};var Ms=8192,qs=18,Uh=1062,Fh=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Kh(t){let e=ze(t);return Vs(e)}function Vs(t){return{n:z(t[1],"base64url"),e:z(t[2],"base64url"),d:z(t[3],"base64url"),p:z(t[4],"base64url"),q:z(t[5],"base64url"),dp:z(t[6],"base64url"),dq:z(t[7],"base64url"),qi:z(t[8],"base64url"),kty:"RSA"}}function Mh(t){if(t.n==null||t.e==null||t.d==null||t.p==null||t.q==null||t.dp==null||t.dq==null||t.qi==null)throw new $("JWK was missing components");return tt([ye(Uint8Array.from([0])),ye(j(t.n,"base64url")),ye(j(t.e,"base64url")),ye(j(t.d,"base64url")),ye(j(t.p,"base64url")),ye(j(t.q,"base64url")),ye(j(t.dp,"base64url")),ye(j(t.dq,"base64url")),ye(j(t.qi,"base64url"))]).subarray()}function qh(t){let e=ze(t,{offset:0});return zs(e)}function zs(t){let e=ze(t[1],{offset:0});return{kty:"RSA",n:z(e[0],"base64url"),e:z(e[1],"base64url")}}function Hs(t){if(t.n==null||t.e==null)throw new $("JWK was missing components");return tt([Fh,cn(tt([ye(j(t.n,"base64url")),ye(j(t.e,"base64url"))]))]).subarray()}function Ec(t){let e=ze(t);return $s(e)}function $s(t){let e=Vs(t);return Ys(e)}function js(t,e){if(t.byteLength>=Uh)throw new Dt("Key size is too large");let r=ze(t,{offset:0});return Zs(r,t,e)}function Zs(t,e,r){let n=zs(t);if(r==null){let s=Ht(Fe.encode({Type:G.RSA,Data:e}));r=Re(qs,s)}return new Qt(n,r)}function Ys(t){if(Ic(t)>Ms)throw new $("Key size is too large");let e=Sc(t),r=Ht(Fe.encode({Type:G.RSA,Data:Hs(e.publicKey)})),n=Re(qs,r);return new Cr(e.privateKey,new Qt(e.publicKey,n))}async function vc(t){if(t>Ms)throw new $("Key size is too large");let e=await Ac(t),r=Ht(Fe.encode({Type:G.RSA,Data:Hs(e.publicKey)})),n=Re(qs,r);return new Cr(e.privateKey,new Qt(e.publicKey,n))}function Sc(t){if(t==null)throw new $("Missing key parameter");return{privateKey:t,publicKey:{kty:t.kty,n:t.n,e:t.e}}}async function Ac(t,e){let r=await Ie.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:t,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);e?.signal?.throwIfAborted();let n=await Vh(r,e);return{privateKey:n[0],publicKey:n[1]}}async function wc(t,e,r){let n=await Ie.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let s=await Ie.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,Pe(e instanceof Uint8Array?e:e.subarray()));return r?.signal?.throwIfAborted(),new Uint8Array(s,0,s.byteLength)}async function xc(t,e,r,n){let s=await Ie.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let o=await Ie.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},s,Pe(e),Pe(r instanceof Uint8Array?r:r.subarray()));return n?.signal?.throwIfAborted(),o}async function Vh(t,e){if(t.privateKey==null||t.publicKey==null)throw new $("Private and public key are required");let r=await Promise.all([Ie.get().subtle.exportKey("jwk",t.privateKey),Ie.get().subtle.exportKey("jwk",t.publicKey)]);return e?.signal?.throwIfAborted(),r}function Ic(t){if(t.kty!=="RSA")throw new $("invalid key type");if(t.n==null)throw new $("invalid key modulus");return j(t.n,"base64url").length*8}var Nn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,r){if(un(e),ve(r,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,s=new Uint8Array(n);s.set(r.length>n?e.create().update(r).digest():r);for(let o=0;o<s.length;o++)s[o]^=54;this.iHash.update(s),this.oHash=e.create();for(let o=0;o<s.length;o++)s[o]^=106;this.oHash.update(s),je(s)}update(e){return zt(this),this.iHash.update(e),this}digestInto(e){zt(this),fn(e,this),this.finished=!0;let r=e.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),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:r,iHash:n,finished:s,destroyed:o,blockLen:i,outputLen:a}=this;return e=e,e.finished=s,e.destroyed=o,e.blockLen=i,e.outputLen=a,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Bc=(()=>{let t=((e,r,n)=>new Nn(e,r).update(n).digest());return t.create=(e,r)=>new Nn(e,r),t})();var Tc=(t,e)=>(t+(t>=0?e:-e)/Lc)/e;function zh(t,e,r){Zt("scalar",t,Ke,r);let[[n,s],[o,i]]=e,a=Tc(i*t,r),c=Tc(-s*t,r),u=t-a*n-c*o,f=-a*s-c*i,h=u<Ke,l=f<Ke;h&&(u=-u),l&&(f=-f);let d=Ar(Math.ceil(Yt(r)/2))+lt;if(u<Ke||u>=d||f<Ke||f>=d)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:h,k1:u,k2neg:l,k2:f}}function Xs(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function Gs(t,e){_e(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return Le(r.lowS,"lowS"),Le(r.prehash,"prehash"),r.format!==void 0&&Xs(r.format),r}var Ws=class extends Error{constructor(e=""){super(e)}},Ce={Err:Ws,_tlv:{encode:(t,e)=>{let{Err:r}=Ce;if(De(t,"tag"),t<0||t>255)throw new r("tlv.encode: wrong tag");if(typeof e!="string")throw new TypeError('"data" expected string, got type='+typeof e);if(e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,s=vr(n);if(s.length/2&128)throw new r("tlv.encode: long form length too big");let o=n>127?vr(s.length/2|128):"";return vr(t)+o+s+e},decode(t,e){let{Err:r}=Ce;e=K(e,void 0,"DER data");let n=0;if(t<0||t>255)throw new r("tlv.encode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let s=e[n++],o=!!(s&128),i=0;if(!o)i=s;else{let c=s&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=e.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)i=i<<8|f;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+i)}}},_int:{encode(t){let{Err:e}=Ce;if(gn(t),t<Ke)throw new e("integer: negative integers are not allowed");let r=vr(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=Ce;if(t.length<1)throw new e("invalid signature integer: empty");if(t[0]&128)throw new e("invalid signature integer: negative");if(t.length>1&&t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return yt(t)}},toSig(t){let{Err:e,_int:r,_tlv:n}=Ce,s=K(t,void 0,"signature"),{v:o,l:i}=n.decode(48,s);if(i.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,o),{v:u,l:f}=n.decode(2,c);if(f.length)throw new e("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(u)}},hexFromSig(t){let{_tlv:e,_int:r}=Ce,n=e.encode(2,r.encode(t.r)),s=e.encode(2,r.encode(t.s)),o=n+s;return e.encode(48,o)}};Object.freeze(Ce._tlv);Object.freeze(Ce._int);Object.freeze(Ce);var Ke=BigInt(0),lt=BigInt(1),Lc=BigInt(2),On=BigInt(3),Hh=BigInt(4);function Dc(t,e={}){let r=vn("weierstrass",t,e),n=r.Fp,s=r.Fn,o=r.CURVE,{h:i,n:a}=o;_e(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c,allowInfinityPoint:u}=e;if(c&&(!n.is0(o.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let f=kc(n,s);function h(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(O,m,w){if(u&&m.is0())return Uint8Array.of(0);let{x:A,y:E}=m.toAffine(),x=n.toBytes(A);if(Le(w,"isCompressed"),w){h();let I=!n.isOdd(E);return oe(_c(I),x)}else return oe(Uint8Array.of(4),x,n.toBytes(E))}function d(O){K(O,void 0,"Point");let{publicKey:m,publicKeyUncompressed:w}=f,A=O.length,E=O[0],x=O.subarray(1);if(u&&A===1&&E===0)return{x:n.ZERO,y:n.ZERO};if(A===m&&(E===2||E===3)){let I=n.fromBytes(x);if(!n.isValid(I))throw new Error("bad point: is not on curve, wrong x");let _=b(I),D;try{D=n.sqrt(_)}catch(F){let M=F instanceof Error?": "+F.message:"";throw new Error("bad point: is not on curve, sqrt error"+M)}h();let C=n.isOdd(D);return(E&1)===1!==C&&(D=n.neg(D)),{x:I,y:D}}else if(A===w&&E===4){let I=n.BYTES,_=n.fromBytes(x.subarray(0,I)),D=n.fromBytes(x.subarray(I,I*2));if(!y(_,D))throw new Error("bad point: is not on curve");return{x:_,y:D}}else throw new Error(`bad point: got length ${A}, expected compressed=${m} or uncompressed=${w}`)}let p=e.toBytes===void 0?l:e.toBytes,g=e.fromBytes===void 0?d:e.fromBytes;function b(O){let m=n.sqr(O),w=n.mul(m,O);return n.add(n.add(w,n.mul(O,o.a)),o.b)}function y(O,m){let w=n.sqr(m),A=b(O);return n.eql(w,A)}if(!y(o.Gx,o.Gy))throw new Error("bad curve params: generator point");let v=n.mul(n.pow(o.a,On),Hh),S=n.mul(n.sqr(o.b),BigInt(27));if(n.is0(n.add(v,S)))throw new Error("bad curve params: a or b");function L(O,m,w=!1){if(!n.isValid(m)||w&&n.is0(m))throw new Error(`bad point coordinate ${O}`);return m}function T(O){if(!(O instanceof B))throw new Error("Weierstrass Point expected")}function R(O){if(!c||!c.basises)throw new Error("no endo");return zh(O,c.basises,s.ORDER)}function k(O,m,w,A,E){return w=new B(n.mul(w.X,O),w.Y,w.Z),m=Br(A,m),w=Br(E,w),m.add(w)}class B{static BASE=new B(o.Gx,o.Gy,n.ONE);static ZERO=new B(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=s;X;Y;Z;constructor(m,w,A){this.X=L("x",m),this.Y=L("y",w,!0),this.Z=L("z",A),Object.freeze(this)}static CURVE(){return o}static fromAffine(m){let{x:w,y:A}=m||{};if(!m||!n.isValid(w)||!n.isValid(A))throw new Error("invalid affine point");if(m instanceof B)throw new Error("projective point not allowed");return n.is0(w)&&n.is0(A)?B.ZERO:new B(w,A,n.ONE)}static fromBytes(m){let w=B.fromAffine(g(K(m,void 0,"point")));return w.assertValidity(),w}static fromHex(m){return B.fromBytes(jt(m))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=8,w=!0){return V.createCache(this,m),w||this.multiply(On),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:w,y:A}=m.toAffine();if(!n.isValid(w)||!n.isValid(A))throw new Error("bad point: x or y not field elements");if(!y(w,A))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){T(m);let{X:w,Y:A,Z:E}=this,{X:x,Y:I,Z:_}=m,D=n.eql(n.mul(w,_),n.mul(x,E)),C=n.eql(n.mul(A,_),n.mul(I,E));return D&&C}negate(){return new B(this.X,n.neg(this.Y),this.Z)}double(){let{a:m,b:w}=o,A=n.mul(w,On),{X:E,Y:x,Z:I}=this,_=n.ZERO,D=n.ZERO,C=n.ZERO,P=n.mul(E,E),F=n.mul(x,x),M=n.mul(I,I),U=n.mul(E,x);return U=n.add(U,U),C=n.mul(E,I),C=n.add(C,C),_=n.mul(m,C),D=n.mul(A,M),D=n.add(_,D),_=n.sub(F,D),D=n.add(F,D),D=n.mul(_,D),_=n.mul(U,_),C=n.mul(A,C),M=n.mul(m,M),U=n.sub(P,M),U=n.mul(m,U),U=n.add(U,C),C=n.add(P,P),P=n.add(C,P),P=n.add(P,M),P=n.mul(P,U),D=n.add(D,P),M=n.mul(x,I),M=n.add(M,M),P=n.mul(M,U),_=n.sub(_,P),C=n.mul(M,F),C=n.add(C,C),C=n.add(C,C),new B(_,D,C)}add(m){T(m);let{X:w,Y:A,Z:E}=this,{X:x,Y:I,Z:_}=m,D=n.ZERO,C=n.ZERO,P=n.ZERO,F=o.a,M=n.mul(o.b,On),U=n.mul(w,x),ne=n.mul(A,I),se=n.mul(E,_),ie=n.add(w,A),Q=n.add(x,I);ie=n.mul(ie,Q),Q=n.add(U,ne),ie=n.sub(ie,Q),Q=n.add(w,E);let be=n.add(x,_);return Q=n.mul(Q,be),be=n.add(U,se),Q=n.sub(Q,be),be=n.add(A,E),D=n.add(I,_),be=n.mul(be,D),D=n.add(ne,se),be=n.sub(be,D),P=n.mul(F,Q),D=n.mul(M,se),P=n.add(D,P),D=n.sub(ne,P),P=n.add(ne,P),C=n.mul(D,P),ne=n.add(U,U),ne=n.add(ne,U),se=n.mul(F,se),Q=n.mul(M,Q),ne=n.add(ne,se),se=n.sub(U,se),se=n.mul(F,se),Q=n.add(Q,se),U=n.mul(ne,Q),C=n.add(C,U),U=n.mul(be,Q),D=n.mul(ie,D),D=n.sub(D,U),U=n.mul(ie,ne),P=n.mul(be,P),P=n.add(P,U),new B(D,C,P)}subtract(m){return T(m),this.add(m.negate())}is0(){return this.equals(B.ZERO)}multiply(m){let{endo:w}=e;if(!s.isValidNot0(m))throw new RangeError("invalid scalar: out of range");let A,E,x=I=>V.cached(this,I,_=>xt(B,_));if(w){let{k1neg:I,k1:_,k2neg:D,k2:C}=R(m),{p:P,f:F}=x(_),{p:M,f:U}=x(C);E=F.add(U),A=k(w.beta,P,M,I,D)}else{let{p:I,f:_}=x(m);A=I,E=_}return xt(B,[A,E])[0]}multiplyUnsafe(m){let{endo:w}=e,A=this,E=m;if(!s.isValid(E))throw new RangeError("invalid scalar: out of range");if(E===Ke||A.is0())return B.ZERO;if(E===lt)return A;if(V.hasCache(this))return this.multiply(E);if(w){let{k1neg:x,k1:I,k2neg:_,k2:D}=R(E),{p1:C,p2:P}=qa(B,A,I,D);return k(w.beta,C,P,x,_)}else return V.unsafe(A,E)}toAffine(m){let w=this,A=m,{X:E,Y:x,Z:I}=w;if(n.eql(I,n.ONE))return{x:E,y:x};let _=w.is0();A==null&&(A=_?n.ONE:n.inv(I));let D=n.mul(E,A),C=n.mul(x,A),P=n.mul(I,A);if(_)return{x:n.ZERO,y:n.ZERO};if(!n.eql(P,n.ONE))throw new Error("invZ was invalid");return{x:D,y:C}}isTorsionFree(){let{isTorsionFree:m}=e;return i===lt?!0:m?m(B,this):V.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:m}=e;return i===lt?this:m?m(B,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===lt?this.is0():this.clearCofactor().is0()}toBytes(m=!0){return Le(m,"isCompressed"),this.assertValidity(),p(B,this,m)}toHex(m=!0){return $t(this.toBytes(m))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let N=s.BITS,V=new Wt(B,e.endo?Math.ceil(N/2):N);return N>=8&&B.BASE.precompute(8),Object.freeze(B.prototype),Object.freeze(B),B}function _c(t){return Uint8Array.of(t?2:3)}function kc(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function $h(t,e={}){let{Fn:r}=t,n=e.randomBytes===void 0?Er:e.randomBytes,s=Object.assign(kc(t.Fp,r),{seed:Math.max(Yo(r.ORDER),16)});function o(d){try{let p=r.fromBytes(d);return r.isValidNot0(p)}catch{return!1}}function i(d,p){let{publicKey:g,publicKeyUncompressed:b}=s;try{let y=d.length;return p===!0&&y!==g||p===!1&&y!==b?!1:!!t.fromBytes(d)}catch{return!1}}function a(d){return d=d===void 0?n(s.seed):d,Go(K(d,s.seed,"seed"),r.ORDER)}function c(d,p=!0){return t.BASE.multiply(r.fromBytes(d)).toBytes(p)}function u(d){let{secretKey:p,publicKey:g,publicKeyUncompressed:b}=s,y=r._lengths;if(!bt(d))return;let v=K(d,void 0,"key").length,S=v===g||v===b,L=v===p||!!y?.includes(v);if(!(S&&L))return S}function f(d,p,g=!0){if(u(d)===!0)throw new Error("first arg must be private key");if(u(p)===!1)throw new Error("second arg must be public key");let b=r.fromBytes(d);return t.fromBytes(p).multiply(b).toBytes(g)}let h={isValidSecretKey:o,isValidPublicKey:i,randomSecretKey:a},l=Sn(a,c);return Object.freeze(h),Object.freeze(s),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:l,Point:t,utils:h,lengths:s})}function Cc(t,e,r={}){let n=e;un(n),_e(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let s=r.randomBytes===void 0?Er:r.randomBytes,o=r.hmac===void 0?(E,x)=>Bc(n,E,x):r.hmac,{Fp:i,Fn:a}=t,{ORDER:c,BITS:u}=a,{keygen:f,getPublicKey:h,getSharedSecret:l,utils:d,lengths:p}=$h(t,r),g={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},b=c*Lc+lt<i.ORDER;function y(E){let x=c>>lt;return E>x}function v(E,x){if(!a.isValidNot0(x))throw new Error(`invalid signature ${E}: out of range 1..Point.Fn.ORDER`);return x}function S(){if(b)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function L(E,x){Xs(x);let I=p.signature,_=x==="compact"?I:x==="recovered"?I+1:void 0;return K(E,_)}class T{r;s;recovery;constructor(x,I,_){if(this.r=v("r",x),this.s=v("s",I),_!=null){if(S(),![0,1,2,3].includes(_))throw new Error("invalid recovery id");this.recovery=_}Object.freeze(this)}static fromBytes(x,I=g.format){L(x,I);let _;if(I==="der"){let{r:F,s:M}=Ce.toSig(K(x));return new T(F,M)}I==="recovered"&&(_=x[0],I="compact",x=x.subarray(1));let D=p.signature/2,C=x.subarray(0,D),P=x.subarray(D,D*2);return new T(a.fromBytes(C),a.fromBytes(P),_)}static fromHex(x,I){return this.fromBytes(jt(x),I)}assertRecovery(){let{recovery:x}=this;if(x==null)throw new Error("invalid recovery id: must be present");return x}addRecoveryBit(x){return new T(this.r,this.s,x)}recoverPublicKey(x){let{r:I,s:_}=this,D=this.assertRecovery(),C=D===2||D===3?I+c:I;if(!i.isValid(C))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let P=i.toBytes(C),F=t.fromBytes(oe(_c((D&1)===0),P)),M=a.inv(C),U=k(K(x,void 0,"msgHash")),ne=a.create(-U*M),se=a.create(_*M),ie=t.BASE.multiplyUnsafe(ne).add(F.multiplyUnsafe(se));if(ie.is0())throw new Error("invalid recovery: point at infinify");return ie.assertValidity(),ie}hasHighS(){return y(this.s)}toBytes(x=g.format){if(Xs(x),x==="der")return jt(Ce.hexFromSig(this));let{r:I,s:_}=this,D=a.toBytes(I),C=a.toBytes(_);return x==="recovered"?(S(),oe(Uint8Array.of(this.assertRecovery()),D,C)):oe(D,C)}toHex(x){return $t(this.toBytes(x))}}Object.freeze(T.prototype),Object.freeze(T);let R=r.bits2int===void 0?function(x){if(x.length>8192)throw new Error("input is too large");let I=yt(x),_=x.length*8-u;return _>0?I>>BigInt(_):I}:r.bits2int,k=r.bits2int_modN===void 0?function(x){return a.create(R(x))}:r.bits2int_modN,B=Ar(u);function N(E){return Zt("num < 2^"+u,E,Ke,B),a.toBytes(E)}function V(E,x){return K(E,void 0,"message"),x?K(n(E),void 0,"prehashed message"):E}function O(E,x,I){let{lowS:_,prehash:D,extraEntropy:C}=Gs(I,g);E=V(E,D);let P=k(E),F=a.fromBytes(x);if(!a.isValidNot0(F))throw new Error("invalid private key");let M=[N(F),N(P)];if(C!=null&&C!==!1){let ie=C===!0?s(p.secretKey):C;M.push(K(ie,void 0,"extraEntropy"))}let U=oe(...M),ne=P;function se(ie){let Q=R(ie);if(!a.isValidNot0(Q))return;let be=a.inv(Q),Lt=t.BASE.multiply(Q).toAffine(),nr=a.create(Lt.x);if(nr===Ke)return;let Wr=a.create(be*a.create(ne+nr*F));if(Wr===Ke)return;let pi=(Lt.x===nr?0:2)|Number(Lt.y<),mi=Wr;return _&&y(Wr)&&(mi=a.neg(Wr),pi^=1),new T(nr,mi,b?void 0:pi)}return{seed:U,k2sig:se}}function m(E,x,I={}){let{seed:_,k2sig:D}=O(E,x,I);return Aa(n.outputLen,a.BYTES,o)(_,D).toBytes(I.format)}function w(E,x,I,_={}){let{lowS:D,prehash:C,format:P}=Gs(_,g);if(I=K(I,void 0,"publicKey"),x=V(x,C),!bt(E)){let F=E instanceof T?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+F)}L(E,P);try{let F=T.fromBytes(E,P),M=t.fromBytes(I);if(D&&F.hasHighS())return!1;let{r:U,s:ne}=F,se=k(x),ie=a.inv(ne),Q=a.create(se*ie),be=a.create(U*ie),Lt=t.BASE.multiplyUnsafe(Q).add(M.multiplyUnsafe(be));return Lt.is0()?!1:a.create(Lt.x)===U}catch{return!1}}function A(E,x,I={}){let{prehash:_}=Gs(I,g);return x=V(x,_),T.fromBytes(E,"recovered").recoverPublicKey(x).toBytes()}return Object.freeze({keygen:f,getPublicKey:h,getSharedSecret:l,utils:d,lengths:p,Point:t,sign:m,verify:w,recoverPublicKey:A,Signature:T,hash:n})}var Qs={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},jh={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Rc=BigInt(2);function Zh(t){let e=Qs.p,r=BigInt(3),n=BigInt(6),s=BigInt(11),o=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=t*t*t%e,f=u*u*t%e,h=Z(f,r,e)*f%e,l=Z(h,r,e)*f%e,d=Z(l,Rc,e)*u%e,p=Z(d,s,e)*d%e,g=Z(p,o,e)*p%e,b=Z(g,a,e)*g%e,y=Z(b,c,e)*b%e,v=Z(y,a,e)*g%e,S=Z(v,r,e)*f%e,L=Z(S,i,e)*p%e,T=Z(L,n,e)*u%e,R=Z(T,Rc,e);if(!Js.eql(Js.sqr(R),t))throw new Error("Cannot find square root");return R}var Js=Gt(Qs.p,{sqrt:Zh}),Yh=Dc(Qs,{Fp:Js,endo:jh}),er=Cc(Yh,Ht);function Pc(t,e,r,n){let s=St.digest(r instanceof Uint8Array?r:r.subarray());if(Ln(s))return s.then(({digest:o})=>(n?.signal?.throwIfAborted(),er.verify(e,o,t,{prehash:!1,format:"der"}))).catch(o=>{throw o.name==="AbortError"?o:new Lr(String(o))});try{return n?.signal?.throwIfAborted(),er.verify(e,s.digest,t,{prehash:!1,format:"der"})}catch(o){throw new Lr(String(o))}}var Un=class{type="secp256k1";raw;_key;constructor(e){this._key=Oc(e),this.raw=Nc(this._key)}toMultihash(){return Be.digest(He(this))}toCID(){return le.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ae(this.raw,e.raw)}verify(e,r,n){return Pc(this._key,r,e,n)}};function ei(t){return new Un(t)}function Nc(t){return er.Point.fromBytes(t).toBytes()}function Oc(t){try{return er.Point.fromBytes(t),t}catch(e){throw new Dt(String(e))}}function ti(t,e){let{Type:r,Data:n}=Fe.decode(t),s=n??new Uint8Array;switch(r){case G.RSA:return js(s,e);case G.Ed25519:return cs(s);case G.secp256k1:return ei(s);case G.ECDSA:return ko(s);default:throw new ht}}function Uc(t){let{Type:e,Data:r}=Fe.decode(t.digest),n=r??new Uint8Array;switch(e){case G.Ed25519:return cs(n);case G.secp256k1:return ei(n);case G.ECDSA:return ko(n);default:throw new ht}}function He(t){return Fe.encode({Type:G[t.type],Data:t.raw})}var Fc=Symbol.for("nodejs.util.inspect.custom"),Gh=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()})`}[$n]=!0;toString(){return this.string==null&&(this.string=Y.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return le.createV1(Gh,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return Ae(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return Ae(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[Fc](){return`PeerId(${this.toString()})`}},Nr=class extends Pr{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Or=class extends Pr{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},Ur=class extends Pr{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},Xh=2336,Fn=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=Be.digest(j(this.url))}[Fc](){return`PeerId(${this.url})`}[$n]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return le.createV1(Xh,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=z(e)),e.toString()===this.toString())}};function ri(t){if(t.type==="Ed25519")return new Or({multihash:t.toCID().multihash,publicKey:t});if(t.type==="secp256k1")return new Ur({multihash:t.toCID().multihash,publicKey:t});if(t.type==="RSA")return new Nr({multihash:t.toCID().multihash,publicKey:t});throw new ht}function Kc(t){return ri(t.publicKey)}function Fr(t){if(Jh(t))return new Nr({multihash:t});if(Wh(t))try{let e=Uc(t);if(e.type==="Ed25519")return new Or({multihash:t,publicKey:e});if(e.type==="secp256k1")return new Ur({multihash:t,publicKey:e})}catch{let r=z(t.digest);return new Fn(new URL(r))}throw new Qr("Supplied PeerID Multihash is invalid")}function Wh(t){return t.code===Be.code}function Jh(t){return t.code===St.code}function It(t,e){let r={[Symbol.iterator]:()=>r,next:()=>{let n=t.next(),s=n.value;return n.done===!0||s==null?{done:!0,value:void 0}:{done:!1,value:e(s)}}};return r}function Kn(t){let e=Je(Y.decode(`z${t}`));return Fr(e)}var Kr=class{map;constructor(e){if(this.map=new Map,e!=null)for(let[r,n]of e.entries())this.map.set(r.toString(),{key:r,value:n})}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(e){return this.map.delete(e.toString())}entries(){return It(this.map.entries(),e=>[e[1].key,e[1].value])}forEach(e){this.map.forEach((r,n)=>{e(r.value,r.key,this)})}get(e){return this.map.get(e.toString())?.value}has(e){return this.map.has(e.toString())}set(e,r){this.map.set(e.toString(),{key:e,value:r})}keys(){return It(this.map.values(),e=>e.key)}values(){return It(this.map.values(),e=>e.value)}get size(){return this.map.size}};var Mr=class t{set;constructor(e){if(this.set=new Set,e!=null)for(let r of e)this.set.add(r.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(e){this.set.add(e.toString())}clear(){this.set.clear()}delete(e){this.set.delete(e.toString())}entries(){return It(this.set.entries(),e=>{let r=Kn(e[0]);return[r,r]})}forEach(e){this.set.forEach(r=>{let n=Kn(r);e(n,n,this)})}has(e){return this.set.has(e.toString())}values(){return It(this.set.values(),e=>Kn(e))}intersection(e){let r=new t;for(let n of e)this.has(n)&&r.add(n);return r}difference(e){let r=new t;for(let n of this)e.has(n)||r.add(n);return r}union(e){let r=new t;for(let n of e)r.add(n);for(let n of this)r.add(n);return r}};var ni=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},Mc=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function qr(t,e){let{milliseconds:r,fallback:n,message:s,customTimers:o={setTimeout,clearTimeout},signal:i}=e,a,c,f=new Promise((h,l)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(i?.aborted){l(Mc(i));return}if(i&&(c=()=>{l(Mc(i))},i.addEventListener("abort",c,{once:!0})),t.then(h,l),r===Number.POSITIVE_INFINITY)return;let d=new ni;a=o.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(p){l(p)}return}typeof t.cancel=="function"&&t.cancel(),s===!1?h():s instanceof Error?l(s):(d.message=s??`Promise timed out after ${r} milliseconds`,l(d))},r)}).finally(()=>{f.clear(),c&&i&&i.removeEventListener("abort",c)});return f.clear=()=>{o.clearTimeout.call(void 0,a),a=void 0},f}var Qh=t=>{let e=t.addEventListener||t.on||t.addListener,r=t.removeEventListener||t.off||t.removeListener;if(!e||!r)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(t),removeListener:r.bind(t)}};function ed(t,e,r){let n,s=new Promise((o,i)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[e].flat(),c=[],{addListener:u,removeListener:f}=Qh(t),h=async(...d)=>{let p=r.multiArgs?d:d[0];if(r.filter)try{if(!await r.filter(p))return}catch(g){n(),i(g);return}c.push(p),r.count===c.length&&(n(),o(c))},l=(...d)=>{n(),i(r.rejectionMultiArgs?d:d[0])};n=()=>{for(let d of a)f(d,h);for(let d of r.rejectionEvents)a.includes(d)||f(d,l)};for(let d of a)u(d,h);for(let d of r.rejectionEvents)a.includes(d)||u(d,l);r.signal&&r.signal.addEventListener("abort",()=>{l(r.signal.reason)},{once:!0}),r.resolveImmediately&&o(c)});if(s.cancel=n,typeof r.timeout=="number"){let o=qr(s,{milliseconds:r.timeout});return o.cancel=()=>{n(),o.clear()},o}return s}function qc(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=ed(t,e,r),s=n.then(o=>o[0]);return s.cancel=n.cancel,s}var Bt=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function td(t){return t.reason}async function oi(t,e,r){if(e==null)return t;let n=r?.translateError??td;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let s;try{return await Promise.race([t,new Promise((o,i)=>{s=()=>{i(n(e))},e.addEventListener("abort",s)})])}finally{s!=null&&e.removeEventListener("abort",s)}}var nd=4194304,Mn=class extends Error{static name="UnwrappedError";name="UnwrappedError"},ii=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},ai=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},ci=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function od(t){return typeof t?.closeRead=="function"}function sd(t){return typeof t?.close=="function"}function si(t){return od(t)?t.remoteWriteStatus!=="writable"&&t.readBufferLength===0:sd(t)?t.status!=="open":!1}function id(t){return t?.addEventListener!=null&&t?.removeEventListener!=null&&t?.send!=null&&t?.push!=null&&t?.log!=null}function ad(t,e){let r=e?.maxBufferSize??nd,n=new ae,s,o=!1;if(!id(t))throw new $("Argument should be a Stream or a Multiaddr");let i=f=>{if(n.append(f.data),n.byteLength>r){let h=n.byteLength;n.consume(n.byteLength),s?.reject(new Error(`Read buffer overflow - ${h} > ${r}`))}s?.resolve()};t.addEventListener("message",i);let a=f=>{f.error!=null?s?.reject(f.error):s?.resolve()};t.addEventListener("close",a);let c=()=>{s?.resolve()};t.addEventListener("remoteCloseWrite",c);let u={readBuffer:n,async read(f){if(o===!0)throw new Mn("Stream was unwrapped");if(si(t)){if(n.byteLength===0&&f?.bytes==null)return null;if(f?.bytes!=null&&n.byteLength<f.bytes)throw t.log.error("closed after reading %d/%d bytes",n.byteLength,f.bytes),new Bt(`Unexpected EOF - stream closed after reading ${n.byteLength}/${f.bytes} bytes`)}let h=f?.bytes??1;for(s=Promise.withResolvers();;){if(n.byteLength>=h){s.resolve();break}if(await oi(s.promise,f?.signal),si(t)){if(n.byteLength===0&&f?.bytes==null)return null;break}s=Promise.withResolvers()}let l=f?.bytes??n.byteLength;if(n.byteLength<l){if(si(t))throw t.log.error("closed while reading %d/%d bytes",n.byteLength,l),new Bt(`Unexpected EOF - stream closed while reading ${n.byteLength}/${l} bytes`);return u.read(f)}let d=n.sublist(0,l);return n.consume(l),d},async write(f,h){if(o===!0)throw new Mn("Stream was unwrapped");t.send(f)||await qc(t,"drain",{signal:h?.signal,rejectionEvents:["close"]})},unwrap(){return o||(o=!0,t.removeEventListener("message",i),t.removeEventListener("close",a),t.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(t.log("stream unwrapped with %d unread bytes",n.byteLength),t.unshift(n))),t}};return u}function cd(t,e={}){let r=ad(t,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=Xe(e.maxDataLength));let n=e?.lengthDecoder??tc,s=e?.lengthEncoder??ec;return{async read(i){let a=-1,c=new ae;for(;;){let f=await r.read({...i,bytes:1});if(f==null)break;c.append(f);try{a=n(c)}catch(h){if(h instanceof RangeError)continue;throw h}if(a<0)throw new ii("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new ci(`Message length length too long - ${c.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new ai(`Message length too long - ${a} > ${e.maxDataLength}`);let u=await r.read({...i,bytes:a});if(u==null)throw t.log.error("tried to read %d bytes but the stream closed",a),new Bt(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(u.byteLength!==a)throw t.log.error("read %d/%d bytes before the stream closed",u.byteLength,a),new Bt(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(i,a){await r.write(new ae(s(i.byteLength),i),a)},async writeV(i,a){let c=new ae(...i.flatMap(u=>[s(u.byteLength),u]));await r.write(c,a)},unwrap(){return r.unwrap()}}}function ui(t,e){let r=cd(t,e),n={read:async(s,o)=>{let i=await r.read(o);return s.decode(i)},write:async(s,o,i)=>{await r.write(o.encode(s),i)},writeV:async(s,o,i)=>{await r.writeV(s.map(a=>o.encode(a)),i)},pb:s=>({read:async o=>n.read(s,o),write:async(o,i)=>n.write(o,s,i),writeV:async(o,i)=>n.writeV(o,s,i),unwrap:()=>n}),unwrap:()=>r.unwrap()};return n}var li=nu(zc(),1);function hi(t,e,r){let n=0,s=t.length;for(;s>0;){let o=Math.trunc(s/2),i=n+o;r(t[i],e)<=0?(n=++i,s-=o+1):s=o}return n}var ld=100,tr=class{#e=[];#t=0;enqueue(e,r){let{priority:n=0,id:s}=r??{},{size:o}=this,i={priority:n,id:s,run:e};if(o===0){this.#e.length=0,this.#t=0,this.#e.push(i);return}if(this.#e.at(-1).priority>=n){this.#e.push(i);return}this.#s();let a=hi(this.#e,i,(c,u)=>u.priority-c.priority);this.#e.splice(a,0,i)}setPriority(e,r){let n=this.#e.findIndex((o,i)=>i>=this.#t&&o.id===e);if(n===-1)throw new ReferenceError(`No promise function with the id "${e}" exists in the queue.`);let[s]=this.#e.splice(n,1);this.enqueue(s.run,{priority:r,id:e})}remove(e){let r=this.#e.findIndex((n,s)=>s<this.#t?!1:typeof e=="string"?n.id===e:n.run===e);r!==-1&&this.#e.splice(r,1)}dequeue(){if(this.#t===this.#e.length)return;let e=this.#e[this.#t];return this.#t++,this.#t===this.#e.length?(this.#e.length=0,this.#t=0):this.#t>ld&&this.#t>this.#e.length/2&&this.#s(),e?.run}filter(e){let r=[];for(let n=this.#t;n<this.#e.length;n++){let s=this.#e[n];s.priority===e.priority&&r.push(s.run)}return r}get size(){return this.#e.length-this.#t}#s(){this.#t!==0&&(this.#e.splice(0,this.#t),this.#t=0)}};var zr=class extends li.default{#e;#t;#s=0;#d;#m=!1;#w=!1;#c;#T=0;#x=0;#u;#f;#a;#i=[];#o=0;#r;#L;#n=0;#b;#l;#R=1n;#y=new Map;#E=new Set;timeout;constructor(e){if(super(),e={carryoverIntervalCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:tr,strict:!1,...e},!(typeof e.intervalCap=="number"&&e.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${e.intervalCap?.toString()??""}\` (${typeof e.intervalCap})`);if(e.interval===void 0||!(Number.isFinite(e.interval)&&e.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${e.interval?.toString()??""}\` (${typeof e.interval})`);if(e.strict&&e.interval===0)throw new TypeError("The `strict` option requires a non-zero `interval`");if(e.strict&&e.intervalCap===Number.POSITIVE_INFINITY)throw new TypeError("The `strict` option requires a finite `intervalCap`");if(this.#e=e.carryoverIntervalCount??e.carryoverConcurrencyCount??!1,this.#t=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#d=e.intervalCap,this.#c=e.interval,this.#a=e.strict,this.#r=new e.queueClass,this.#L=e.queueClass,this.concurrency=e.concurrency,e.timeout!==void 0&&!(Number.isFinite(e.timeout)&&e.timeout>0))throw new TypeError(`Expected \`timeout\` to be a positive finite number, got \`${e.timeout}\` (${typeof e.timeout})`);this.timeout=e.timeout,this.#l=e.autoStart===!1,this.#q()}#v(e){for(;this.#o<this.#i.length;){let n=this.#i[this.#o];if(n!==void 0&&e-n>=this.#c)this.#o++;else break}(this.#o>100&&this.#o>this.#i.length/2||this.#o===this.#i.length)&&(this.#i=this.#i.slice(this.#o),this.#o=0)}#P(e){this.#a?this.#i.push(e):this.#s++}#N(){this.#a?this.#i.length>this.#o&&this.#i.pop():this.#s>0&&this.#s--}#S(){return this.#i.length-this.#o}get#O(){return this.#t?!0:this.#a?this.#S()<this.#d:this.#s<this.#d}get#U(){return this.#n<this.#b}#F(){this.#n--,this.#n===0&&this.emit("pendingZero"),this.#g(),this.emit("next")}#K(){this.#f=void 0,this.#k(),this.#_()}#M(e){if(this.#a){if(this.#v(e),this.#S()>=this.#d){let n=this.#i[this.#o],s=this.#c-(e-n);return this.#A(s),!0}return!1}if(this.#u===void 0){let r=this.#T-e;if(r<0){if(this.#x>0){let n=e-this.#x;if(n<this.#c)return this.#A(this.#c-n),!0}this.#s=this.#e?this.#n:0}else return this.#A(r),!0}return!1}#A(e){this.#f===void 0&&(this.#f=setTimeout(()=>{this.#K()},e))}#I(){this.#u&&(clearInterval(this.#u),this.#u=void 0)}#D(){this.#f&&(clearTimeout(this.#f),this.#f=void 0)}#g(){if(this.#r.size===0){if(this.#I(),this.emit("empty"),this.#n===0){if(this.#D(),this.#a&&this.#o>0){let r=Date.now();this.#v(r)}this.emit("idle")}return!1}let e=!1;if(!this.#l){let r=Date.now(),n=!this.#M(r);if(this.#O&&this.#U){let s=this.#r.dequeue();this.#t||(this.#P(r),this.#p()),this.emit("active"),s(),n&&this.#_(),e=!0}}return e}#_(){this.#t||this.#u!==void 0||this.#a||(this.#u=setInterval(()=>{this.#k()},this.#c),this.#T=Date.now()+this.#c)}#k(){this.#a||(this.#s===0&&this.#n===0&&this.#u&&this.#I(),this.#s=this.#e?this.#n:0),this.#B(),this.#p()}#B(){for(;this.#g(););}get concurrency(){return this.#b}set concurrency(e){if(!(typeof e=="number"&&e>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);this.#b=e,this.#B()}setPriority(e,r){if(typeof r!="number"||!Number.isFinite(r))throw new TypeError(`Expected \`priority\` to be a finite number, got \`${r}\` (${typeof r})`);this.#r.setPriority(e,r)}async add(e,r={}){return r={timeout:this.timeout,...r,id:r.id??(this.#R++).toString()},new Promise((n,s)=>{let o=Symbol(`task-${r.id}`),i=()=>{},a=async()=>{i(),this.#n++,this.#y.set(o,{id:r.id,priority:r.priority??0,startTime:Date.now(),timeout:r.timeout});let u;try{try{r.signal?.throwIfAborted()}catch(l){throw this.#V(),this.#y.delete(o),l}this.#x=Date.now();let f=e({signal:r.signal});if(r.timeout&&(f=qr(Promise.resolve(f),{milliseconds:r.timeout,message:`Task timed out after ${r.timeout}ms (queue has ${this.#n} running, ${this.#r.size} waiting)`})),r.signal){let{signal:l}=r;f=Promise.race([f,new Promise((d,p)=>{u=()=>{p(l.reason)},l.addEventListener("abort",u,{once:!0})})])}let h=await f;n(h),this.emit("completed",h)}catch(f){s(f),this.emit("error",f)}finally{u&&r.signal?.removeEventListener("abort",u),this.#y.delete(o),queueMicrotask(()=>{this.#F()})}};this.#r.enqueue(a,r);let c=()=>{if(this.#r instanceof tr){this.#r.remove(a);return}this.#r.remove?.(r.id)};if(r.signal){let{signal:u}=r,f=()=>{i(),c(),s(u.reason),this.#g(),this.emit("next")};if(i=()=>{u.removeEventListener("abort",f),this.#E.delete(i)},u.aborted){f();return}u.addEventListener("abort",f,{once:!0}),this.#E.add(i)}this.emit("add"),this.#g()})}async addAll(e,r){return Promise.all(e.map(async n=>this.add(n,r)))}start(){return this.#l?(this.#l=!1,this.#B(),this):this}pause(){this.#l=!0}clear(){for(let e of this.#E)e();this.#r=new this.#L,this.#I(),this.#C(),this.emit("empty"),this.#n===0&&(this.#D(),this.emit("idle")),this.emit("next")}async onEmpty(){this.#r.size!==0&&await this.#h("empty")}async onSizeLessThan(e){this.#r.size<e||await this.#h("next",()=>this.#r.size<e)}async onIdle(){this.#n===0&&this.#r.size===0||await this.#h("idle")}async onPendingZero(){this.#n!==0&&await this.#h("pendingZero")}async onRateLimit(){this.isRateLimited||await this.#h("rateLimit")}async onRateLimitCleared(){this.isRateLimited&&await this.#h("rateLimitCleared")}onError(){return new Promise((e,r)=>{let n=s=>{this.off("error",n),r(s)};this.on("error",n)})}async#h(e,r){return new Promise(n=>{let s=()=>{r&&!r()||(this.off(e,s),n())};this.on(e,s)})}get size(){return this.#r.size}sizeBy(e){return this.#r.filter(e).length}get pending(){return this.#n}get isPaused(){return this.#l}#q(){this.#t||(this.on("add",()=>{this.#r.size>0&&this.#p()}),this.on("next",()=>{this.#p()}))}#p(){this.#t||this.#w||(this.#w=!0,queueMicrotask(()=>{this.#w=!1,this.#C()}))}#V(){this.#t||(this.#N(),this.#p())}#C(){let e=this.#m;if(this.#t||this.#r.size===0){e&&(this.#m=!1,this.emit("rateLimitCleared"));return}let r;if(this.#a){let s=Date.now();this.#v(s),r=this.#S()}else r=this.#s;let n=r>=this.#d;n!==e&&(this.#m=n,this.emit(n?"rateLimit":"rateLimitCleared"))}get isRateLimited(){return this.#m}get isSaturated(){return this.#n===this.#b&&this.#r.size>0||this.isRateLimited&&this.#r.size>0}get runningTasks(){return[...this.#y.values()].map(e=>({...e,timeoutRemaining:e.timeout?Math.max(0,e.startTime+e.timeout-Date.now()):void 0}))}};var Vn=class{entries;validityMs;lastPruneTime=0;constructor(e){this.entries=new Map,this.validityMs=e.validityMs}put(e,r){this.entries.set(e,{value:r,validUntilMs:Date.now()+this.validityMs}),this.prune()}prune(){let e=Date.now();if(!(e-this.lastPruneTime<200)){this.lastPruneTime=e;for(let[r,n]of this.entries.entries())if(n.validUntilMs<e)this.entries.delete(r);else break}}has(e){return this.entries.has(e)}get(e){let r=this.entries.get(e);return r!=null&&r.validUntilMs>=Date.now()?r.value:void 0}clear(){this.entries=new Map,this.lastPruneTime=0}};var Tt;(function(t){let e;(function(a){let c;a.codec=()=>(c==null&&(c=Ee((l,d,p={})=>{p.lengthDelimited!==!1&&d.fork(),l.subscribe!=null&&(d.uint32(8),d.bool(l.subscribe)),l.topic!=null&&(d.uint32(18),d.string(l.topic)),p.lengthDelimited!==!1&&d.ldelim()},(l,d,p={})=>{let g={},b=d==null?l.len:l.pos+d;for(;l.pos<b;){let y=l.uint32();switch(y>>>3){case 1:{g.subscribe=l.bool();break}case 2:{g.topic=l.string();break}default:{l.skipType(y&7);break}}}return g},function*(l,d,p,g={}){let b=d==null?l.len:l.pos+d;for(;l.pos<b;){let y=l.uint32();switch(y>>>3){case 1:{yield{field:`${p}.subscribe`,value:l.bool()};break}case 2:{yield{field:`${p}.topic`,value:l.string()};break}default:{l.skipType(y&7);break}}}})),c);function u(l){return we(l,a.codec())}a.encode=u;function f(l,d){return ge(l,a.codec(),d)}a.decode=f;function h(l,d){return xe(l,a.codec(),d)}a.stream=h})(e=t.SubOpts||(t.SubOpts={}));let r;(function(a){let c;a.codec=()=>(c==null&&(c=Ee((l,d,p={})=>{p.lengthDelimited!==!1&&d.fork(),l.from!=null&&(d.uint32(10),d.bytes(l.from)),l.data!=null&&(d.uint32(18),d.bytes(l.data)),l.sequenceNumber!=null&&(d.uint32(26),d.bytes(l.sequenceNumber)),l.topic!=null&&(d.uint32(34),d.string(l.topic)),l.signature!=null&&(d.uint32(42),d.bytes(l.signature)),l.key!=null&&(d.uint32(50),d.bytes(l.key)),p.lengthDelimited!==!1&&d.ldelim()},(l,d,p={})=>{let g={},b=d==null?l.len:l.pos+d;for(;l.pos<b;){let y=l.uint32();switch(y>>>3){case 1:{g.from=l.bytes();break}case 2:{g.data=l.bytes();break}case 3:{g.sequenceNumber=l.bytes();break}case 4:{g.topic=l.string();break}case 5:{g.signature=l.bytes();break}case 6:{g.key=l.bytes();break}default:{l.skipType(y&7);break}}}return g},function*(l,d,p,g={}){let b=d==null?l.len:l.pos+d;for(;l.pos<b;){let y=l.uint32();switch(y>>>3){case 1:{yield{field:`${p}.from`,value:l.bytes()};break}case 2:{yield{field:`${p}.data`,value:l.bytes()};break}case 3:{yield{field:`${p}.sequenceNumber`,value:l.bytes()};break}case 4:{yield{field:`${p}.topic`,value:l.string()};break}case 5:{yield{field:`${p}.signature`,value:l.bytes()};break}case 6:{yield{field:`${p}.key`,value:l.bytes()};break}default:{l.skipType(y&7);break}}}})),c);function u(l){return we(l,a.codec())}a.encode=u;function f(l,d){return ge(l,a.codec(),d)}a.decode=f;function h(l,d){return xe(l,a.codec(),d)}a.stream=h})(r=t.Message||(t.Message={}));let n;t.codec=()=>(n==null&&(n=Ee((a,c,u={})=>{if(u.lengthDelimited!==!1&&c.fork(),a.subscriptions!=null&&a.subscriptions.length>0)for(let f of a.subscriptions)c.uint32(10),t.SubOpts.codec().encode(f,c);if(a.messages!=null&&a.messages.length>0)for(let f of a.messages)c.uint32(18),t.Message.codec().encode(f,c);a.control!=null&&(c.uint32(26),Hr.codec().encode(a.control,c)),u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={subscriptions:[],messages:[]},h=c==null?a.len:a.pos+c;for(;a.pos<h;){let l=a.uint32();switch(l>>>3){case 1:{if(u.limits?.subscriptions!=null&&f.subscriptions.length===u.limits.subscriptions)throw new re('Decode error - repeated field "subscriptions" had too many elements');f.subscriptions.push(t.SubOpts.codec().decode(a,a.uint32(),{limits:u.limits?.subscriptions$}));break}case 2:{if(u.limits?.messages!=null&&f.messages.length===u.limits.messages)throw new re('Decode error - repeated field "messages" had too many elements');f.messages.push(t.Message.codec().decode(a,a.uint32(),{limits:u.limits?.messages$}));break}case 3:{f.control=Hr.codec().decode(a,a.uint32(),{limits:u.limits?.control});break}default:{a.skipType(l&7);break}}}return f},function*(a,c,u,f={}){let h={subscriptions:0,messages:0},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let d=a.uint32();switch(d>>>3){case 1:{if(f.limits?.subscriptions!=null&&h.subscriptions===f.limits.subscriptions)throw new re('Streaming decode error - repeated field "subscriptions" had too many elements');for(let p of t.SubOpts.codec().stream(a,a.uint32(),`${u}.subscriptions[]`,{limits:f.limits?.subscriptions$}))yield{...p,index:h.subscriptions};h.subscriptions++;break}case 2:{if(f.limits?.messages!=null&&h.messages===f.limits.messages)throw new re('Streaming decode error - repeated field "messages" had too many elements');for(let p of t.Message.codec().stream(a,a.uint32(),`${u}.messages[]`,{limits:f.limits?.messages$}))yield{...p,index:h.messages};h.messages++;break}case 3:{yield*Hr.codec().stream(a,a.uint32(),`${u}.control`,{limits:f.limits?.control});break}default:{a.skipType(d&7);break}}}})),n);function s(a){return we(a,t.codec())}t.encode=s;function o(a,c){return ge(a,t.codec(),c)}t.decode=o;function i(a,c){return xe(a,t.codec(),c)}t.stream=i})(Tt||(Tt={}));var Hr;(function(t){let e;t.codec=()=>(e==null&&(e=Ee((o,i,a={})=>{if(a.lengthDelimited!==!1&&i.fork(),o.ihave!=null&&o.ihave.length>0)for(let c of o.ihave)i.uint32(10),$r.codec().encode(c,i);if(o.iwant!=null&&o.iwant.length>0)for(let c of o.iwant)i.uint32(18),jr.codec().encode(c,i);if(o.graft!=null&&o.graft.length>0)for(let c of o.graft)i.uint32(26),Zr.codec().encode(c,i);if(o.prune!=null&&o.prune.length>0)for(let c of o.prune)i.uint32(34),Yr.codec().encode(c,i);a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={ihave:[],iwant:[],graft:[],prune:[]},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{if(a.limits?.ihave!=null&&c.ihave.length===a.limits.ihave)throw new re('Decode error - repeated field "ihave" had too many elements');c.ihave.push($r.codec().decode(o,o.uint32(),{limits:a.limits?.ihave$}));break}case 2:{if(a.limits?.iwant!=null&&c.iwant.length===a.limits.iwant)throw new re('Decode error - repeated field "iwant" had too many elements');c.iwant.push(jr.codec().decode(o,o.uint32(),{limits:a.limits?.iwant$}));break}case 3:{if(a.limits?.graft!=null&&c.graft.length===a.limits.graft)throw new re('Decode error - repeated field "graft" had too many elements');c.graft.push(Zr.codec().decode(o,o.uint32(),{limits:a.limits?.graft$}));break}case 4:{if(a.limits?.prune!=null&&c.prune.length===a.limits.prune)throw new re('Decode error - repeated field "prune" had too many elements');c.prune.push(Yr.codec().decode(o,o.uint32(),{limits:a.limits?.prune$}));break}default:{o.skipType(f&7);break}}}return c},function*(o,i,a,c={}){let u={ihave:0,iwant:0,graft:0,prune:0},f=i==null?o.len:o.pos+i;for(;o.pos<f;){let h=o.uint32();switch(h>>>3){case 1:{if(c.limits?.ihave!=null&&u.ihave===c.limits.ihave)throw new re('Streaming decode error - repeated field "ihave" had too many elements');for(let l of $r.codec().stream(o,o.uint32(),`${a}.ihave[]`,{limits:c.limits?.ihave$}))yield{...l,index:u.ihave};u.ihave++;break}case 2:{if(c.limits?.iwant!=null&&u.iwant===c.limits.iwant)throw new re('Streaming decode error - repeated field "iwant" had too many elements');for(let l of jr.codec().stream(o,o.uint32(),`${a}.iwant[]`,{limits:c.limits?.iwant$}))yield{...l,index:u.iwant};u.iwant++;break}case 3:{if(c.limits?.graft!=null&&u.graft===c.limits.graft)throw new re('Streaming decode error - repeated field "graft" had too many elements');for(let l of Zr.codec().stream(o,o.uint32(),`${a}.graft[]`,{limits:c.limits?.graft$}))yield{...l,index:u.graft};u.graft++;break}case 4:{if(c.limits?.prune!=null&&u.prune===c.limits.prune)throw new re('Streaming decode error - repeated field "prune" had too many elements');for(let l of Yr.codec().stream(o,o.uint32(),`${a}.prune[]`,{limits:c.limits?.prune$}))yield{...l,index:u.prune};u.prune++;break}default:{o.skipType(h&7);break}}}})),e);function r(o){return we(o,t.codec())}t.encode=r;function n(o,i){return ge(o,t.codec(),i)}t.decode=n;function s(o,i){return xe(o,t.codec(),i)}t.stream=s})(Hr||(Hr={}));var $r;(function(t){let e;t.codec=()=>(e==null&&(e=Ee((o,i,a={})=>{if(a.lengthDelimited!==!1&&i.fork(),o.topic!=null&&(i.uint32(10),i.string(o.topic)),o.messageIDs!=null&&o.messageIDs.length>0)for(let c of o.messageIDs)i.uint32(18),i.bytes(c);a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={messageIDs:[]},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{c.topic=o.string();break}case 2:{if(a.limits?.messageIDs!=null&&c.messageIDs.length===a.limits.messageIDs)throw new re('Decode error - repeated field "messageIDs" had too many elements');c.messageIDs.push(o.bytes());break}default:{o.skipType(f&7);break}}}return c},function*(o,i,a,c={}){let u={messageIDs:0},f=i==null?o.len:o.pos+i;for(;o.pos<f;){let h=o.uint32();switch(h>>>3){case 1:{yield{field:`${a}.topic`,value:o.string()};break}case 2:{if(c.limits?.messageIDs!=null&&u.messageIDs===c.limits.messageIDs)throw new re('Streaming decode error - repeated field "messageIDs" had too many elements');yield{field:`${a}.messageIDs[]`,index:u.messageIDs,value:o.bytes()},u.messageIDs++;break}default:{o.skipType(h&7);break}}}})),e);function r(o){return we(o,t.codec())}t.encode=r;function n(o,i){return ge(o,t.codec(),i)}t.decode=n;function s(o,i){return xe(o,t.codec(),i)}t.stream=s})($r||($r={}));var jr;(function(t){let e;t.codec=()=>(e==null&&(e=Ee((o,i,a={})=>{if(a.lengthDelimited!==!1&&i.fork(),o.messageIDs!=null&&o.messageIDs.length>0)for(let c of o.messageIDs)i.uint32(10),i.bytes(c);a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={messageIDs:[]},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{if(a.limits?.messageIDs!=null&&c.messageIDs.length===a.limits.messageIDs)throw new re('Decode error - repeated field "messageIDs" had too many elements');c.messageIDs.push(o.bytes());break}default:{o.skipType(f&7);break}}}return c},function*(o,i,a,c={}){let u={messageIDs:0},f=i==null?o.len:o.pos+i;for(;o.pos<f;){let h=o.uint32();switch(h>>>3){case 1:{if(c.limits?.messageIDs!=null&&u.messageIDs===c.limits.messageIDs)throw new re('Streaming decode error - repeated field "messageIDs" had too many elements');yield{field:`${a}.messageIDs[]`,index:u.messageIDs,value:o.bytes()},u.messageIDs++;break}default:{o.skipType(h&7);break}}}})),e);function r(o){return we(o,t.codec())}t.encode=r;function n(o,i){return ge(o,t.codec(),i)}t.decode=n;function s(o,i){return xe(o,t.codec(),i)}t.stream=s})(jr||(jr={}));var Zr;(function(t){let e;t.codec=()=>(e==null&&(e=Ee((o,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),o.topic!=null&&(i.uint32(10),i.string(o.topic)),a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();f>>>3===1?c.topic=o.string():o.skipType(f&7)}return c},function*(o,i,a,c={}){let u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();f>>>3===1?yield{field:`${a}.topic`,value:o.string()}:o.skipType(f&7)}})),e);function r(o){return we(o,t.codec())}t.encode=r;function n(o,i){return ge(o,t.codec(),i)}t.decode=n;function s(o,i){return xe(o,t.codec(),i)}t.stream=s})(Zr||(Zr={}));var Yr;(function(t){let e;t.codec=()=>(e==null&&(e=Ee((o,i,a={})=>{if(a.lengthDelimited!==!1&&i.fork(),o.topic!=null&&(i.uint32(10),i.string(o.topic)),o.peers!=null&&o.peers.length>0)for(let c of o.peers)i.uint32(18),Gr.codec().encode(c,i);o.backoff!=null&&(i.uint32(24),i.uint64(o.backoff)),a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={peers:[]},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{c.topic=o.string();break}case 2:{if(a.limits?.peers!=null&&c.peers.length===a.limits.peers)throw new re('Decode error - repeated field "peers" had too many elements');c.peers.push(Gr.codec().decode(o,o.uint32(),{limits:a.limits?.peers$}));break}case 3:{c.backoff=o.uint64();break}default:{o.skipType(f&7);break}}}return c},function*(o,i,a,c={}){let u={peers:0},f=i==null?o.len:o.pos+i;for(;o.pos<f;){let h=o.uint32();switch(h>>>3){case 1:{yield{field:`${a}.topic`,value:o.string()};break}case 2:{if(c.limits?.peers!=null&&u.peers===c.limits.peers)throw new re('Streaming decode error - repeated field "peers" had too many elements');for(let l of Gr.codec().stream(o,o.uint32(),`${a}.peers[]`,{limits:c.limits?.peers$}))yield{...l,index:u.peers};u.peers++;break}case 3:{yield{field:`${a}.backoff`,value:o.uint64()};break}default:{o.skipType(h&7);break}}}})),e);function r(o){return we(o,t.codec())}t.encode=r;function n(o,i){return ge(o,t.codec(),i)}t.decode=n;function s(o,i){return xe(o,t.codec(),i)}t.stream=s})(Yr||(Yr={}));var Gr;(function(t){let e;t.codec=()=>(e==null&&(e=Ee((o,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),o.peerID!=null&&(i.uint32(10),i.bytes(o.peerID)),o.signedPeerRecord!=null&&(i.uint32(18),i.bytes(o.signedPeerRecord)),a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{c.peerID=o.bytes();break}case 2:{c.signedPeerRecord=o.bytes();break}default:{o.skipType(f&7);break}}}return c},function*(o,i,a,c={}){let u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{yield{field:`${a}.peerID`,value:o.bytes()};break}case 2:{yield{field:`${a}.signedPeerRecord`,value:o.bytes()};break}default:{o.skipType(f&7);break}}}})),e);function r(o){return we(o,t.codec())}t.encode=r;function n(o,i){return ge(o,t.codec(),i)}t.decode=n;function s(o,i){return xe(o,t.codec(),i)}t.stream=s})(Gr||(Gr={}));var zn=class extends _t{peerId;shutDownController;inboundPb;outboundPb;constructor(e){super(),this.peerId=e,this.shutDownController=new AbortController}attachInboundStream(e,r){this.inboundPb=ui(e,r).pb(Tt),Promise.resolve().then(async()=>{for(;;){if(this.inboundPb==null)return;let n=await this.inboundPb.read({signal:this.shutDownController.signal});this.safeDispatchEvent("message",{detail:n})}}).catch(n=>{this.inboundPb?.unwrap().unwrap().abort(n)})}attachOutboundStream(e,r){this.outboundPb=ui(e,r).pb(Tt)}write(e){this.outboundPb!=null&&this.outboundPb.write(e,{signal:this.shutDownController.signal}).catch(r=>{this.outboundPb?.unwrap().unwrap().abort(r)})}close(){this.shutDownController.abort(),Promise.all([this.inboundPb?.unwrap().unwrap().close().catch(e=>{this.inboundPb?.unwrap().unwrap().abort(e)}),this.outboundPb?.unwrap().unwrap().close().catch(e=>{this.inboundPb?.unwrap().unwrap().abort(e)})]).finally(()=>{this.safeDispatchEvent("close")})}};function Hc(){return BigInt(`0x${z(Pn(8),"base16")}`)}var $c=(t,e)=>{let r=j(e.toString(16).padStart(16,"0"),"base16"),n=He(t),s=new Uint8Array(n.byteLength+r.length);return s.set(n,0),s.set(r,n.byteLength),s},jc=t=>St.encode(t);var hd=async t=>{if(t.sequenceNumber==null||t.from==null||t.signature==null)return!1;let e=Fr(Je(t.from));if(e.publicKey!=null)return!0;if(t.key!=null){let r=t.key;return ri(ti(r)).equals(e)}return!1},Zc=async t=>{if(t.from==null)throw new ee("RPC message was missing from");if(!await hd(t))return{type:"unsigned",topic:t.topic??"",data:t.data??new Uint8Array(0)};let e=Fr(Je(t.from)),r=t.key??e.publicKey;if(r==null)throw new ee("RPC message was missing public key");return{type:"signed",from:e,topic:t.topic??"",sequenceNumber:pd(t.sequenceNumber??new Uint8Array(0)),data:t.data??new Uint8Array(0),signature:t.signature??new Uint8Array(0),key:r instanceof Uint8Array?ti(r):r}},Xr=t=>t.type==="signed"?{from:t.from.toMultihash().bytes,data:t.data,sequenceNumber:dd(t.sequenceNumber),topic:t.topic,signature:t.signature,key:t.key?He(t.key):void 0}:{data:t.data,topic:t.topic},dd=t=>{let e=t.toString(16);return e.length%2!==0&&(e=`0${e}`),j(e,"base16")},pd=t=>BigInt(`0x${z(t,"base16")}`);var Yc=j("libp2p-pubsub:");async function Gc(t,e,r){let n={type:"signed",topic:e.topic,data:e.data,sequenceNumber:e.sequenceNumber,from:Kc(t)},s=Tn([Yc,r(Xr(n)).subarray()]);return n.signature=await t.sign(s),n.key=t.publicKey,n}async function Xc(t,e){if(t.type!=="signed")throw new Error('Message type must be "signed" to be verified');if(t.signature==null)throw new Error("Message must contain a signature to be verified");if(t.from==null)throw new Error("Message must contain a from property to be verified");let r=Tn([Yc,e({...Xr(t),signature:void 0,key:void 0}).subarray()]);return md(t).verify(r,t.signature)}function md(t){if(t.type!=="signed")throw new Error('Message type must be "signed" to have a public key');if(t.from==null)throw new Error("Could not get the public key from the originator id");if(t.key!=null)return t.key;if(t.from.publicKey!=null)return t.from.publicKey;throw new Error("Could not get the public key from the originator id")}var Hn=class extends _t{log;started;topics;subscriptions;peers;globalSignaturePolicy;canRelayMessage;emitSelf;topicValidators;queue;protocol;components;_registrarTopologyId;maxInboundStreams;maxOutboundStreams;seenCache;constructor(e,r){super(),this.log=e.logger.forComponent("libp2p:floodsub"),this.components=e,this.protocol=r.protocol??di,this.started=!1,this.topics=new Map,this.subscriptions=new Set,this.peers=new Kr,this.globalSignaturePolicy=r.globalSignaturePolicy==="StrictNoSign"?"StrictNoSign":"StrictSign",this.canRelayMessage=r.canRelayMessage??!0,this.emitSelf=r.emitSelf??!1,this.topicValidators=new Map,this.queue=new zr({concurrency:r.messageProcessingConcurrency??10}),this.maxInboundStreams=r.maxInboundStreams??1,this.maxOutboundStreams=r.maxOutboundStreams??1,this.seenCache=new Vn({validityMs:r?.seenTTL??3e4}),this._onIncomingStream=this._onIncomingStream.bind(this),this._onPeerConnected=this._onPeerConnected.bind(this),this._onPeerDisconnected=this._onPeerDisconnected.bind(this)}[or]=!0;[Symbol.toStringTag]="@libp2p/floodsub";[yi]=["@libp2p/pubsub"];[gi]=["@libp2p/identify"];async start(){this.started||(this.log("starting"),await this.components.registrar.handle(this.protocol,this._onIncomingStream,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this._registrarTopologyId=await this.components.registrar.register(this.protocol,{onConnect:this._onPeerConnected,onDisconnect:this._onPeerDisconnected}),this.log("started"),this.started=!0)}async stop(){if(!this.started)return;let e=this.components.registrar;this._registrarTopologyId!=null&&e.unregister(this._registrarTopologyId),await e.unhandle(this.protocol),this.log("stopping");for(let r of this.peers.values())r.close();this.peers.clear(),this.subscriptions=new Set,this.started=!1,this.log("stopped")}isStarted(){return this.started}_onIncomingStream(e,r){this.addPeer(r.remotePeer,e).attachInboundStream(e)}async _onPeerConnected(e,r){if(this.log("connected %p",e),r.streams.find(o=>o.direction==="outbound"&&o.protocol===this.protocol)){this.log("outbound pubsub stream already present on connection from %p",e);return}let n=await r.newStream(this.protocol);this.addPeer(e,n).attachOutboundStream(n),this.send(e,{subscriptions:Array.from(this.subscriptions).map(o=>o.toString()),subscribe:!0})}_onPeerDisconnected(e,r){this.log("connection ended %p",e),this._removePeer(e)}addPeer(e,r){let n=this.peers.get(e);if(n!=null)return n;this.log("new peer %p",e);let s=new zn(e);return this.peers.set(e,s),s.addEventListener("message",o=>{let i=o.detail,a=[];for(let c of i.messages??[]){if(c.from==null||c.data==null||c.topic==null){this.log("message from %p was missing from, data or topic fields, dropping",e);continue}a.push({from:c.from,data:c.data,topic:c.topic,sequenceNumber:c.sequenceNumber??void 0,signature:c.signature??void 0,key:c.key??void 0})}this.processRpc(s,{subscriptions:(i.subscriptions??[]).map(c=>({subscribe:!!c.subscribe,topic:c.topic??""})),messages:a}).catch(c=>{this.log(c)})}),s.addEventListener("close",()=>this._removePeer(e),{once:!0}),s}_removePeer(e){let r=this.peers.get(e);if(r!=null){r.close(),this.log("delete peer %p",e),this.peers.delete(e);for(let n of this.topics.values())n.delete(e)}}async processRpc(e,r){this.log("rpc from %p",e.peerId);let{subscriptions:n,messages:s}=r;return n!=null&&n.length>0&&(this.log("subscription update from %p",e.peerId),n.forEach(o=>{this.processRpcSubOpt(e.peerId,o)}),super.dispatchEvent(new CustomEvent("subscription-change",{detail:{peerId:e.peerId,subscriptions:n.map(({topic:o,subscribe:i})=>({topic:`${o??""}`,subscribe:!!i}))}}))),s!=null&&s.length>0&&(this.log("messages from %p",e.peerId),this.queue.addAll(s.map(o=>async()=>{if(o.topic==null||!this.subscriptions.has(o.topic)&&!this.canRelayMessage)return this.log("received message we didn't subscribe to. Dropping."),!1;try{let i=await Zc(o);await this.processMessage(e.peerId,i)}catch(i){this.log.error("failed to queue messages from %p - %e",e.peerId,i)}})).catch(o=>{this.log(o)})),!0}processRpcSubOpt(e,r){let n=r.topic;if(n==null)return;let s=this.topics.get(n);s==null&&(s=new Mr,this.topics.set(n,s)),r.subscribe===!0?s.add(e):s.delete(e)}async processMessage(e,r){if(this.components.peerId.equals(e)&&!this.emitSelf)return;let n=await this.getMsgId(r),s=z(n,"base64");if(!this.seenCache.has(s)){this.seenCache.put(s,!0);try{await this.validate(e,r)}catch(o){this.log("Message is invalid, dropping it. %O",o);return}this.subscriptions.has(r.topic)&&(!this.components.peerId.equals(e)||this.emitSelf)&&super.dispatchEvent(new CustomEvent("message",{detail:r})),await this.publishMessage(e,r)}}getMsgId(e){switch(this.globalSignaturePolicy){case"StrictSign":if(e.type!=="signed")throw new ee('Message type should be "signed" when signature policy is StrictSign but it was not');if(e.sequenceNumber==null)throw new ee("Need sequence number when signature policy is StrictSign but it was missing");if(e.key==null)throw new ee("Need key when signature policy is StrictSign but it was missing");return $c(e.key,e.sequenceNumber);case"StrictNoSign":return jc(e.data);default:throw new ee("Cannot get message id: unhandled signature policy")}}encodeMessage(e){return Tt.Message.encode(e)}send(e,r){let{messages:n,subscriptions:s,subscribe:o}=r;this.sendRpc(e,{subscriptions:(s??[]).map(i=>({topic:i,subscribe:!!o})),messages:(n??[]).map(Xr)})}sendRpc(e,r){let n=this.peers.get(e);if(n==null){this.log.error("cannot send RPC to %p as there are no streams to it available",e);return}n.write(r)}async validate(e,r){switch(this.globalSignaturePolicy){case"StrictNoSign":if(r.type!=="unsigned")throw new ee('Message type should be "unsigned" when signature policy is StrictNoSign but it was not');if(r.signature!=null)throw new ee("StrictNoSigning: signature should not be present");if(r.key!=null)throw new ee("StrictNoSigning: key should not be present");if(r.sequenceNumber!=null)throw new ee("StrictNoSigning: seqno should not be present");break;case"StrictSign":if(r.type!=="signed")throw new ee('Message type should be "signed" when signature policy is StrictSign but it was not');if(r.signature==null)throw new ee("StrictSigning: Signing required and no signature was present");if(r.sequenceNumber==null)throw new ee("StrictSigning: Signing required and no sequenceNumber was present");if(!await Xc(r,this.encodeMessage.bind(this)))throw new ee("StrictSigning: Invalid message signature");break;default:throw new ee("Cannot validate message: unhandled signature policy")}let s=this.topicValidators.get(r.topic);if(s!=null){let o=await s(e,r);if(o===rr.Reject||o===rr.Ignore)throw new ee("Message validation failed")}}async buildMessage(e){switch(this.globalSignaturePolicy){case"StrictSign":return Gc(this.components.privateKey,e,this.encodeMessage.bind(this));case"StrictNoSign":return Promise.resolve({type:"unsigned",...e});default:throw new ee("Cannot build message: unhandled signature policy")}}getSubscribers(e){if(!this.started)throw new en("not started yet");if(e==null)throw new $("Topic is required");let r=this.topics.get(e.toString());return r==null?[]:Array.from(r.values())}async publish(e,r){if(!this.started)throw new Error("Pubsub has not started");let n={from:this.components.peerId,topic:e,data:r??new Uint8Array(0),sequenceNumber:Hc()};this.log("publish topic: %s from: %p data: %m",e,n.from,n.data);let s=await this.buildMessage(n),o=!1;this.emitSelf&&this.subscriptions.has(e)&&(o=!0,super.dispatchEvent(new CustomEvent("message",{detail:s})));let i=await this.publishMessage(this.components.peerId,s);return o&&(i.recipients=[...i.recipients,this.components.peerId]),i}async publishMessage(e,r){let n=this.getSubscribers(r.topic),s=[];return n==null||n.length===0?(this.log("no peers are subscribed to topic %s",r.topic),{recipients:s}):(n.forEach(o=>{if(this.components.peerId.equals(o)){this.log("not sending message on topic %s to myself",r.topic);return}if(o.equals(e)){this.log("not sending message on topic %s to sender %p",r.topic,o);return}this.log("publish msgs on topics %s %p",r.topic,o),s.push(o),this.send(o,{messages:[r]})}),{recipients:s})}subscribe(e){if(!this.started)throw new Error("Pubsub has not started");if(!this.subscriptions.has(e)){this.log("subscribe to topic: %s",e),this.subscriptions.add(e);for(let r of this.peers.keys())this.send(r,{subscriptions:[e],subscribe:!0})}}unsubscribe(e){if(!this.started)throw new Error("Pubsub is not started");if(this.subscriptions.has(e)){this.log("unsubscribe from %s",e),this.subscriptions.delete(e);for(let r of this.peers.keys())this.send(r,{subscriptions:[e],subscribe:!1})}}getTopics(){if(!this.started)throw new Error("Pubsub is not started");return Array.from(this.subscriptions)}getPeers(){if(!this.started)throw new Error("Pubsub is not started");return Array.from(this.peers.keys())}};var di="/floodsub/1.0.0",bd="StrictSign",yd="StrictNoSign",rr;(function(t){t.Accept="accept",t.Ignore="ignore",t.Reject="reject"})(rr||(rr={}));function gd(t){return!!t?.[or]}function wd(t={}){return e=>new Hn(e,t)}return ou(xd);})();
|
|
2
|
+
"use strict";var Libp2PFloodsub=(()=>{var Wc=Object.create;var Jr=Object.defineProperty;var Jc=Object.getOwnPropertyDescriptor;var Qc=Object.getOwnPropertyNames;var eu=Object.getPrototypeOf,tu=Object.prototype.hasOwnProperty;var ru=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),H=(t,e)=>{for(var r in e)Jr(t,r,{get:e[r],enumerable:!0})},bi=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Qc(e))!tu.call(t,s)&&s!==r&&Jr(t,s,{get:()=>e[s],enumerable:!(n=Jc(e,s))||n.enumerable});return t};var nu=(t,e,r)=>(r=t!=null?Wc(eu(t)):{},bi(e||!t||!t.__esModule?Jr(r,"default",{value:t,enumerable:!0}):r,t)),ou=t=>bi(Jr({},"__esModule",{value:!0}),t);var zc=ru((Rw,fi)=>{"use strict";var ud=Object.prototype.hasOwnProperty,me="~";function Vr(){}Object.create&&(Vr.prototype=Object.create(null),new Vr().__proto__||(me=!1));function fd(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function Vc(t,e,r,n,s){if(typeof r!="function")throw new TypeError("The listener must be a function");var o=new fd(r,n||t,s),i=me?me+e:e;return t._events[i]?t._events[i].fn?t._events[i]=[t._events[i],o]:t._events[i].push(o):(t._events[i]=o,t._eventsCount++),t}function qn(t,e){--t._eventsCount===0?t._events=new Vr:delete t._events[e]}function pe(){this._events=new Vr,this._eventsCount=0}pe.prototype.eventNames=function(){var e=[],r,n;if(this._eventsCount===0)return e;for(n in r=this._events)ud.call(r,n)&&e.push(me?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(r)):e};pe.prototype.listeners=function(e){var r=me?me+e:e,n=this._events[r];if(!n)return[];if(n.fn)return[n.fn];for(var s=0,o=n.length,i=new Array(o);s<o;s++)i[s]=n[s].fn;return i};pe.prototype.listenerCount=function(e){var r=me?me+e:e,n=this._events[r];return n?n.fn?1:n.length:0};pe.prototype.emit=function(e,r,n,s,o,i){var a=me?me+e:e;if(!this._events[a])return!1;var c=this._events[a],u=arguments.length,f,h;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),u){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,r),!0;case 3:return c.fn.call(c.context,r,n),!0;case 4:return c.fn.call(c.context,r,n,s),!0;case 5:return c.fn.call(c.context,r,n,s,o),!0;case 6:return c.fn.call(c.context,r,n,s,o,i),!0}for(h=1,f=new Array(u-1);h<u;h++)f[h-1]=arguments[h];c.fn.apply(c.context,f)}else{var l=c.length,d;for(h=0;h<l;h++)switch(c[h].once&&this.removeListener(e,c[h].fn,void 0,!0),u){case 1:c[h].fn.call(c[h].context);break;case 2:c[h].fn.call(c[h].context,r);break;case 3:c[h].fn.call(c[h].context,r,n);break;case 4:c[h].fn.call(c[h].context,r,n,s);break;default:if(!f)for(d=1,f=new Array(u-1);d<u;d++)f[d-1]=arguments[d];c[h].fn.apply(c[h].context,f)}}return!0};pe.prototype.on=function(e,r,n){return Vc(this,e,r,n,!1)};pe.prototype.once=function(e,r,n){return Vc(this,e,r,n,!0)};pe.prototype.removeListener=function(e,r,n,s){var o=me?me+e:e;if(!this._events[o])return this;if(!r)return qn(this,o),this;var i=this._events[o];if(i.fn)i.fn===r&&(!s||i.once)&&(!n||i.context===n)&&qn(this,o);else{for(var a=0,c=[],u=i.length;a<u;a++)(i[a].fn!==r||s&&!i[a].once||n&&i[a].context!==n)&&c.push(i[a]);c.length?this._events[o]=c.length===1?c[0]:c:qn(this,o)}return this};pe.prototype.removeAllListeners=function(e){var r;return e?(r=me?me+e:e,this._events[r]&&qn(this,r)):(this._events=new Vr,this._eventsCount=0),this};pe.prototype.off=pe.prototype.removeListener;pe.prototype.addListener=pe.prototype.on;pe.prefixed=me;pe.EventEmitter=pe;typeof fi<"u"&&(fi.exports=pe)});var xd={};H(xd,{StrictNoSign:()=>yd,StrictSign:()=>bd,TopicValidatorResult:()=>rr,floodsub:()=>wd,isPubSub:()=>gd,protocol:()=>di,pubSubSymbol:()=>or});var or=Symbol.for("@libp2p/pubsub");var $=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},Dt=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var Qr=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var ee=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var en=class extends Error{static name="NotStartedError";constructor(e="Not started"){super(e),this.name="NotStartedError"}};var ht=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var $n=Symbol.for("@libp2p/peer-id");function su(t){return typeof t?.handleEvent=="function"}function iu(t){return(t!==!0&&t!==!1&&t?.once)??!1}var _t=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let r=this.#e.get(e);return r==null?0:r.length}addEventListener(e,r,n){let s=iu(n);super.addEventListener(e,i=>{if(s){let a=this.#e.get(i.type);a!=null&&(a=a.filter(({callback:c})=>c!==r),this.#e.set(i.type,a))}su(r)?r.handleEvent(i):r(i)},n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:r,once:s})}removeEventListener(e,r,n){super.removeEventListener(e.toString(),r??null,n);let s=this.#e.get(e);s!=null&&(s=s.filter(({callback:o})=>o!==r),this.#e.set(e,s))}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};var yi=Symbol.for("@libp2p/service-capabilities"),gi=Symbol.for("@libp2p/service-dependencies");var Xn={};H(Xn,{base58btc:()=>Y,base58flickr:()=>pu});var Wd=new Uint8Array(0);function wi(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function Me(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return dt(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return dt(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function xi(t){return new TextEncoder().encode(t)}function Ei(t){return new TextDecoder().decode(t)}function au(t){return t?.buffer instanceof ArrayBuffer}function dt(t){return au(t)?t:t.slice()}function cu(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var s=0;s<t.length;s++){var o=t.charAt(s),i=o.charCodeAt(0);if(r[i]!==255)throw new TypeError(o+" is ambiguous");r[i]=s}var a=t.length,c=t.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function h(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var g=0,b=0,y=0,v=p.length;y!==v&&p[y]===0;)y++,g++;for(var S=(v-y)*f+1>>>0,L=new Uint8Array(S);y!==v;){for(var T=p[y],R=0,k=S-1;(T!==0||R<b)&&k!==-1;k--,R++)T+=256*L[k]>>>0,L[k]=T%a>>>0,T=T/a>>>0;if(T!==0)throw new Error("Non-zero carry");b=R,y++}for(var B=S-b;B!==S&&L[B]===0;)B++;for(var N=c.repeat(g);B<S;++B)N+=t.charAt(L[B]);return N}function l(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var g=0;if(p[g]!==" "){for(var b=0,y=0;p[g]===c;)b++,g++;for(var v=(p.length-g)*u+1>>>0,S=new Uint8Array(v);p[g];){var L=r[p.charCodeAt(g)];if(L===255)return;for(var T=0,R=v-1;(L!==0||T<y)&&R!==-1;R--,T++)L+=a*S[R]>>>0,S[R]=L%256>>>0,L=L/256>>>0;if(L!==0)throw new Error("Non-zero carry");y=T,g++}if(p[g]!==" "){for(var k=v-y;k!==v&&S[k]===0;)k++;for(var B=new Uint8Array(b+(v-k)),N=b;k!==v;)B[N++]=S[k++];return B}}}function d(p){var g=l(p);if(g)return g;throw new Error(`Non-${e} character`)}return{encode:h,decodeUnsafe:l,decode:d}}var uu=cu,fu=uu,Si=fu;var jn=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,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,r,n){this.name=e,this.prefix=r;let s=r.codePointAt(0);if(s===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=s,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 Ai(this,e)}},Yn=class{decoders;constructor(e){this.decoders=e}or(e){return Ai(this,e)}decode(e){let r=e[0],n=this.decoders[r];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 Ai(t,e){return new Yn({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Gn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,s){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=s,this.encoder=new jn(e,r,n),this.decoder=new Zn(e,r,s)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function kt({name:t,prefix:e,encode:r,decode:n}){return new Gn(t,e,r,n)}function We({name:t,prefix:e,alphabet:r}){let{encode:n,decode:s}=Si(r,t);return kt({prefix:e,name:t,encode:n,decode:o=>Me(s(o))})}function lu(t,e,r,n){let s=t.length;for(;t[s-1]==="=";)--s;let o=new Uint8Array(s*r/8|0),i=0,a=0,c=0;for(let u=0;u<s;++u){let f=e[t[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,o[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return o}function hu(t,e,r){let n=e[e.length-1]==="=",s=(1<<r)-1,o="",i=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],i+=8;i>r;)i-=r,o+=e[s&a>>i];if(i!==0&&(o+=e[s&a<<r-i]),n)for(;(o.length*r&7)!==0;)o+="=";return o}function du(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function X({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let s=du(n);return kt({prefix:e,name:t,encode(o){return hu(o,n,r)},decode(o){return lu(o,s,r,t)}})}var Y=We({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),pu=We({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Wn={};H(Wn,{base32:()=>Ct,base32hex:()=>gu,base32hexpad:()=>xu,base32hexpadupper:()=>Eu,base32hexupper:()=>wu,base32pad:()=>bu,base32padupper:()=>yu,base32upper:()=>mu,base32z:()=>vu});var Ct=X({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),mu=X({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),bu=X({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),yu=X({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),gu=X({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),wu=X({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),xu=X({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Eu=X({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),vu=X({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Jn={};H(Jn,{base36:()=>sr,base36upper:()=>Su});var sr=We({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Su=We({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Au=Ti,Ii=128,Iu=127,Bu=~Iu,Tu=Math.pow(2,31);function Ti(t,e,r){e=e||[],r=r||0;for(var n=r;t>=Tu;)e[r++]=t&255|Ii,t/=128;for(;t&Bu;)e[r++]=t&255|Ii,t>>>=7;return e[r]=t|0,Ti.bytes=r-n+1,e}var Lu=Qn,Du=128,Bi=127;function Qn(t,n){var r=0,n=n||0,s=0,o=n,i,a=t.length;do{if(o>=a)throw Qn.bytes=0,new RangeError("Could not decode varint");i=t[o++],r+=s<28?(i&Bi)<<s:(i&Bi)*Math.pow(2,s),s+=7}while(i>=Du);return Qn.bytes=o-n,r}var _u=Math.pow(2,7),ku=Math.pow(2,14),Cu=Math.pow(2,21),Ru=Math.pow(2,28),Pu=Math.pow(2,35),Nu=Math.pow(2,42),Ou=Math.pow(2,49),Uu=Math.pow(2,56),Fu=Math.pow(2,63),Ku=function(t){return t<_u?1:t<ku?2:t<Cu?3:t<Ru?4:t<Pu?5:t<Nu?6:t<Ou?7:t<Uu?8:t<Fu?9:10},Mu={encode:Au,decode:Lu,encodingLength:Ku},qu=Mu,ir=qu;function ar(t,e=0){return[ir.decode(t,e),ir.decode.bytes]}function Rt(t,e,r=0){return ir.encode(t,e,r),e}function Pt(t){return ir.encodingLength(t)}function Re(t,e){let r=e.byteLength,n=Pt(t),s=n+Pt(r),o=new Uint8Array(s+r);return Rt(t,o,0),Rt(r,o,n),o.set(e,s),new Nt(t,r,e,o)}function Je(t){let e=Me(t),[r,n]=ar(e),[s,o]=ar(e.subarray(n)),i=e.subarray(n+o);if(i.byteLength!==s)throw new Error("Incorrect length");return new Nt(r,s,i,e)}function Li(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&wi(t.bytes,r.bytes)}}var Nt=class{code;size;digest;bytes;constructor(e,r,n,s){this.code=e,this.size=r,this.digest=dt(n),this.bytes=dt(s)}};function Di(t,e){let{bytes:r,version:n}=t;return n===0?zu(r,eo(t),e??Y.encoder):Hu(r,eo(t),e??Ct.encoder)}var _i=new WeakMap;function eo(t){let e=_i.get(t);if(e==null){let r=new Map;return _i.set(t,r),r}return e}var le=class t{code;version;multihash;bytes;"/";constructor(e,r,n,s){this.code=r,this.version=e,this.multihash=n,this.bytes=dt(s),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:r}=this;if(e!==cr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==$u)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:r}=this.multihash,n=Re(e,r);return t.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 t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&Li(e.multihash,n.multihash)}toString(e){return Di(this,e)}toJSON(){return{"/":Di(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 r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:s,multihash:o,bytes:i}=r;return new t(n,s,o,i??ki(n,s,o.bytes))}else if(r[ju]===!0){let{version:n,multihash:s,code:o}=r,i=Je(s);return t.create(n,o,i)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==cr)throw new Error(`Version 0 CID must use dag-pb (code: ${cr}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let s=ki(e,r,n.bytes);return new t(e,r,n,s)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,cr,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,s=Me(e.subarray(n,n+r.multihashSize));if(s.byteLength!==r.multihashSize)throw new Error("Incorrect length");let o=s.subarray(r.multihashSize-r.digestSize),i=new Nt(r.multihashCode,r.digestSize,o,s);return[r.version===0?t.createV0(i):t.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[h,l]=ar(e.subarray(r));return r+=l,h},s=n(),o=cr;if(s===18?(s=0,r=0):o=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let i=r,a=n(),c=n(),u=r+c,f=u-i;return{version:s,codec:o,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(e,r){let[n,s]=Vu(e,r),o=t.decode(s);if(o.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return eo(o).set(n,e),o}};function Vu(t,e){switch(t[0]){case"Q":{let r=e??Y;return[Y.prefix,r.decode(`${Y.prefix}${t}`)]}case Y.prefix:{let r=e??Y;return[Y.prefix,r.decode(t)]}case Ct.prefix:{let r=e??Ct;return[Ct.prefix,r.decode(t)]}case sr.prefix:{let r=e??sr;return[sr.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function zu(t,e,r){let{prefix:n}=r;if(n!==Y.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let s=e.get(n);if(s==null){let o=r.encode(t).slice(1);return e.set(n,o),o}else return s}function Hu(t,e,r){let{prefix:n}=r,s=e.get(n);if(s==null){let o=r.encode(t);return e.set(n,o),o}else return s}var cr=112,$u=18;function ki(t,e,r){let n=Pt(t),s=n+Pt(e),o=new Uint8Array(s+r.byteLength);return Rt(t,o,0),Rt(e,o,n),o.set(r,s),o}var ju=Symbol.for("@ipld/js-cid/CID");var to={};H(to,{identity:()=>Be});var Ci=0,Zu="identity",Ri=Me;function Yu(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return Re(Ci,Ri(t))}var Be={code:Ci,name:Zu,encode:Ri,digest:Yu};function Ae(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function Gu(t){return t.buffer instanceof ArrayBuffer}function Pe(t){return Gu(t)?t:t.slice()}async function Pi(t,e,r,n){let s=await crypto.subtle.importKey("jwk",t,{name:"ECDSA",namedCurve:t.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let o=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},s,Pe(e),Pe(r.subarray()));return n?.signal?.throwIfAborted(),o}function qe(t=0){return new Uint8Array(t)}function ur(t=0){return new Uint8Array(t)}function ro(t,e){e==null&&(e=t.reduce((s,o)=>s+o.length,0));let r=ur(e),n=0;for(let s of t)r.set(s,n),n+=s.length;return r}function Ni(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}var Ui=Symbol.for("@achingbrain/uint8arraylist");function Oi(t,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let r=0;for(let n of t){let s=r+n.byteLength;if(e<s)return{buf:n,index:e-r};r=s}throw new RangeError("index is out of bounds")}function rn(t){return!!t?.[Ui]}var ae=class t{bufs;length;[Ui]=!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 r=0;for(let n of e)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(rn(n)){r+=n.byteLength;for(let s of n.bufs)this.bufs.push(s)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...e){this.prependAll(e)}prependAll(e){let r=0;for(let n of e.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(rn(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(e){let r=Oi(this.bufs,e);return r.buf[r.index]}set(e,r){let n=Oi(this.bufs,e);n.buf[n.index]=r}write(e,r=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(r+n,e[n]);else if(rn(e))for(let n=0;n<e.length;n++)this.set(r+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,r){let{bufs:n,length:s}=this._subList(e,r);return ro(n,s)}subarray(e,r){let{bufs:n,length:s}=this._subList(e,r);return n.length===1?n[0]:ro(n,s)}sublist(e,r){let{bufs:n,length:s}=this._subList(e,r),o=new t;return o.length=s,o.bufs=n,o}_subList(e,r){if(e=e??0,r=r??this.length,e<0&&(e=this.length+e),r<0&&(r=this.length+r),e<0||r>this.length)throw new RangeError("index is out of bounds");if(e===r)return{bufs:[],length:0};if(e===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],s=0;for(let o=0;o<this.bufs.length;o++){let i=this.bufs[o],a=s,c=a+i.byteLength;if(s=c,e>=c)continue;let u=e>=a&&e<c,f=r>a&&r<=c;if(u&&f){if(e===a&&r===c){n.push(i);break}let h=e-a;n.push(i.subarray(h,h+(r-e)));break}if(u){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(f){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-e}}indexOf(e,r=0){if(!rn(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(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),e.length===0)return r>this.length?this.length:r;let s=n.byteLength;if(s===0)throw new TypeError("search must be at least 1 byte long");let o=256,i=new Int32Array(o);for(let h=0;h<o;h++)i[h]=-1;for(let h=0;h<s;h++)i[n[h]]=h;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let h=r;h<=c;h+=f){f=0;for(let l=u;l>=0;l--){let d=this.get(h+l);if(n[l]!==d){f=Math.max(1,l-a[d]);break}}if(f===0)return h}return-1}getInt8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(e,r){let n=ur(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,e)}getInt16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(e,r,n){let s=qe(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,r,n),this.write(s,e)}getInt32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(e,r,n){let s=qe(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,r,n),this.write(s,e)}getBigInt64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(e,r,n){let s=qe(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,r,n),this.write(s,e)}getUint8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(e,r){let n=ur(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,e)}getUint16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(e,r,n){let s=qe(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,r,n),this.write(s,e)}getUint32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(e,r,n){let s=qe(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,r,n),this.write(s,e)}getBigUint64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(e,r,n){let s=qe(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,r,n),this.write(s,e)}getFloat32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(e,r,n){let s=qe(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,r,n),this.write(s,e)}getFloat64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(e,r,n){let s=qe(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,r,n),this.write(s,e)}equals(e){if(e==null||!(e instanceof t)||e.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!Ni(this.bufs[r],e.bufs[r]))return!1;return!0}static fromUint8Arrays(e,r){let n=new t;return n.bufs=e,r==null&&(r=e.reduce((s,o)=>s+o.byteLength,0)),n.length=r,n}};var no={};H(no,{base10:()=>Xu});var Xu=We({prefix:"9",name:"base10",alphabet:"0123456789"});var oo={};H(oo,{base16:()=>Wu,base16upper:()=>Ju});var Wu=X({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ju=X({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var so={};H(so,{base2:()=>Qu});var Qu=X({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var io={};H(io,{base256emoji:()=>of});var Fi=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}"),ef=Fi.reduce((t,e,r)=>(t[r]=e,t),[]),tf=Fi.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function rf(t){return t.reduce((e,r)=>(e+=ef[r],e),"")}function nf(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let s=tf[n];if(s==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(s)}return new Uint8Array(e)}var of=kt({prefix:"\u{1F680}",name:"base256emoji",encode:rf,decode:nf});var ao={};H(ao,{base64:()=>sf,base64pad:()=>af,base64url:()=>cf,base64urlpad:()=>uf});var sf=X({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),af=X({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),cf=X({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),uf=X({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var co={};H(co,{base8:()=>ff});var ff=X({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var uo={};H(uo,{identity:()=>lf});var lf=kt({prefix:"\0",name:"identity",encode:t=>Ei(t),decode:t=>xi(t)});var Fp=new TextEncoder,Kp=new TextDecoder;var ho={};H(ho,{sha256:()=>pt,sha512:()=>mf});var pf=20;function lo({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:s}){return new fo(t,e,r,n,s)}var fo=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,s,o){this.name=e,this.code=r,this.encode=n,this.minDigestLength=s??pf,this.maxDigestLength=o}digest(e,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?Ki(n,this.code,r?.truncate):n.then(s=>Ki(s,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Ki(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return Re(e,t)}function qi(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var pt=lo({name:"sha2-256",code:18,encode:qi("SHA-256")}),mf=lo({name:"sha2-512",code:19,encode:qi("SHA-512")});var po={...uo,...so,...co,...no,...oo,...Wn,...Jn,...Xn,...ao,...io},Wp={...ho,...to};function nn(t=0){return new Uint8Array(t)}function zi(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Vi=zi("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),mo=zi("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=nn(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),bf={utf8:Vi,"utf-8":Vi,hex:po.base16,latin1:mo,ascii:mo,binary:mo,...po},on=bf;function j(t,e="utf8"){let r=on[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function z(t,e="utf8"){let r=on[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var yf=parseInt("11111",2),bo=parseInt("10000000",2),gf=parseInt("01111111",2),Hi={0:fr,1:fr,2:wf,3:vf,4:Sf,5:Ef,6:xf,16:fr,22:fr,48:fr};function Ve(t,e={offset:0}){let r=t[e.offset]&yf;if(e.offset++,Hi[r]!=null)return Hi[r](t,e);throw new Error("No decoder for tag "+r)}function lr(t,e){let r=0;if((t[e.offset]&bo)===bo){let n=t[e.offset]&gf,s="0x";e.offset++;for(let o=0;o<n;o++,e.offset++)s+=t[e.offset].toString(16).padStart(2,"0");r=parseInt(s,16)}else r=t[e.offset],e.offset++;return r}function fr(t,e){lr(t,e);let r=[];for(;!(e.offset>=t.byteLength);){let n=Ve(t,e);if(n===null)break;r.push(n)}return r}function wf(t,e){let r=lr(t,e),n=e.offset,s=e.offset+r,o=[];for(let i=n;i<s;i++)i===n&&t[i]===0||o.push(t[i]);return e.offset+=r,Uint8Array.from(o)}function xf(t,e){let r=lr(t,e),n=e.offset+r,s=t[e.offset];e.offset++;let o=0,i=0;s<40?(o=0,i=s):s<80?(o=1,i=s-40):(o=2,i=s-80);let a=`${o}.${i}`,c=[];for(;e.offset<n;){let u=t[e.offset];if(e.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let h=0;h<c.length;h++)f+=c[h]<<h*7;a+=`.${f}`,c=[]}}return a}function Ef(t,e){return e.offset++,null}function vf(t,e){let r=lr(t,e),n=t[e.offset];e.offset++;let s=t.subarray(e.offset,e.offset+r-1);if(e.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return s}function Sf(t,e){let r=lr(t,e),n=t.subarray(e.offset,e.offset+r);return e.offset+=r,n}function Af(t){let e=t.toString(16);e.length%2===1&&(e="0"+e);let r=new ae;for(let n=0;n<e.length;n+=2)r.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return r}function yo(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=Af(t.byteLength);return new ae(Uint8Array.from([e.byteLength|bo]),e)}function ye(t){let e=new ae,r=128;return(t.subarray()[0]&r)===r&&e.append(Uint8Array.from([0])),e.append(t),new ae(Uint8Array.from([2]),yo(e),e)}function sn(t){let e=Uint8Array.from([0]),r=new ae(e,t);return new ae(Uint8Array.from([3]),yo(r),r)}function et(t,e=48){let r=new ae;for(let n of t)r.append(n);return new ae(Uint8Array.from([e]),yo(r),r)}var If=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Bf=Uint8Array.from([6,5,43,129,4,0,34]),Tf=Uint8Array.from([6,5,43,129,4,0,35]),Lf={ext:!0,kty:"EC",crv:"P-256"},Df={ext:!0,kty:"EC",crv:"P-384"},_f={ext:!0,kty:"EC",crv:"P-521"},go=32,wo=48,xo=66;function Eo(t){let e=Ve(t);return $i(e)}function $i(t){let e=t[1][1][0],r=1,n,s;if(e.byteLength===go*2+1)return n=z(e.subarray(r,r+go),"base64url"),s=z(e.subarray(r+go),"base64url"),new Ot({...Lf,key_ops:["verify"],x:n,y:s});if(e.byteLength===wo*2+1)return n=z(e.subarray(r,r+wo),"base64url"),s=z(e.subarray(r+wo),"base64url"),new Ot({...Df,key_ops:["verify"],x:n,y:s});if(e.byteLength===xo*2+1)return n=z(e.subarray(r,r+xo),"base64url"),s=z(e.subarray(r+xo),"base64url"),new Ot({..._f,key_ops:["verify"],x:n,y:s});throw new $(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function ji(t){return et([ye(Uint8Array.from([1])),et([kf(t.crv)],160),et([sn(new ae(Uint8Array.from([4]),j(t.x??"","base64url"),j(t.y??"","base64url")))],161)]).subarray()}function kf(t){if(t==="P-256")return If;if(t==="P-384")return Bf;if(t==="P-521")return Tf;throw new $(`Invalid curve ${t}`)}var Ot=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=ji(this.jwk)),this._raw}toMultihash(){return Be.digest(ze(this))}toCID(){return le.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ae(this.raw,e.raw)}async verify(e,r,n){return Pi(this.jwk,r,e,n)}};function vo(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}function tt(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(`${r}expected number, got ${typeof t}`)}if(!Number.isSafeInteger(t)||t<0){let r=e&&`"${e}" `;throw new RangeError(`${r}expected integer >= 0, got ${t}`)}}function ve(t,e,r=""){let n=vo(t),s=t?.length,o=e!==void 0;if(!n||o&&s!==e){let i=r&&`"${r}" `,a=o?` of length ${e}`:"",c=n?`length=${s}`:`type=${typeof t}`,u=i+"expected Uint8Array"+a+", got "+c;throw n?new RangeError(u):new TypeError(u)}return t}function an(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(tt(t.outputLen),tt(t.blockLen),t.outputLen<1)throw new Error('"outputLen" must be >= 1');if(t.blockLen<1)throw new Error('"blockLen" must be >= 1')}function Ut(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function cn(t,e){ve(t,void 0,"digestInto() output");let r=e.outputLen;if(t.length<r)throw new RangeError('"digestInto() output" expected to be of length >='+r)}function $e(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function un(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Te(t,e){return t<<32-e|t>>>e}var Yi=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Cf=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function fn(t){if(ve(t),Yi)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=Cf[t[r]];return e}var He={_0:48,_9:57,A:65,F:70,a:97,f:102};function Zi(t){if(t>=He._0&&t<=He._9)return t-He._0;if(t>=He.A&&t<=He.F)return t-(He.A-10);if(t>=He.a&&t<=He.f)return t-(He.a-10)}function hr(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(Yi)try{return Uint8Array.fromHex(t)}catch(s){throw s instanceof SyntaxError?new RangeError(s.message):s}let e=t.length,r=e/2;if(e%2)throw new RangeError("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let s=0,o=0;s<r;s++,o+=2){let i=Zi(t.charCodeAt(o)),a=Zi(t.charCodeAt(o+1));if(i===void 0||a===void 0){let c=t[o]+t[o+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+o)}n[s]=i*16+a}return n}function So(...t){let e=0;for(let n=0;n<t.length;n++){let s=t[n];ve(s),e+=s.length}let r=new Uint8Array(e);for(let n=0,s=0;n<t.length;n++){let o=t[n];r.set(o,s),s+=o.length}return r}function Ao(t,e={}){let r=(s,o)=>t(o).update(s).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=s=>t(s),Object.assign(r,e),Object.freeze(r)}function ln(t=32){tt(t,"bytesLength");let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(t>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${t}`);return e.getRandomValues(new Uint8Array(t))}var Io=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function Gi(t,e,r){return t&e^~t&r}function Xi(t,e,r){return t&e^t&r^e&r}var dr=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,r,n,s){this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=s,this.buffer=new Uint8Array(e),this.view=un(this.buffer)}update(e){Ut(this),ve(e);let{view:r,buffer:n,blockLen:s}=this,o=e.length;for(let i=0;i<o;){let a=Math.min(s-this.pos,o-i);if(a===s){let c=un(e);for(;s<=o-i;i+=s)this.process(c,i);continue}n.set(e.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===s&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Ut(this),cn(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:s,isLE:o}=this,{pos:i}=this;r[i++]=128,$e(this.buffer.subarray(i)),this.padOffset>s-i&&(this.process(n,0),i=0);for(let h=i;h<s;h++)r[h]=0;n.setBigUint64(s-8,BigInt(this.length*8),o),this.process(n,0);let a=un(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=c/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<u;h++)a.setUint32(4*h,f[h],o)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());let{blockLen:r,buffer:n,length:s,finished:o,destroyed:i,pos:a}=this;return e.destroyed=i,e.finished=o,e.length=s,e.pos=a,s%r&&e.buffer.set(n),e}clone(){return this._cloneInto()}},je=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ue=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var hn=BigInt(4294967295),Wi=BigInt(32);function Rf(t,e=!1){return e?{h:Number(t&hn),l:Number(t>>Wi&hn)}:{h:Number(t>>Wi&hn)|0,l:Number(t&hn)|0}}function Ji(t,e=!1){let r=t.length,n=new Uint32Array(r),s=new Uint32Array(r);for(let o=0;o<r;o++){let{h:i,l:a}=Rf(t[o],e);[n[o],s[o]]=[i,a]}return[n,s]}var Bo=(t,e,r)=>t>>>r,To=(t,e,r)=>t<<32-r|e>>>r,mt=(t,e,r)=>t>>>r|e<<32-r,bt=(t,e,r)=>t<<32-r|e>>>r,pr=(t,e,r)=>t<<64-r|e>>>r-32,mr=(t,e,r)=>t>>>r-32|e<<64-r;function Ne(t,e,r,n){let s=(e>>>0)+(n>>>0);return{h:t+r+(s/2**32|0)|0,l:s|0}}var Qi=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),ea=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,ta=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),ra=(t,e,r,n,s)=>e+r+n+s+(t/2**32|0)|0,na=(t,e,r,n,s)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(s>>>0),oa=(t,e,r,n,s,o)=>e+r+n+s+o+(t/2**32|0)|0;var Nf=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),rt=new Uint32Array(64),Lo=class extends dr{constructor(e){super(64,e,8,!1)}get(){let{A:e,B:r,C:n,D:s,E:o,F:i,G:a,H:c}=this;return[e,r,n,s,o,i,a,c]}set(e,r,n,s,o,i,a,c){this.A=e|0,this.B=r|0,this.C=n|0,this.D=s|0,this.E=o|0,this.F=i|0,this.G=a|0,this.H=c|0}process(e,r){for(let h=0;h<16;h++,r+=4)rt[h]=e.getUint32(r,!1);for(let h=16;h<64;h++){let l=rt[h-15],d=rt[h-2],p=Te(l,7)^Te(l,18)^l>>>3,g=Te(d,17)^Te(d,19)^d>>>10;rt[h]=g+rt[h-7]+p+rt[h-16]|0}let{A:n,B:s,C:o,D:i,E:a,F:c,G:u,H:f}=this;for(let h=0;h<64;h++){let l=Te(a,6)^Te(a,11)^Te(a,25),d=f+l+Gi(a,c,u)+Nf[h]+rt[h]|0,g=(Te(n,2)^Te(n,13)^Te(n,22))+Xi(n,s,o)|0;f=u,u=c,c=a,a=i+d|0,i=o,o=s,s=n,n=d+g|0}n=n+this.A|0,s=s+this.B|0,o=o+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,s,o,i,a,c,u,f)}roundClean(){$e(rt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),$e(this.buffer)}},Do=class extends Lo{A=je[0]|0;B=je[1]|0;C=je[2]|0;D=je[3]|0;E=je[4]|0;F=je[5]|0;G=je[6]|0;H=je[7]|0;constructor(){super(32)}};var sa=Ji(["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(t=>BigInt(t))),Of=sa[0],Uf=sa[1],nt=new Uint32Array(80),ot=new Uint32Array(80),_o=class extends dr{constructor(e){super(128,e,16,!1)}get(){let{Ah:e,Al:r,Bh:n,Bl:s,Ch:o,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:h,Fl:l,Gh:d,Gl:p,Hh:g,Hl:b}=this;return[e,r,n,s,o,i,a,c,u,f,h,l,d,p,g,b]}set(e,r,n,s,o,i,a,c,u,f,h,l,d,p,g,b){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=s|0,this.Ch=o|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=h|0,this.Fl=l|0,this.Gh=d|0,this.Gl=p|0,this.Hh=g|0,this.Hl=b|0}process(e,r){for(let S=0;S<16;S++,r+=4)nt[S]=e.getUint32(r),ot[S]=e.getUint32(r+=4);for(let S=16;S<80;S++){let L=nt[S-15]|0,T=ot[S-15]|0,R=mt(L,T,1)^mt(L,T,8)^Bo(L,T,7),k=bt(L,T,1)^bt(L,T,8)^To(L,T,7),B=nt[S-2]|0,N=ot[S-2]|0,V=mt(B,N,19)^pr(B,N,61)^Bo(B,N,6),O=bt(B,N,19)^mr(B,N,61)^To(B,N,6),m=ta(k,O,ot[S-7],ot[S-16]),w=ra(m,R,V,nt[S-7],nt[S-16]);nt[S]=w|0,ot[S]=m|0}let{Ah:n,Al:s,Bh:o,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:h,El:l,Fh:d,Fl:p,Gh:g,Gl:b,Hh:y,Hl:v}=this;for(let S=0;S<80;S++){let L=mt(h,l,14)^mt(h,l,18)^pr(h,l,41),T=bt(h,l,14)^bt(h,l,18)^mr(h,l,41),R=h&d^~h&g,k=l&p^~l&b,B=na(v,T,k,Uf[S],ot[S]),N=oa(B,y,L,R,Of[S],nt[S]),V=B|0,O=mt(n,s,28)^pr(n,s,34)^pr(n,s,39),m=bt(n,s,28)^mr(n,s,34)^mr(n,s,39),w=n&o^n&a^o&a,A=s&i^s&c^i&c;y=g|0,v=b|0,g=d|0,b=p|0,d=h|0,p=l|0,{h,l}=Ne(u|0,f|0,N|0,V|0),u=a|0,f=c|0,a=o|0,c=i|0,o=n|0,i=s|0;let E=Qi(V,m,A);n=ea(E,N,O,w),s=E|0}({h:n,l:s}=Ne(this.Ah|0,this.Al|0,n|0,s|0)),{h:o,l:i}=Ne(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=Ne(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=Ne(this.Dh|0,this.Dl|0,u|0,f|0),{h,l}=Ne(this.Eh|0,this.El|0,h|0,l|0),{h:d,l:p}=Ne(this.Fh|0,this.Fl|0,d|0,p|0),{h:g,l:b}=Ne(this.Gh|0,this.Gl|0,g|0,b|0),{h:y,l:v}=Ne(this.Hh|0,this.Hl|0,y|0,v|0),this.set(n,s,o,i,a,c,u,f,h,l,d,p,g,b,y,v)}roundClean(){$e(nt,ot)}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)}},ko=class extends _o{Ah=ue[0]|0;Al=ue[1]|0;Bh=ue[2]|0;Bl=ue[3]|0;Ch=ue[4]|0;Cl=ue[5]|0;Dh=ue[6]|0;Dl=ue[7]|0;Eh=ue[8]|0;El=ue[9]|0;Fh=ue[10]|0;Fl=ue[11]|0;Gh=ue[12]|0;Gl=ue[13]|0;Hh=ue[14]|0;Hl=ue[15]|0;constructor(){super(64)}};var Ft=Ao(()=>new Do,Io(1));var dn=Ao(()=>new ko,Io(3));var K=(t,e,r)=>ve(t,e,r),Ro=tt,Kt=fn,oe=(...t)=>So(...t),Mt=t=>hr(t),yt=vo,br=t=>ln(t),mn=BigInt(0),Co=BigInt(1);function Le(t,e=""){if(typeof t!="boolean"){let r=e&&`"${e}" `;throw new TypeError(r+"expected boolean, got type="+typeof t)}return t}function bn(t){if(typeof t=="bigint"){if(!pn(t))throw new RangeError("positive bigint expected, got "+t)}else Ro(t);return t}function De(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(r+"expected number, got type="+typeof t)}if(!Number.isSafeInteger(t)){let r=e&&`"${e}" `;throw new RangeError(r+"expected safe integer, got "+t)}}function yr(t){let e=bn(t).toString(16);return e.length&1?"0"+e:e}function ia(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?mn:BigInt("0x"+t)}function gt(t){return ia(fn(t))}function Oe(t){return ia(fn(gr(ve(t)).reverse()))}function yn(t,e){if(tt(e),e===0)throw new RangeError("zero length");t=bn(t);let r=t.toString(16);if(r.length>e*2)throw new RangeError("number too large");return hr(r.padStart(e*2,"0"))}function Po(t,e){return yn(t,e).reverse()}function aa(t,e){if(t=K(t),e=K(e),t.length!==e.length)return!1;let r=0;for(let n=0;n<t.length;n++)r|=t[n]^e[n];return r===0}function gr(t){return Uint8Array.from(K(t))}function gn(t){if(typeof t!="string")throw new TypeError("ascii string expected, got "+typeof t);return Uint8Array.from(t,(e,r)=>{let n=e.charCodeAt(0);if(e.length!==1||n>127)throw new RangeError(`string contains non-ASCII character "${t[r]}" with code ${n} at position ${r}`);return n})}var pn=t=>typeof t=="bigint"&&mn<=t;function Ff(t,e,r){return pn(t)&&pn(e)&&pn(r)&&e<=t&&t<r}function qt(t,e,r,n){if(!Ff(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function Vt(t){if(t<mn)throw new Error("expected non-negative bigint, got "+t);let e;for(e=0;t>mn;t>>=Co,e+=1);return e}var wr=t=>(Co<<BigInt(t))-Co;function ca(t,e,r){if(tt(t,"hashLen"),tt(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=b=>new Uint8Array(b),s=Uint8Array.of(),o=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(t),u=n(t),f=0,h=()=>{c.fill(1),u.fill(0),f=0},l=(...b)=>r(u,oe(c,...b)),d=(b=s)=>{u=l(o,b),c=l(),b.length!==0&&(u=l(i,b),c=l())},p=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let b=0,y=[];for(;b<e;){c=l();let v=c.slice();y.push(v),b+=c.length}return oe(...y)};return(b,y)=>{h(),d(b);let v;for(;(v=y(p()))===void 0;)d();return h(),v}}function _e(t,e={},r={}){if(Object.prototype.toString.call(t)!=="[object Object]")throw new TypeError("expected valid options object");function n(o,i,a){if(!a&&i!=="function"&&!Object.hasOwn(t,o))throw new TypeError(`param "${o}" is invalid: expected own property`);let c=t[o];if(a&&c===void 0)return;let u=typeof c;if(u!==i||c===null)throw new TypeError(`param "${o}" is invalid: expected ${i}, got ${u}`)}let s=(o,i)=>Object.entries(o).forEach(([a,c])=>n(a,c,i));s(e,!1),s(r,!0)}var No=()=>{throw new Error("not implemented")};var fe=BigInt(0),W=BigInt(1),wt=BigInt(2),ha=BigInt(3),da=BigInt(4),pa=BigInt(5),Kf=BigInt(7),ma=BigInt(8),Mf=BigInt(9),ba=BigInt(16);function te(t,e){if(e<=fe)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=fe?r:e+r}function Z(t,e,r){if(e<fe)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >fe;)n*=n,n%=r;return n}function ua(t,e){if(t===fe)throw new Error("invert: expected non-zero number");if(e<=fe)throw new Error("invert: expected positive modulus, got "+e);let r=te(t,e),n=e,s=fe,o=W,i=W,a=fe;for(;r!==fe;){let u=n/r,f=n-r*u,h=s-i*u,l=o-a*u;n=r,r=f,s=i,o=a,i=h,a=l}if(n!==W)throw new Error("invert: does not exist");return te(s,e)}function Oo(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function ya(t,e){let r=t,n=(r.ORDER+W)/da,s=r.pow(e,n);return Oo(r,s,e),s}function qf(t,e){let r=t,n=(r.ORDER-pa)/ma,s=r.mul(e,wt),o=r.pow(s,n),i=r.mul(e,o),a=r.mul(r.mul(i,wt),o),c=r.mul(i,r.sub(a,r.ONE));return Oo(r,c,e),c}function Vf(t){let e=zt(t),r=ga(t),n=r(e,e.neg(e.ONE)),s=r(e,n),o=r(e,e.neg(n)),i=(t+Kf)/ba;return((a,c)=>{let u=a,f=u.pow(c,i),h=u.mul(f,n),l=u.mul(f,s),d=u.mul(f,o),p=u.eql(u.sqr(h),c),g=u.eql(u.sqr(l),c);f=u.cmov(f,h,p),h=u.cmov(d,l,g);let b=u.eql(u.sqr(h),c),y=u.cmov(f,h,b);return Oo(u,y,c),y})}function ga(t){if(t<ha)throw new Error("sqrt is not defined for small field");let e=t-W,r=0;for(;e%wt===fe;)e/=wt,r++;let n=wt,s=zt(t);for(;fa(s,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return ya;let o=s.pow(n,e),i=(e+W)/wt;return function(c,u){let f=c;if(f.is0(u))return u;if(fa(f,u)!==1)throw new Error("Cannot find square root");let h=r,l=f.mul(f.ONE,o),d=f.pow(u,e),p=f.pow(u,i);for(;!f.eql(d,f.ONE);){if(f.is0(d))return f.ZERO;let g=1,b=f.sqr(d);for(;!f.eql(b,f.ONE);)if(g++,b=f.sqr(b),g===h)throw new Error("Cannot find square root");let y=W<<BigInt(h-g-1),v=f.pow(l,y);h=g,l=f.sqr(v),d=f.mul(d,l),p=f.mul(p,v)}return p}}function zf(t){return t%da===ha?ya:t%ma===pa?qf:t%ba===Mf?Vf(t):ga(t)}var Ze=(t,e)=>(te(t,e)&W)===W,Hf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Uo(t){let e={ORDER:"bigint",BYTES:"number",BITS:"number"},r=Hf.reduce((n,s)=>(n[s]="function",n),e);if(_e(t,r),De(t.BYTES,"BYTES"),De(t.BITS,"BITS"),t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=W)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function $f(t,e,r){let n=t;if(r<fe)throw new Error("invalid exponent, negatives unsupported");if(r===fe)return n.ONE;if(r===W)return e;let s=n.ONE,o=e;for(;r>fe;)r&W&&(s=n.mul(s,o)),o=n.sqr(o),r>>=W;return s}function xr(t,e,r=!1){let n=t,s=new Array(e.length).fill(r?n.ZERO:void 0),o=e.reduce((a,c,u)=>n.is0(c)?a:(s[u]=a,n.mul(a,c)),n.ONE),i=n.inv(o);return e.reduceRight((a,c,u)=>n.is0(c)?a:(s[u]=n.mul(a,s[u]),n.mul(a,c)),i),s}function fa(t,e){let r=t,n=(r.ORDER-W)/wt,s=r.pow(e,n),o=r.eql(s,r.ONE),i=r.eql(s,r.ZERO),a=r.eql(s,r.neg(r.ONE));if(!o&&!i&&!a)throw new Error("invalid Legendre symbol result");return o?1:i?0:-1}function jf(t,e){if(e!==void 0&&Ro(e),t<=fe)throw new Error("invalid n length: expected positive n, got "+t);if(e!==void 0&&e<1)throw new Error("invalid n length: expected positive bit length, got "+e);let r=Vt(t);if(e!==void 0&&e<r)throw new Error(`invalid n length: expected bit length (${r}) >= n.length (${e})`);let n=e!==void 0?e:r,s=Math.ceil(n/8);return{nBitLength:n,nByteLength:s}}var la=new WeakMap,wn=class{ORDER;BITS;BYTES;isLE;ZERO=fe;ONE=W;_lengths;_mod;constructor(e,r={}){if(e<=W)throw new Error("invalid field: expected ORDER > 1, got "+e);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:s,nByteLength:o}=jf(e,n);if(o>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=s,this.BYTES=o,Object.freeze(this)}create(e){return te(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return fe<=e&&e<this.ORDER}is0(e){return e===fe}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&W)===W}neg(e){return te(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return te(e*e,this.ORDER)}add(e,r){return te(e+r,this.ORDER)}sub(e,r){return te(e-r,this.ORDER)}mul(e,r){return te(e*r,this.ORDER)}pow(e,r){return $f(this,e,r)}div(e,r){return te(e*ua(r,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,r){return e+r}subN(e,r){return e-r}mulN(e,r){return e*r}inv(e){return ua(e,this.ORDER)}sqrt(e){let r=la.get(this);return r||la.set(this,r=zf(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?Po(e,this.BYTES):yn(e,this.BYTES)}fromBytes(e,r=!1){K(e);let{_lengths:n,BYTES:s,isLE:o,ORDER:i,_mod:a}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>s)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let u=new Uint8Array(s);u.set(e,o?0:u.length-e.length),e=u}if(e.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+e.length);let c=o?Oe(e):gt(e);if(a&&(c=te(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return xr(this,e)}cmov(e,r,n){return Le(n,"condition"),n?r:e}};Object.freeze(wn.prototype);function zt(t,e={}){return new wn(t,e)}function wa(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=W)throw new Error("field order must be greater than 1");let e=Vt(t-W);return Math.ceil(e/8)}function Fo(t){let e=wa(t);return e+Math.ceil(e/2)}function Ko(t,e,r=!1){K(t);let n=t.length,s=wa(e),o=Math.max(Fo(e),16);if(n<o||n>1024)throw new Error("expected "+o+"-1024 bytes of input, got "+n);let i=r?Oe(t):gt(t),a=te(i,e-W)+W;return r?Po(a,s):yn(a,s)}var Ht=BigInt(0),xt=BigInt(1);function Er(t,e){let r=e.negate();return t?r:e}function Et(t,e){let r=xr(t.Fp,e.map(n=>n.Z));return e.map((n,s)=>t.fromAffine(n.toAffine(r[s])))}function Sa(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function Mo(t,e){Sa(t,e);let r=Math.ceil(e/t)+1,n=2**(t-1),s=2**t,o=wr(t),i=BigInt(t);return{windows:r,windowSize:n,mask:o,maxNumber:s,shiftBy:i}}function xa(t,e,r){let{windowSize:n,mask:s,maxNumber:o,shiftBy:i}=r,a=Number(t&s),c=t>>i;a>n&&(a-=o,c+=xt);let u=e*n,f=u+Math.abs(a)-1,h=a===0,l=a<0,d=e%2!==0;return{nextN:c,offset:f,isZero:h,isNeg:l,isNegF:d,offsetF:u}}var qo=new WeakMap,Aa=new WeakMap;function Vo(t){return Aa.get(t)||1}function Ea(t){if(t!==Ht)throw new Error("invalid wNAF")}var $t=class{BASE;ZERO;Fn;bits;constructor(e,r){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=r}_unsafeLadder(e,r,n=this.ZERO){let s=e;for(;r>Ht;)r&xt&&(n=n.add(s)),s=s.double(),r>>=xt;return n}precomputeWindow(e,r){let{windows:n,windowSize:s}=Mo(r,this.bits),o=[],i=e,a=i;for(let c=0;c<n;c++){a=i,o.push(a);for(let u=1;u<s;u++)a=a.add(i),o.push(a);i=a.double()}return o}wNAF(e,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let s=this.ZERO,o=this.BASE,i=Mo(e,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:u,isZero:f,isNeg:h,isNegF:l,offsetF:d}=xa(n,a,i);n=c,f?o=o.add(Er(l,r[d])):s=s.add(Er(h,r[u]))}return Ea(n),{p:s,f:o}}wNAFUnsafe(e,r,n,s=this.ZERO){let o=Mo(e,this.bits);for(let i=0;i<o.windows&&n!==Ht;i++){let{nextN:a,offset:c,isZero:u,isNeg:f}=xa(n,i,o);if(n=a,!u){let h=r[c];s=s.add(f?h.negate():h)}}return Ea(n),s}getPrecomputes(e,r,n){let s=qo.get(r);return s||(s=this.precomputeWindow(r,e),e!==1&&(typeof n=="function"&&(s=n(s)),qo.set(r,s))),s}cached(e,r,n){let s=Vo(e);return this.wNAF(s,this.getPrecomputes(s,e,n),r)}unsafe(e,r,n,s){let o=Vo(e);return o===1?this._unsafeLadder(e,r,s):this.wNAFUnsafe(o,this.getPrecomputes(o,e,n),r,s)}createCache(e,r){Sa(r,this.bits),Aa.set(e,r),qo.delete(e)}hasCache(e){return Vo(e)!==1}};function Ia(t,e,r,n){let s=e,o=t.ZERO,i=t.ZERO;for(;r>Ht||n>Ht;)r&xt&&(o=o.add(s)),n&xt&&(i=i.add(s)),s=s.double(),r>>=xt,n>>=xt;return{p1:o,p2:i}}function va(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Uo(e),e}else return zt(t,{isLE:r})}function xn(t,e,r={},n){if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);for(let c of["p","n","h"]){let u=e[c];if(!(typeof u=="bigint"&&u>Ht))throw new Error(`CURVE.${c} must be positive bigint`)}let s=va(e.p,r.Fp,n),o=va(e.n,r.Fn,n),a=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let c of a)if(!s.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:s,Fn:o}}function En(t,e){return function(n){let s=t(n);return{secretKey:s,publicKey:e(s)}}}var st=BigInt(0),ce=BigInt(1),zo=BigInt(2),Zf=BigInt(8);function Yf(t,e,r,n){let s=t.sqr(r),o=t.sqr(n),i=t.add(t.mul(e.a,s),o),a=t.add(t.ONE,t.mul(e.d,t.mul(s,o)));return t.eql(i,a)}function Ba(t,e={}){let r=e,n=xn("edwards",t,r,r.FpFnLE),{Fp:s,Fn:o}=n,i=n.CURVE,{h:a}=i;_e(r,{},{uvRatio:"function"});let c=zo<<BigInt(o.BYTES*8)-ce,u=g=>s.create(g),f=r.uvRatio===void 0?(g,b)=>{try{return{isValid:!0,value:s.sqrt(s.div(g,b))}}catch{return{isValid:!1,value:st}}}:r.uvRatio;if(!Yf(s,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function h(g,b,y=!1){let v=y?ce:st;return qt("coordinate "+g,b,v,c),b}function l(g){if(!(g instanceof d))throw new Error("EdwardsPoint expected")}class d{static BASE=new d(i.Gx,i.Gy,ce,u(i.Gx*i.Gy));static ZERO=new d(st,ce,ce,st);static Fp=s;static Fn=o;X;Y;Z;T;constructor(b,y,v,S){this.X=h("x",b),this.Y=h("y",y),this.Z=h("z",v,!0),this.T=h("t",S),Object.freeze(this)}static CURVE(){return i}static fromAffine(b){if(b instanceof d)throw new Error("extended point not allowed");let{x:y,y:v}=b||{};return h("x",y),h("y",v),new d(y,v,ce,u(y*v))}static fromBytes(b,y=!1){let v=s.BYTES,{a:S,d:L}=i;b=gr(K(b,v,"point")),Le(y,"zip215");let T=gr(b),R=b[v-1];T[v-1]=R&-129;let k=Oe(T),B=y?c:s.ORDER;qt("point.y",k,st,B);let N=u(k*k),V=u(N-ce),O=u(L*N-S),{isValid:m,value:w}=f(V,O);if(!m)throw new Error("bad point: invalid y coordinate");let A=(w&ce)===ce,E=(R&128)!==0;if(!y&&w===st&&E)throw new Error("bad point: x=0 and x_0=1");return E!==A&&(w=u(-w)),d.fromAffine({x:w,y:k})}static fromHex(b,y=!1){return d.fromBytes(Mt(b),y)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=8,y=!0){return p.createCache(this,b),y||this.multiply(zo),this}assertValidity(){let b=this,{a:y,d:v}=i;if(b.is0())throw new Error("bad point: ZERO");let{X:S,Y:L,Z:T,T:R}=b,k=u(S*S),B=u(L*L),N=u(T*T),V=u(N*N),O=u(k*y),m=u(N*u(O+B)),w=u(V+u(v*u(k*B)));if(m!==w)throw new Error("bad point: equation left != right (1)");let A=u(S*L),E=u(T*R);if(A!==E)throw new Error("bad point: equation left != right (2)")}equals(b){l(b);let{X:y,Y:v,Z:S}=this,{X:L,Y:T,Z:R}=b,k=u(y*R),B=u(L*S),N=u(v*R),V=u(T*S);return k===B&&N===V}is0(){return this.equals(d.ZERO)}negate(){return new d(u(-this.X),this.Y,this.Z,u(-this.T))}double(){let{a:b}=i,{X:y,Y:v,Z:S}=this,L=u(y*y),T=u(v*v),R=u(zo*u(S*S)),k=u(b*L),B=y+v,N=u(u(B*B)-L-T),V=k+T,O=V-R,m=k-T,w=u(N*O),A=u(V*m),E=u(N*m),x=u(O*V);return new d(w,A,x,E)}add(b){l(b);let{a:y,d:v}=i,{X:S,Y:L,Z:T,T:R}=this,{X:k,Y:B,Z:N,T:V}=b,O=u(S*k),m=u(L*B),w=u(R*v*V),A=u(T*N),E=u((S+L)*(k+B)-O-m),x=A-w,I=A+w,_=u(m-y*O),D=u(E*x),C=u(I*_),P=u(E*_),F=u(x*I);return new d(D,C,F,P)}subtract(b){return l(b),this.add(b.negate())}multiply(b){if(!o.isValidNot0(b))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:y,f:v}=p.cached(this,b,S=>Et(d,S));return Et(d,[y,v])[0]}multiplyUnsafe(b){if(!o.isValid(b))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return b===st?d.ZERO:this.is0()||b===ce?this:p.unsafe(this,b,y=>Et(d,y))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return p.unsafe(this,i.n).is0()}toAffine(b){let y=this,v=b,{X:S,Y:L,Z:T}=y,R=y.is0();v==null&&(v=R?Zf:s.inv(T));let k=u(S*v),B=u(L*v),N=s.mul(T,v);if(R)return{x:st,y:ce};if(N!==ce)throw new Error("invZ was invalid");return{x:k,y:B}}clearCofactor(){return a===ce?this:this.multiplyUnsafe(a)}toBytes(){let{x:b,y}=this.toAffine(),v=s.toBytes(y);return v[v.length-1]|=b&ce?128:0,v}toHex(){return Kt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let p=new $t(d,o.BITS);return o.BITS>=8&&d.BASE.precompute(8),Object.freeze(d.prototype),Object.freeze(d),d}var vn=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(e){this.ep=e}static fromBytes(e){No()}static fromHex(e){No()}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 Kt(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,r){return this.ep.precompute(e,r),this}};function Ta(t,e,r={}){if(typeof e!="function")throw new Error('"hash" function param is required');let n=e,s=r;_e(s,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function"});let{prehash:o}=s,{BASE:i,Fp:a,Fn:c}=t,u=n.outputLen,f=2*a.BYTES;if(u!==void 0&&(De(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let h=s.randomBytes===void 0?br:s.randomBytes,l=s.adjustScalarBytes===void 0?m=>m:s.adjustScalarBytes,d=s.domain===void 0?(m,w,A)=>{if(Le(A,"phflag"),w.length||A)throw new Error("Contexts/pre-hash are not supported");return m}:s.domain;function p(m){return c.create(Oe(m))}function g(m){let w=k.secretKey;K(m,k.secretKey,"secretKey");let A=K(n(m),2*w,"hashedSecretKey"),E=l(A.slice(0,w)),x=A.slice(w,2*w),I=p(E);return{head:E,prefix:x,scalar:I}}function b(m){let{head:w,prefix:A,scalar:E}=g(m),x=i.multiply(E),I=x.toBytes();return{head:w,prefix:A,scalar:E,point:x,pointBytes:I}}function y(m){return b(m).pointBytes}function v(m=Uint8Array.of(),...w){let A=oe(...w);return p(n(d(A,K(m,void 0,"context"),!!o)))}function S(m,w,A={}){m=K(m,void 0,"message"),o&&(m=o(m));let{prefix:E,scalar:x,pointBytes:I}=b(w),_=v(A.context,E,m),D=i.multiply(_).toBytes(),C=v(A.context,D,I,m),P=c.create(_+C*x);if(!c.isValid(P))throw new Error("sign failed: invalid s");let F=oe(D,c.toBytes(P));return K(F,k.signature,"result")}let L={zip215:s.zip215};function T(m,w,A,E=L){let{context:x}=E,I=E.zip215===void 0?!!L.zip215:E.zip215,_=k.signature;m=K(m,_,"signature"),w=K(w,void 0,"message"),A=K(A,k.publicKey,"publicKey"),I!==void 0&&Le(I,"zip215"),o&&(w=o(w));let D=_/2,C=m.subarray(0,D),P=Oe(m.subarray(D,_)),F,M,U;try{F=t.fromBytes(A,I),M=t.fromBytes(C,I),U=i.multiplyUnsafe(P)}catch{return!1}if(!I&&F.isSmallOrder())return!1;let ne=v(x,C,A,w);return M.add(F.multiplyUnsafe(ne)).subtract(U).clearCofactor().is0()}let R=a.BYTES,k={secretKey:R,publicKey:R,signature:2*R,seed:R};function B(m){return m=m===void 0?h(k.seed):m,K(m,k.seed,"seed")}function N(m){return yt(m)&&m.length===k.secretKey}function V(m,w){try{return!!t.fromBytes(m,w===void 0?L.zip215:w)}catch{return!1}}let O={getExtendedPublicKey:b,randomSecretKey:B,isValidSecretKey:N,isValidPublicKey:V,toMontgomery(m){let{y:w}=t.fromBytes(m),A=k.publicKey,E=A===32;if(!E&&A!==57)throw new Error("only defined for 25519 and 448");let x=E?a.div(ce+w,ce-w):a.div(w-ce,w+ce);return a.toBytes(x)},toMontgomerySecret(m){let w=k.secretKey;K(m,w);let A=n(m.subarray(0,w));return l(A).subarray(0,w)}};return Object.freeze(k),Object.freeze(O),Object.freeze({keygen:En(B,y),getPublicKey:y,sign:S,verify:T,utils:O,Point:t,lengths:k})}function vr(t,e){if(De(t),De(e),e<0||e>4)throw new Error("invalid I2OSP length: "+e);if(t<0||t>2**(8*e)-1)throw new Error("invalid I2OSP input: "+t);let r=Array.from({length:e}).fill(0);for(let n=e-1;n>=0;n--)r[n]=t&255,t>>>=8;return new Uint8Array(r)}function Gf(t,e){let r=new Uint8Array(t.length);for(let n=0;n<t.length;n++)r[n]=t[n]^e[n];return r}function Xf(t){if(!yt(t)&&typeof t!="string")throw new Error("DST must be Uint8Array or ascii string");let e=typeof t=="string"?gn(t):t;if(e.length===0)throw new Error("DST must be non-empty");return e}function Ho(t,e,r,n){K(t),De(r),e=Xf(e),e.length>255&&(e=n(oe(gn("H2C-OVERSIZE-DST-"),e)));let{outputLen:s,blockLen:o}=n,i=Math.ceil(r/s);if(r>65535||i>255)throw new Error("expand_message_xmd: invalid lenInBytes");let a=oe(e,vr(e.length,1)),c=new Uint8Array(o),u=vr(r,2),f=new Array(i),h=n(oe(c,t,u,vr(0,1),a));f[0]=n(oe(h,vr(1,1),a));for(let d=1;d<i;d++){let p=[Gf(h,f[d-1]),vr(d+1,1),a];f[d]=n(oe(...p))}return oe(...f).slice(0,r)}var La="HashToScalar-";var Wf=BigInt(0),Ye=BigInt(1),Da=BigInt(2);var Jf=BigInt(5),Qf=BigInt(8),jt=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Yo={p:jt,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Qf,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function el(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),s=BigInt(80),o=jt,a=t*t%o*t%o,c=Z(a,Da,o)*a%o,u=Z(c,Ye,o)*t%o,f=Z(u,Jf,o)*u%o,h=Z(f,e,o)*f%o,l=Z(h,r,o)*h%o,d=Z(l,n,o)*l%o,p=Z(d,s,o)*d%o,g=Z(p,s,o)*d%o,b=Z(g,e,o)*f%o;return{pow_p_5_8:Z(b,Da,o)*t%o,b2:a}}function tl(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var $o=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Go(t,e){let r=jt,n=te(e*e*e,r),s=te(n*n*e,r),o=el(t*s).pow_p_5_8,i=te(t*n*o,r),a=te(e*i*i,r),c=i,u=te(i*$o,r),f=a===t,h=a===te(-t,r),l=a===te(-t*$o,r);return f&&(i=c),(h||l)&&(i=u),Ze(i,r)&&(i=te(-i,r)),{isValid:f||h,value:i}}var at=Ba(Yo,{uvRatio:Go}),it=at.Fp,Ca=at.Fn;function rl(t){return Ta(at,dn,Object.assign({adjustScalarBytes:tl,zip215:!0},t))}var Ra=rl({});var jo=$o,nl=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),ol=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),sl=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),il=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),_a=t=>Go(Ye,t),al=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Zo=t=>it.create(Oe(t)&al);function ka(t){let{d:e}=Yo,r=jt,n=y=>it.create(y),s=n(jo*t*t),o=n((s+Ye)*sl),i=BigInt(-1),a=n((i-e*s)*n(s+e)),{isValid:c,value:u}=Go(o,a),f=n(u*t);Ze(f,r)||(f=n(-f)),c||(u=f),c||(i=s);let h=n(i*(s-Ye)*il-a),l=u*u,d=n((u+u)*a),p=n(h*nl),g=n(Ye-l),b=n(Ye+l);return new at(n(d*b),n(g*p),n(p*b),n(d*g))}var ct=class t extends vn{static BASE=new t(at.BASE);static ZERO=new t(at.ZERO);static Fp=it;static Fn=Ca;constructor(e){super(e)}static fromAffine(e){return new t(at.fromAffine(e))}assertSame(e){if(!(e instanceof t))throw new Error("RistrettoPoint expected")}init(e){return new t(e)}static fromBytes(e){ve(e,32);let{a:r,d:n}=Yo,s=jt,o=L=>it.create(L),i=Zo(e);if(!aa(it.toBytes(i),e)||Ze(i,s))throw new Error("invalid ristretto255 encoding 1");let a=o(i*i),c=o(Ye+r*a),u=o(Ye-r*a),f=o(c*c),h=o(u*u),l=o(r*n*f-h),{isValid:d,value:p}=_a(o(l*h)),g=o(p*u),b=o(p*g*l),y=o((i+i)*g);Ze(y,s)&&(y=o(-y));let v=o(c*b),S=o(y*v);if(!d||Ze(S,s)||v===Wf)throw new Error("invalid ristretto255 encoding 2");return new t(new at(y,v,Ye,S))}static fromHex(e){return t.fromBytes(hr(e))}toBytes(){let{X:e,Y:r,Z:n,T:s}=this.ep,o=jt,i=b=>it.create(b),a=i(i(n+r)*i(n-r)),c=i(e*r),u=i(c*c),{value:f}=_a(i(a*u)),h=i(f*a),l=i(f*c),d=i(h*l*s),p;if(Ze(s*d,o)){let b=i(r*jo),y=i(e*jo);e=b,r=y,p=i(h*ol)}else p=l;Ze(e*d,o)&&(r=i(-r));let g=i((n-r)*p);return Ze(g,o)&&(g=i(-g)),it.toBytes(g)}equals(e){this.assertSame(e);let{X:r,Y:n}=this.ep,{X:s,Y:o}=e.ep,i=u=>it.create(u),a=i(r*o)===i(n*s),c=i(n*o)===i(r*s);return a||c}is0(){return this.equals(t.ZERO)}};Object.freeze(ct.BASE);Object.freeze(ct.ZERO);Object.freeze(ct.prototype);Object.freeze(ct);var cl=Object.freeze({Point:ct,hashToCurve(t,e){let r=e?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":e.DST,n=Ho(t,r,64,dn);return cl.deriveToCurve(n)},hashToScalar(t,e={DST:La}){let r=Ho(t,e.DST,64,dn);return Ca.create(Oe(r))},deriveToCurve(t){ve(t,64);let e=Zo(t.subarray(0,32)),r=ka(e),n=Zo(t.subarray(32,64)),s=ka(n);return new ct(r.add(s))}});var Sr=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},Sn=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var Ie={get(t=globalThis){let e=t.crypto;if(e?.subtle==null)throw new Sn("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 An=32;var Xo,ul=(async()=>{try{return await Ie.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function fl(t,e,r){if(t.buffer instanceof ArrayBuffer){let n=await Ie.get().subtle.importKey("raw",t.buffer,{name:"Ed25519"},!1,["verify"]);return await Ie.get().subtle.verify({name:"Ed25519"},n,Pe(e),Pe(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function ll(t,e,r){return Ra.verify(e,r instanceof Uint8Array?r:r.subarray(),t)}async function Pa(t,e,r){return Xo==null&&(Xo=await ul),Xo?fl(t,e,r):ll(t,e,r)}function hl(t){return t?.buffer instanceof ArrayBuffer}function Oa(t){if(hl(t))return t;let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function In(t,e){e==null&&(e=t.reduce((s,o)=>s+o.length,0));let r=nn(e),n=0;for(let s of t)r.set(s,n),n+=s.length;return Oa(r)}function Bn(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var Tn=class{type="Ed25519";raw;constructor(e){this.raw=Wo(e,An)}toMultihash(){return Be.digest(ze(this))}toCID(){return le.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ae(this.raw,e.raw)}verify(e,r,n){n?.signal?.throwIfAborted();let s=Pa(this.raw,r,e);return Bn(s)?s.then(o=>(n?.signal?.throwIfAborted(),o)):s}};function Jo(t){return t=Wo(t,An),new Tn(t)}function Wo(t,e){if(t=Uint8Array.from(t??[]),t.length!==e)throw new $(`Key must be a Uint8Array of length ${e}, got ${t.length}`);return t}function Ua(t=0){return new Uint8Array(t)}var pl=Math.pow(2,7),ml=Math.pow(2,14),bl=Math.pow(2,21),Qo=Math.pow(2,28),es=Math.pow(2,35),ts=Math.pow(2,42),rs=Math.pow(2,49),q=128,he=127;function Ge(t){if(t<pl)return 1;if(t<ml)return 2;if(t<bl)return 3;if(t<Qo)return 4;if(t<es)return 5;if(t<ts)return 6;if(t<rs)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ns(t,e,r=0){switch(Ge(t)){case 8:e[r++]=t&255|q,t/=128;case 7:e[r++]=t&255|q,t/=128;case 6:e[r++]=t&255|q,t/=128;case 5:e[r++]=t&255|q,t/=128;case 4:e[r++]=t&255|q,t>>>=7;case 3:e[r++]=t&255|q,t>>>=7;case 2:e[r++]=t&255|q,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function yl(t,e,r=0){switch(Ge(t)){case 8:e.set(r++,t&255|q),t/=128;case 7:e.set(r++,t&255|q),t/=128;case 6:e.set(r++,t&255|q),t/=128;case 5:e.set(r++,t&255|q),t/=128;case 4:e.set(r++,t&255|q),t>>>=7;case 3:e.set(r++,t&255|q),t>>>=7;case 2:e.set(r++,t&255|q),t>>>=7;case 1:{e.set(r++,t&255),t>>>=7;break}default:throw new Error("unreachable")}return e}function os(t,e){let r=t[e],n=0;if(n+=r&he,r<q||(r=t[e+1],n+=(r&he)<<7,r<q)||(r=t[e+2],n+=(r&he)<<14,r<q)||(r=t[e+3],n+=(r&he)<<21,r<q)||(r=t[e+4],n+=(r&he)*Qo,r<q)||(r=t[e+5],n+=(r&he)*es,r<q)||(r=t[e+6],n+=(r&he)*ts,r<q)||(r=t[e+7],n+=(r&he)*rs,r<q))return n;throw new RangeError("Could not decode varint")}function gl(t,e){let r=t.get(e),n=0;if(n+=r&he,r<q||(r=t.get(e+1),n+=(r&he)<<7,r<q)||(r=t.get(e+2),n+=(r&he)<<14,r<q)||(r=t.get(e+3),n+=(r&he)<<21,r<q)||(r=t.get(e+4),n+=(r&he)*Qo,r<q)||(r=t.get(e+5),n+=(r&he)*es,r<q)||(r=t.get(e+6),n+=(r&he)*ts,r<q)||(r=t.get(e+7),n+=(r&he)*rs,r<q))return n;throw new RangeError("Could not decode varint")}function Fa(t,e,r=0){return e==null&&(e=Ua(Ge(t))),e instanceof Uint8Array?ns(t,e,r):yl(t,e,r)}function Ka(t,e=0){return t instanceof Uint8Array?os(t,e):gl(t,e)}var ss=new Float32Array([-0]),ut=new Uint8Array(ss.buffer);function Ma(t,e,r){ss[0]=t,e[r]=ut[0],e[r+1]=ut[1],e[r+2]=ut[2],e[r+3]=ut[3]}function qa(t,e){return ut[0]=t[e],ut[1]=t[e+1],ut[2]=t[e+2],ut[3]=t[e+3],ss[0]}var is=new Float64Array([-0]),de=new Uint8Array(is.buffer);function Va(t,e,r){is[0]=t,e[r]=de[0],e[r+1]=de[1],e[r+2]=de[2],e[r+3]=de[3],e[r+4]=de[4],e[r+5]=de[5],e[r+6]=de[6],e[r+7]=de[7]}function za(t,e){return de[0]=t[e],de[1]=t[e+1],de[2]=t[e+2],de[3]=t[e+3],de[4]=t[e+4],de[5]=t[e+5],de[6]=t[e+6],de[7]=t[e+7],is[0]}var xl=BigInt(Number.MAX_SAFE_INTEGER),El=BigInt(Number.MIN_SAFE_INTEGER),Se=class t{lo;hi;constructor(e,r){this.lo=e|0,this.hi=r|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(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,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?e<16384?e<128?1:2:e<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return vt;if(e<xl&&e>El)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,s=e-(n<<32n);return r&&(n=~n|0n,s=~s|0n,++s>Ha&&(s=0n,++n>Ha&&(n=0n))),new t(Number(s),Number(n))}static fromNumber(e){if(e===0)return vt;let r=e<0;r&&(e=-e);let n=e>>>0,s=(e-n)/4294967296>>>0;return r&&(s=~s>>>0,n=~n>>>0,++n>4294967295&&(n=0,++s>4294967295&&(s=0))),new t(n,s)}static from(e){return typeof e=="number"?t.fromNumber(e):typeof e=="bigint"?t.fromBigInt(e):typeof e=="string"?t.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new t(e.low>>>0,e.high>>>0):vt}},vt=new Se(0,0);vt.toBigInt=function(){return 0n};vt.zzEncode=vt.zzDecode=function(){return this};vt.length=function(){return 1};var Ha=4294967296n;function $a(t){let e=0,r=0;for(let n=0;n<t.length;++n)r=t.charCodeAt(n),r<128?e+=1:r<2048?e+=2:(r&64512)===55296&&(t.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function ja(t,e,r){if(r-e<1)return"";let s,o=[],i=0,a;for(;e<r;)a=t[e++],a<128?o[i++]=a:a>191&&a<224?o[i++]=(a&31)<<6|t[e++]&63:a>239&&a<365?(a=((a&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,o[i++]=55296+(a>>10),o[i++]=56320+(a&1023)):o[i++]=(a&15)<<12|(t[e++]&63)<<6|t[e++]&63,i>8191&&((s??(s=[])).push(String.fromCharCode.apply(String,o)),i=0);return s!=null?(i>0&&s.push(String.fromCharCode.apply(String,o.slice(0,i))),s.join("")):String.fromCharCode.apply(String,o.slice(0,i))}function as(t,e,r){let n=r,s,o;for(let i=0;i<t.length;++i)s=t.charCodeAt(i),s<128?e[r++]=s:s<2048?(e[r++]=s>>6|192,e[r++]=s&63|128):(s&64512)===55296&&((o=t.charCodeAt(i+1))&64512)===56320?(s=65536+((s&1023)<<10)+(o&1023),++i,e[r++]=s>>18|240,e[r++]=s>>12&63|128,e[r++]=s>>6&63|128,e[r++]=s&63|128):(e[r++]=s>>12|224,e[r++]=s>>6&63|128,e[r++]=s&63|128);return r-n}function ke(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function Ln(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var cs=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,ke(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 ke(this,4);return Ln(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw ke(this,4);return Ln(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw ke(this,4);let e=qa(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw ke(this,4);let e=za(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),r=this.pos,n=this.pos+e;if(n>this.len)throw ke(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return ja(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw ke(this,e);this.pos+=e}else do if(this.pos>=this.len)throw ke(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 Se(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*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;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw ke(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,e}if(this.len-this.pos>4){for(;r<5;++r)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;r<5;++r){if(this.pos>=this.len)throw ke(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw ke(this,8);let e=Ln(this.buf,this.pos+=4),r=Ln(this.buf,this.pos+=4);return new Se(e,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=os(this.buf,this.pos);return this.pos+=Ge(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 Ar(t){return new cs(t instanceof Uint8Array?t:t.subarray())}function ge(t,e,r){let n=Ar(t);return e.decode(n,void 0,r)}function St(t=0){return new Uint8Array(t)}var ds={};H(ds,{base10:()=>Ll});var z0=new Uint8Array(0);function Ya(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function Xe(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}function Ga(t){return new TextEncoder().encode(t)}function Xa(t){return new TextDecoder().decode(t)}function vl(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var s=0;s<t.length;s++){var o=t.charAt(s),i=o.charCodeAt(0);if(r[i]!==255)throw new TypeError(o+" is ambiguous");r[i]=s}var a=t.length,c=t.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function h(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var g=0,b=0,y=0,v=p.length;y!==v&&p[y]===0;)y++,g++;for(var S=(v-y)*f+1>>>0,L=new Uint8Array(S);y!==v;){for(var T=p[y],R=0,k=S-1;(T!==0||R<b)&&k!==-1;k--,R++)T+=256*L[k]>>>0,L[k]=T%a>>>0,T=T/a>>>0;if(T!==0)throw new Error("Non-zero carry");b=R,y++}for(var B=S-b;B!==S&&L[B]===0;)B++;for(var N=c.repeat(g);B<S;++B)N+=t.charAt(L[B]);return N}function l(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var g=0;if(p[g]!==" "){for(var b=0,y=0;p[g]===c;)b++,g++;for(var v=(p.length-g)*u+1>>>0,S=new Uint8Array(v);p[g];){var L=r[p.charCodeAt(g)];if(L===255)return;for(var T=0,R=v-1;(L!==0||T<y)&&R!==-1;R--,T++)L+=a*S[R]>>>0,S[R]=L%256>>>0,L=L/256>>>0;if(L!==0)throw new Error("Non-zero carry");y=T,g++}if(p[g]!==" "){for(var k=v-y;k!==v&&S[k]===0;)k++;for(var B=new Uint8Array(b+(v-k)),N=b;k!==v;)B[N++]=S[k++];return B}}}function d(p){var g=l(p);if(g)return g;throw new Error(`Non-${e} character`)}return{encode:h,decodeUnsafe:l,decode:d}}var Sl=vl,Al=Sl,Ja=Al;var us=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},fs=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let s=r.codePointAt(0);if(s===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=s,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 Qa(this,e)}},ls=class{decoders;constructor(e){this.decoders=e}or(e){return Qa(this,e)}decode(e){let r=e[0],n=this.decoders[r];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 Qa(t,e){return new ls({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var hs=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,s){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=s,this.encoder=new us(e,r,n),this.decoder=new fs(e,r,s)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Zt({name:t,prefix:e,encode:r,decode:n}){return new hs(t,e,r,n)}function ft({name:t,prefix:e,alphabet:r}){let{encode:n,decode:s}=Ja(r,t);return Zt({prefix:e,name:t,encode:n,decode:o=>Xe(s(o))})}function Il(t,e,r,n){let s=t.length;for(;t[s-1]==="=";)--s;let o=new Uint8Array(s*r/8|0),i=0,a=0,c=0;for(let u=0;u<s;++u){let f=e[t[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,o[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return o}function Bl(t,e,r){let n=e[e.length-1]==="=",s=(1<<r)-1,o="",i=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],i+=8;i>r;)i-=r,o+=e[s&a>>i];if(i!==0&&(o+=e[s&a<<r-i]),n)for(;(o.length*r&7)!==0;)o+="=";return o}function Tl(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function J({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let s=Tl(n);return Zt({prefix:e,name:t,encode(o){return Bl(o,n,r)},decode(o){return Il(o,s,r,t)}})}var Ll=ft({prefix:"9",name:"base10",alphabet:"0123456789"});var ps={};H(ps,{base16:()=>Dl,base16upper:()=>_l});var Dl=J({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),_l=J({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ms={};H(ms,{base2:()=>kl});var kl=J({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var bs={};H(bs,{base256emoji:()=>Ol});var ec=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}"),Cl=ec.reduce((t,e,r)=>(t[r]=e,t),[]),Rl=ec.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function Pl(t){return t.reduce((e,r)=>(e+=Cl[r],e),"")}function Nl(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let s=Rl[n];if(s==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(s)}return new Uint8Array(e)}var Ol=Zt({prefix:"\u{1F680}",name:"base256emoji",encode:Pl,decode:Nl});var ys={};H(ys,{base32:()=>Yt,base32hex:()=>Ml,base32hexpad:()=>Vl,base32hexpadupper:()=>zl,base32hexupper:()=>ql,base32pad:()=>Fl,base32padupper:()=>Kl,base32upper:()=>Ul,base32z:()=>Hl});var Yt=J({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ul=J({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Fl=J({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Kl=J({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ml=J({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),ql=J({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Vl=J({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),zl=J({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Hl=J({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var gs={};H(gs,{base36:()=>Ir,base36upper:()=>$l});var Ir=ft({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),$l=ft({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ws={};H(ws,{base58btc:()=>Ue,base58flickr:()=>jl});var Ue=ft({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),jl=ft({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var xs={};H(xs,{base64:()=>Zl,base64pad:()=>Yl,base64url:()=>Gl,base64urlpad:()=>Xl});var Zl=J({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Yl=J({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Gl=J({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Xl=J({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Es={};H(Es,{base8:()=>Wl});var Wl=J({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var vs={};H(vs,{identity:()=>Jl});var Jl=Zt({prefix:"\0",name:"identity",encode:t=>Xa(t),decode:t=>Ga(t)});var sb=new TextEncoder,ib=new TextDecoder;var As={};H(As,{identity:()=>Eh});var th=nc,tc=128,rh=127,nh=~rh,oh=Math.pow(2,31);function nc(t,e,r){e=e||[],r=r||0;for(var n=r;t>=oh;)e[r++]=t&255|tc,t/=128;for(;t&nh;)e[r++]=t&255|tc,t>>>=7;return e[r]=t|0,nc.bytes=r-n+1,e}var sh=Ss,ih=128,rc=127;function Ss(t,n){var r=0,n=n||0,s=0,o=n,i,a=t.length;do{if(o>=a)throw Ss.bytes=0,new RangeError("Could not decode varint");i=t[o++],r+=s<28?(i&rc)<<s:(i&rc)*Math.pow(2,s),s+=7}while(i>=ih);return Ss.bytes=o-n,r}var ah=Math.pow(2,7),ch=Math.pow(2,14),uh=Math.pow(2,21),fh=Math.pow(2,28),lh=Math.pow(2,35),hh=Math.pow(2,42),dh=Math.pow(2,49),ph=Math.pow(2,56),mh=Math.pow(2,63),bh=function(t){return t<ah?1:t<ch?2:t<uh?3:t<fh?4:t<lh?5:t<hh?6:t<dh?7:t<ph?8:t<mh?9:10},yh={encode:th,decode:sh,encodingLength:bh},gh=yh,Br=gh;function Tr(t,e=0){return[Br.decode(t,e),Br.decode.bytes]}function Gt(t,e,r=0){return Br.encode(t,e,r),e}function Xt(t){return Br.encodingLength(t)}function Jt(t,e){let r=e.byteLength,n=Xt(t),s=n+Xt(r),o=new Uint8Array(s+r);return Gt(t,o,0),Gt(r,o,n),o.set(e,s),new Wt(t,r,e,o)}function oc(t){let e=Xe(t),[r,n]=Tr(e),[s,o]=Tr(e.subarray(n)),i=e.subarray(n+o);if(i.byteLength!==s)throw new Error("Incorrect length");return new Wt(r,s,i,e)}function sc(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&Ya(t.bytes,r.bytes)}}var Wt=class{code;size;digest;bytes;constructor(e,r,n,s){this.code=e,this.size=r,this.digest=n,this.bytes=s}};var ic=0,wh="identity",ac=Xe;function xh(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return Jt(ic,ac(t))}var Eh={code:ic,name:wh,encode:ac,digest:xh};var Ts={};H(Ts,{sha256:()=>Sh,sha512:()=>Ah});var vh=20;function Bs({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:s}){return new Is(t,e,r,n,s)}var Is=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,s,o){this.name=e,this.code=r,this.encode=n,this.minDigestLength=s??vh,this.maxDigestLength=o}digest(e,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?cc(n,this.code,r?.truncate):n.then(s=>cc(s,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function cc(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return Jt(e,t)}function fc(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Sh=Bs({name:"sha2-256",code:18,encode:fc("SHA-256")}),Ah=Bs({name:"sha2-512",code:19,encode:fc("SHA-512")});function lc(t,e){let{bytes:r,version:n}=t;return n===0?Bh(r,Ls(t),e??Ue.encoder):Th(r,Ls(t),e??Yt.encoder)}var hc=new WeakMap;function Ls(t){let e=hc.get(t);if(e==null){let r=new Map;return hc.set(t,r),r}return e}var _n=class t{code;version;multihash;bytes;"/";constructor(e,r,n,s){this.code=r,this.version=e,this.multihash=n,this.bytes=s,this["/"]=s}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:r}=this;if(e!==Dr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Lh)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:r}=this.multihash,n=Jt(e,r);return t.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 t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&sc(e.multihash,n.multihash)}toString(e){return lc(this,e)}toJSON(){return{"/":lc(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 r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:s,multihash:o,bytes:i}=r;return new t(n,s,o,i??dc(n,s,o.bytes))}else if(r[Dh]===!0){let{version:n,multihash:s,code:o}=r,i=oc(s);return t.create(n,o,i)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==Dr)throw new Error(`Version 0 CID must use dag-pb (code: ${Dr}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let s=dc(e,r,n.bytes);return new t(e,r,n,s)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,Dr,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,s=Xe(e.subarray(n,n+r.multihashSize));if(s.byteLength!==r.multihashSize)throw new Error("Incorrect length");let o=s.subarray(r.multihashSize-r.digestSize),i=new Wt(r.multihashCode,r.digestSize,o,s);return[r.version===0?t.createV0(i):t.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[h,l]=Tr(e.subarray(r));return r+=l,h},s=n(),o=Dr;if(s===18?(s=0,r=0):o=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let i=r,a=n(),c=n(),u=r+c,f=u-i;return{version:s,codec:o,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(e,r){let[n,s]=Ih(e,r),o=t.decode(s);if(o.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Ls(o).set(n,e),o}};function Ih(t,e){switch(t[0]){case"Q":{let r=e??Ue;return[Ue.prefix,r.decode(`${Ue.prefix}${t}`)]}case Ue.prefix:{let r=e??Ue;return[Ue.prefix,r.decode(t)]}case Yt.prefix:{let r=e??Yt;return[Yt.prefix,r.decode(t)]}case Ir.prefix:{let r=e??Ir;return[Ir.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function Bh(t,e,r){let{prefix:n}=r;if(n!==Ue.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let s=e.get(n);if(s==null){let o=r.encode(t).slice(1);return e.set(n,o),o}else return s}function Th(t,e,r){let{prefix:n}=r,s=e.get(n);if(s==null){let o=r.encode(t);return e.set(n,o),o}else return s}var Dr=112,Lh=18;function dc(t,e,r){let n=Xt(t),s=n+Xt(e),o=new Uint8Array(s+r.byteLength);return Gt(t,o,0),Gt(e,o,n),o.set(r,s),o}var Dh=Symbol.for("@ipld/js-cid/CID");var Ds={...vs,...ms,...Es,...ds,...ps,...ys,...gs,...ws,...xs,...bs},Lb={...Ts,...As};function mc(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var pc=mc("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),_s=mc("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=St(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),_h={utf8:pc,"utf-8":pc,hex:Ds.base16,latin1:_s,ascii:_s,binary:_s,...Ds},bc=_h;function yc(t,e="utf8"){let r=bc[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function ks(t){let e=t??8192,r=e>>>1,n,s=e;return function(i){if(i<1||i>r)return St(i);s+i>e&&(n=St(e),s=0);let a=n.subarray(s,s+=i);return(s&7)!==0&&(s=(s|7)+1),a}}var At=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function Cs(){}var Ps=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},kh=ks();function Ch(t){return globalThis.Buffer!=null?St(t):kh(t)}var kr=class{len;head;tail;states;constructor(){this.len=0,this.head=new At(Cs,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new At(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Ns((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(kn,10,Se.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=Se.fromBigInt(e);return this._push(kn,r.length(),r)}uint64Number(e){return this._push(ns,Ge(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 r=Se.fromBigInt(e).zzEncode();return this._push(kn,r.length(),r)}sint64Number(e){let r=Se.fromNumber(e).zzEncode();return this._push(kn,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Rs,1,e?1:0)}fixed32(e){return this._push(_r,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=Se.fromBigInt(e);return this._push(_r,4,r.lo)._push(_r,4,r.hi)}fixed64Number(e){let r=Se.fromNumber(e);return this._push(_r,4,r.lo)._push(_r,4,r.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(Ma,4,e)}double(e){return this._push(Va,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(Rs,1,0):this.uint32(r)._push(Ph,r,e)}string(e){let r=$a(e);return r!==0?this.uint32(r)._push(as,r,e):this._push(Rs,1,0)}fork(){return this.states=new Ps(this),this.head=this.tail=new At(Cs,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 At(Cs,0,0),this.len=0),this}ldelim(){let e=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=r,this.len+=n),this}finish(){let e=this.head.next,r=Ch(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function Rs(t,e,r){e[r]=t&255}function Rh(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var Ns=class extends At{next;constructor(e,r){super(Rh,e,r),this.next=void 0}};function kn(t,e,r){for(;t.hi!==0;)e[r++]=t.lo&127|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;t.lo>127;)e[r++]=t.lo&127|128,t.lo=t.lo>>>7;e[r++]=t.lo}function _r(t,e,r){e[r]=t&255,e[r+1]=t>>>8&255,e[r+2]=t>>>16&255,e[r+3]=t>>>24}function Ph(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(kr.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(Nh,e,t),this},kr.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(Oh,e,t),this});function Nh(t,e,r){e.set(t,r)}function Oh(t,e,r){t.length<40?as(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(yc(t),r)}function Os(){return new kr}function we(t,e){let r=Os();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*xe(t,e,r){let n=Ar(t);yield*e.stream(n,void 0,"$",r)}var Cn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Rn(t,e,r,n,s){return{name:t,type:e,encode:r,decode:n,stream:s}}function Us(t){function e(o){if(t[o.toString()]==null)throw new Error("Invalid enum value");return t[o]}let r=function(i,a){let c=e(i);a.int32(c)},n=function(i){let a=i.int32();return e(a)},s=function*(i){let a=i.int32();yield e(a)};return Rn("enum",Cn.VARINT,r,n,s)}function Ee(t,e,r){return Rn("message",Cn.LENGTH_DELIMITED,t,e,r)}var re=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var G;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.ECDSA="ECDSA"})(G||(G={}));var Fs;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(Fs||(Fs={}));(function(t){t.codec=()=>Us(Fs)})(G||(G={}));var Fe;(function(t){let e;t.codec=()=>(e==null&&(e=Ee((o,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),o.Type!=null&&(i.uint32(8),G.codec().encode(o.Type,i)),o.Data!=null&&(i.uint32(18),i.bytes(o.Data)),a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{c.Type=G.codec().decode(o);break}case 2:{c.Data=o.bytes();break}default:{o.skipType(f&7);break}}}return c},function*(o,i,a,c={}){let u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:G.codec().decode(o)};break}case 2:{yield{field:`${a}.Data`,value:o.bytes()};break}default:{o.skipType(f&7);break}}}})),e);function r(o){return we(o,t.codec())}t.encode=r;function n(o,i){return ge(o,t.codec(),i)}t.decode=n;function s(o,i){return xe(o,t.codec(),i)}t.stream=s})(Fe||(Fe={}));var Ks;(function(t){let e;t.codec=()=>(e==null&&(e=Ee((o,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),o.Type!=null&&(i.uint32(8),G.codec().encode(o.Type,i)),o.Data!=null&&(i.uint32(18),i.bytes(o.Data)),a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{c.Type=G.codec().decode(o);break}case 2:{c.Data=o.bytes();break}default:{o.skipType(f&7);break}}}return c},function*(o,i,a,c={}){let u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:G.codec().decode(o)};break}case 2:{yield{field:`${a}.Data`,value:o.bytes()};break}default:{o.skipType(f&7);break}}}})),e);function r(o){return we(o,t.codec())}t.encode=r;function n(o,i){return ge(o,t.codec(),i)}t.decode=n;function s(o,i){return xe(o,t.codec(),i)}t.stream=s})(Ks||(Ks={}));function Pn(t){if(isNaN(t)||t<=0)throw new $("random bytes length must be a Number bigger than 0");return ln(t)}var Rr={};H(Rr,{MAX_RSA_KEY_SIZE:()=>Ms,generateRSAKeyPair:()=>vc,jwkToJWKKeyPair:()=>Sc,jwkToPkcs1:()=>Mh,jwkToPkix:()=>Hs,jwkToRSAPrivateKey:()=>Ys,pkcs1MessageToJwk:()=>Vs,pkcs1MessageToRSAPrivateKey:()=>$s,pkcs1ToJwk:()=>Kh,pkcs1ToRSAPrivateKey:()=>Ec,pkixMessageToJwk:()=>zs,pkixMessageToRSAPublicKey:()=>Zs,pkixToJwk:()=>qh,pkixToRSAPublicKey:()=>js});var Qt=class{type="RSA";jwk;_raw;_multihash;constructor(e,r){this.jwk=e,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Rr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return le.createV1(114,this._multihash)}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ae(this.raw,e.raw)}verify(e,r,n){return xc(this.jwk,r,e,n)}},Cr=class{type="RSA";jwk;_raw;publicKey;constructor(e,r){this.jwk=e,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Rr.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ae(this.raw,e.raw)}sign(e,r){return wc(this.jwk,e,r)}};var Ms=8192,qs=18,Uh=1062,Fh=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Kh(t){let e=Ve(t);return Vs(e)}function Vs(t){return{n:z(t[1],"base64url"),e:z(t[2],"base64url"),d:z(t[3],"base64url"),p:z(t[4],"base64url"),q:z(t[5],"base64url"),dp:z(t[6],"base64url"),dq:z(t[7],"base64url"),qi:z(t[8],"base64url"),kty:"RSA"}}function Mh(t){if(t.n==null||t.e==null||t.d==null||t.p==null||t.q==null||t.dp==null||t.dq==null||t.qi==null)throw new $("JWK was missing components");return et([ye(Uint8Array.from([0])),ye(j(t.n,"base64url")),ye(j(t.e,"base64url")),ye(j(t.d,"base64url")),ye(j(t.p,"base64url")),ye(j(t.q,"base64url")),ye(j(t.dp,"base64url")),ye(j(t.dq,"base64url")),ye(j(t.qi,"base64url"))]).subarray()}function qh(t){let e=Ve(t,{offset:0});return zs(e)}function zs(t){let e=Ve(t[1],{offset:0});return{kty:"RSA",n:z(e[0],"base64url"),e:z(e[1],"base64url")}}function Hs(t){if(t.n==null||t.e==null)throw new $("JWK was missing components");return et([Fh,sn(et([ye(j(t.n,"base64url")),ye(j(t.e,"base64url"))]))]).subarray()}function Ec(t){let e=Ve(t);return $s(e)}function $s(t){let e=Vs(t);return Ys(e)}function js(t,e){if(t.byteLength>=Uh)throw new Dt("Key size is too large");let r=Ve(t,{offset:0});return Zs(r,t,e)}function Zs(t,e,r){let n=zs(t);if(r==null){let s=Ft(Fe.encode({Type:G.RSA,Data:e}));r=Re(qs,s)}return new Qt(n,r)}function Ys(t){if(Ic(t)>Ms)throw new $("Key size is too large");let e=Sc(t),r=Ft(Fe.encode({Type:G.RSA,Data:Hs(e.publicKey)})),n=Re(qs,r);return new Cr(e.privateKey,new Qt(e.publicKey,n))}async function vc(t){if(t>Ms)throw new $("Key size is too large");let e=await Ac(t),r=Ft(Fe.encode({Type:G.RSA,Data:Hs(e.publicKey)})),n=Re(qs,r);return new Cr(e.privateKey,new Qt(e.publicKey,n))}function Sc(t){if(t==null)throw new $("Missing key parameter");return{privateKey:t,publicKey:{kty:t.kty,n:t.n,e:t.e}}}async function Ac(t,e){let r=await Ie.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:t,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);e?.signal?.throwIfAborted();let n=await Vh(r,e);return{privateKey:n[0],publicKey:n[1]}}async function wc(t,e,r){let n=await Ie.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let s=await Ie.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,Pe(e instanceof Uint8Array?e:e.subarray()));return r?.signal?.throwIfAborted(),new Uint8Array(s,0,s.byteLength)}async function xc(t,e,r,n){let s=await Ie.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let o=await Ie.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},s,Pe(e),Pe(r instanceof Uint8Array?r:r.subarray()));return n?.signal?.throwIfAborted(),o}async function Vh(t,e){if(t.privateKey==null||t.publicKey==null)throw new $("Private and public key are required");let r=await Promise.all([Ie.get().subtle.exportKey("jwk",t.privateKey),Ie.get().subtle.exportKey("jwk",t.publicKey)]);return e?.signal?.throwIfAborted(),r}function Ic(t){if(t.kty!=="RSA")throw new $("invalid key type");if(t.n==null)throw new $("invalid key modulus");return j(t.n,"base64url").length*8}var Nn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,r){if(an(e),ve(r,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,s=new Uint8Array(n);s.set(r.length>n?e.create().update(r).digest():r);for(let o=0;o<s.length;o++)s[o]^=54;this.iHash.update(s),this.oHash=e.create();for(let o=0;o<s.length;o++)s[o]^=106;this.oHash.update(s),$e(s)}update(e){return Ut(this),this.iHash.update(e),this}digestInto(e){Ut(this),cn(e,this),this.finished=!0;let r=e.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),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:r,iHash:n,finished:s,destroyed:o,blockLen:i,outputLen:a}=this;return e=e,e.finished=s,e.destroyed=o,e.blockLen=i,e.outputLen=a,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Bc=(()=>{let t=((e,r,n)=>new Nn(e,r).update(n).digest());return t.create=(e,r)=>new Nn(e,r),t})();var Tc=(t,e)=>(t+(t>=0?e:-e)/Lc)/e;function zh(t,e,r){qt("scalar",t,Ke,r);let[[n,s],[o,i]]=e,a=Tc(i*t,r),c=Tc(-s*t,r),u=t-a*n-c*o,f=-a*s-c*i,h=u<Ke,l=f<Ke;h&&(u=-u),l&&(f=-f);let d=wr(Math.ceil(Vt(r)/2))+lt;if(u<Ke||u>=d||f<Ke||f>=d)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:h,k1:u,k2neg:l,k2:f}}function Xs(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function Gs(t,e){_e(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return Le(r.lowS,"lowS"),Le(r.prehash,"prehash"),r.format!==void 0&&Xs(r.format),r}var Ws=class extends Error{constructor(e=""){super(e)}},Ce={Err:Ws,_tlv:{encode:(t,e)=>{let{Err:r}=Ce;if(De(t,"tag"),t<0||t>255)throw new r("tlv.encode: wrong tag");if(typeof e!="string")throw new TypeError('"data" expected string, got type='+typeof e);if(e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,s=yr(n);if(s.length/2&128)throw new r("tlv.encode: long form length too big");let o=n>127?yr(s.length/2|128):"";return yr(t)+o+s+e},decode(t,e){let{Err:r}=Ce;e=K(e,void 0,"DER data");let n=0;if(t<0||t>255)throw new r("tlv.encode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let s=e[n++],o=!!(s&128),i=0;if(!o)i=s;else{let c=s&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=e.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)i=i<<8|f;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+i)}}},_int:{encode(t){let{Err:e}=Ce;if(bn(t),t<Ke)throw new e("integer: negative integers are not allowed");let r=yr(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=Ce;if(t.length<1)throw new e("invalid signature integer: empty");if(t[0]&128)throw new e("invalid signature integer: negative");if(t.length>1&&t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return gt(t)}},toSig(t){let{Err:e,_int:r,_tlv:n}=Ce,s=K(t,void 0,"signature"),{v:o,l:i}=n.decode(48,s);if(i.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,o),{v:u,l:f}=n.decode(2,c);if(f.length)throw new e("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(u)}},hexFromSig(t){let{_tlv:e,_int:r}=Ce,n=e.encode(2,r.encode(t.r)),s=e.encode(2,r.encode(t.s)),o=n+s;return e.encode(48,o)}};Object.freeze(Ce._tlv);Object.freeze(Ce._int);Object.freeze(Ce);var Ke=BigInt(0),lt=BigInt(1),Lc=BigInt(2),On=BigInt(3),Hh=BigInt(4);function Dc(t,e={}){let r=xn("weierstrass",t,e),n=r.Fp,s=r.Fn,o=r.CURVE,{h:i,n:a}=o;_e(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c,allowInfinityPoint:u}=e;if(c&&(!n.is0(o.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let f=kc(n,s);function h(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(O,m,w){if(u&&m.is0())return Uint8Array.of(0);let{x:A,y:E}=m.toAffine(),x=n.toBytes(A);if(Le(w,"isCompressed"),w){h();let I=!n.isOdd(E);return oe(_c(I),x)}else return oe(Uint8Array.of(4),x,n.toBytes(E))}function d(O){K(O,void 0,"Point");let{publicKey:m,publicKeyUncompressed:w}=f,A=O.length,E=O[0],x=O.subarray(1);if(u&&A===1&&E===0)return{x:n.ZERO,y:n.ZERO};if(A===m&&(E===2||E===3)){let I=n.fromBytes(x);if(!n.isValid(I))throw new Error("bad point: is not on curve, wrong x");let _=b(I),D;try{D=n.sqrt(_)}catch(F){let M=F instanceof Error?": "+F.message:"";throw new Error("bad point: is not on curve, sqrt error"+M)}h();let C=n.isOdd(D);return(E&1)===1!==C&&(D=n.neg(D)),{x:I,y:D}}else if(A===w&&E===4){let I=n.BYTES,_=n.fromBytes(x.subarray(0,I)),D=n.fromBytes(x.subarray(I,I*2));if(!y(_,D))throw new Error("bad point: is not on curve");return{x:_,y:D}}else throw new Error(`bad point: got length ${A}, expected compressed=${m} or uncompressed=${w}`)}let p=e.toBytes===void 0?l:e.toBytes,g=e.fromBytes===void 0?d:e.fromBytes;function b(O){let m=n.sqr(O),w=n.mul(m,O);return n.add(n.add(w,n.mul(O,o.a)),o.b)}function y(O,m){let w=n.sqr(m),A=b(O);return n.eql(w,A)}if(!y(o.Gx,o.Gy))throw new Error("bad curve params: generator point");let v=n.mul(n.pow(o.a,On),Hh),S=n.mul(n.sqr(o.b),BigInt(27));if(n.is0(n.add(v,S)))throw new Error("bad curve params: a or b");function L(O,m,w=!1){if(!n.isValid(m)||w&&n.is0(m))throw new Error(`bad point coordinate ${O}`);return m}function T(O){if(!(O instanceof B))throw new Error("Weierstrass Point expected")}function R(O){if(!c||!c.basises)throw new Error("no endo");return zh(O,c.basises,s.ORDER)}function k(O,m,w,A,E){return w=new B(n.mul(w.X,O),w.Y,w.Z),m=Er(A,m),w=Er(E,w),m.add(w)}class B{static BASE=new B(o.Gx,o.Gy,n.ONE);static ZERO=new B(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=s;X;Y;Z;constructor(m,w,A){this.X=L("x",m),this.Y=L("y",w,!0),this.Z=L("z",A),Object.freeze(this)}static CURVE(){return o}static fromAffine(m){let{x:w,y:A}=m||{};if(!m||!n.isValid(w)||!n.isValid(A))throw new Error("invalid affine point");if(m instanceof B)throw new Error("projective point not allowed");return n.is0(w)&&n.is0(A)?B.ZERO:new B(w,A,n.ONE)}static fromBytes(m){let w=B.fromAffine(g(K(m,void 0,"point")));return w.assertValidity(),w}static fromHex(m){return B.fromBytes(Mt(m))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=8,w=!0){return V.createCache(this,m),w||this.multiply(On),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:w,y:A}=m.toAffine();if(!n.isValid(w)||!n.isValid(A))throw new Error("bad point: x or y not field elements");if(!y(w,A))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){T(m);let{X:w,Y:A,Z:E}=this,{X:x,Y:I,Z:_}=m,D=n.eql(n.mul(w,_),n.mul(x,E)),C=n.eql(n.mul(A,_),n.mul(I,E));return D&&C}negate(){return new B(this.X,n.neg(this.Y),this.Z)}double(){let{a:m,b:w}=o,A=n.mul(w,On),{X:E,Y:x,Z:I}=this,_=n.ZERO,D=n.ZERO,C=n.ZERO,P=n.mul(E,E),F=n.mul(x,x),M=n.mul(I,I),U=n.mul(E,x);return U=n.add(U,U),C=n.mul(E,I),C=n.add(C,C),_=n.mul(m,C),D=n.mul(A,M),D=n.add(_,D),_=n.sub(F,D),D=n.add(F,D),D=n.mul(_,D),_=n.mul(U,_),C=n.mul(A,C),M=n.mul(m,M),U=n.sub(P,M),U=n.mul(m,U),U=n.add(U,C),C=n.add(P,P),P=n.add(C,P),P=n.add(P,M),P=n.mul(P,U),D=n.add(D,P),M=n.mul(x,I),M=n.add(M,M),P=n.mul(M,U),_=n.sub(_,P),C=n.mul(M,F),C=n.add(C,C),C=n.add(C,C),new B(_,D,C)}add(m){T(m);let{X:w,Y:A,Z:E}=this,{X:x,Y:I,Z:_}=m,D=n.ZERO,C=n.ZERO,P=n.ZERO,F=o.a,M=n.mul(o.b,On),U=n.mul(w,x),ne=n.mul(A,I),se=n.mul(E,_),ie=n.add(w,A),Q=n.add(x,I);ie=n.mul(ie,Q),Q=n.add(U,ne),ie=n.sub(ie,Q),Q=n.add(w,E);let be=n.add(x,_);return Q=n.mul(Q,be),be=n.add(U,se),Q=n.sub(Q,be),be=n.add(A,E),D=n.add(I,_),be=n.mul(be,D),D=n.add(ne,se),be=n.sub(be,D),P=n.mul(F,Q),D=n.mul(M,se),P=n.add(D,P),D=n.sub(ne,P),P=n.add(ne,P),C=n.mul(D,P),ne=n.add(U,U),ne=n.add(ne,U),se=n.mul(F,se),Q=n.mul(M,Q),ne=n.add(ne,se),se=n.sub(U,se),se=n.mul(F,se),Q=n.add(Q,se),U=n.mul(ne,Q),C=n.add(C,U),U=n.mul(be,Q),D=n.mul(ie,D),D=n.sub(D,U),U=n.mul(ie,ne),P=n.mul(be,P),P=n.add(P,U),new B(D,C,P)}subtract(m){return T(m),this.add(m.negate())}is0(){return this.equals(B.ZERO)}multiply(m){let{endo:w}=e;if(!s.isValidNot0(m))throw new RangeError("invalid scalar: out of range");let A,E,x=I=>V.cached(this,I,_=>Et(B,_));if(w){let{k1neg:I,k1:_,k2neg:D,k2:C}=R(m),{p:P,f:F}=x(_),{p:M,f:U}=x(C);E=F.add(U),A=k(w.beta,P,M,I,D)}else{let{p:I,f:_}=x(m);A=I,E=_}return Et(B,[A,E])[0]}multiplyUnsafe(m){let{endo:w}=e,A=this,E=m;if(!s.isValid(E))throw new RangeError("invalid scalar: out of range");if(E===Ke||A.is0())return B.ZERO;if(E===lt)return A;if(V.hasCache(this))return this.multiply(E);if(w){let{k1neg:x,k1:I,k2neg:_,k2:D}=R(E),{p1:C,p2:P}=Ia(B,A,I,D);return k(w.beta,C,P,x,_)}else return V.unsafe(A,E)}toAffine(m){let w=this,A=m,{X:E,Y:x,Z:I}=w;if(n.eql(I,n.ONE))return{x:E,y:x};let _=w.is0();A==null&&(A=_?n.ONE:n.inv(I));let D=n.mul(E,A),C=n.mul(x,A),P=n.mul(I,A);if(_)return{x:n.ZERO,y:n.ZERO};if(!n.eql(P,n.ONE))throw new Error("invZ was invalid");return{x:D,y:C}}isTorsionFree(){let{isTorsionFree:m}=e;return i===lt?!0:m?m(B,this):V.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:m}=e;return i===lt?this:m?m(B,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===lt?this.is0():this.clearCofactor().is0()}toBytes(m=!0){return Le(m,"isCompressed"),this.assertValidity(),p(B,this,m)}toHex(m=!0){return Kt(this.toBytes(m))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let N=s.BITS,V=new $t(B,e.endo?Math.ceil(N/2):N);return N>=8&&B.BASE.precompute(8),Object.freeze(B.prototype),Object.freeze(B),B}function _c(t){return Uint8Array.of(t?2:3)}function kc(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function $h(t,e={}){let{Fn:r}=t,n=e.randomBytes===void 0?br:e.randomBytes,s=Object.assign(kc(t.Fp,r),{seed:Math.max(Fo(r.ORDER),16)});function o(d){try{let p=r.fromBytes(d);return r.isValidNot0(p)}catch{return!1}}function i(d,p){let{publicKey:g,publicKeyUncompressed:b}=s;try{let y=d.length;return p===!0&&y!==g||p===!1&&y!==b?!1:!!t.fromBytes(d)}catch{return!1}}function a(d){return d=d===void 0?n(s.seed):d,Ko(K(d,s.seed,"seed"),r.ORDER)}function c(d,p=!0){return t.BASE.multiply(r.fromBytes(d)).toBytes(p)}function u(d){let{secretKey:p,publicKey:g,publicKeyUncompressed:b}=s,y=r._lengths;if(!yt(d))return;let v=K(d,void 0,"key").length,S=v===g||v===b,L=v===p||!!y?.includes(v);if(!(S&&L))return S}function f(d,p,g=!0){if(u(d)===!0)throw new Error("first arg must be private key");if(u(p)===!1)throw new Error("second arg must be public key");let b=r.fromBytes(d);return t.fromBytes(p).multiply(b).toBytes(g)}let h={isValidSecretKey:o,isValidPublicKey:i,randomSecretKey:a},l=En(a,c);return Object.freeze(h),Object.freeze(s),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:l,Point:t,utils:h,lengths:s})}function Cc(t,e,r={}){let n=e;an(n),_e(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let s=r.randomBytes===void 0?br:r.randomBytes,o=r.hmac===void 0?(E,x)=>Bc(n,E,x):r.hmac,{Fp:i,Fn:a}=t,{ORDER:c,BITS:u}=a,{keygen:f,getPublicKey:h,getSharedSecret:l,utils:d,lengths:p}=$h(t,r),g={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},b=c*Lc+lt<i.ORDER;function y(E){let x=c>>lt;return E>x}function v(E,x){if(!a.isValidNot0(x))throw new Error(`invalid signature ${E}: out of range 1..Point.Fn.ORDER`);return x}function S(){if(b)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function L(E,x){Xs(x);let I=p.signature,_=x==="compact"?I:x==="recovered"?I+1:void 0;return K(E,_)}class T{r;s;recovery;constructor(x,I,_){if(this.r=v("r",x),this.s=v("s",I),_!=null){if(S(),![0,1,2,3].includes(_))throw new Error("invalid recovery id");this.recovery=_}Object.freeze(this)}static fromBytes(x,I=g.format){L(x,I);let _;if(I==="der"){let{r:F,s:M}=Ce.toSig(K(x));return new T(F,M)}I==="recovered"&&(_=x[0],I="compact",x=x.subarray(1));let D=p.signature/2,C=x.subarray(0,D),P=x.subarray(D,D*2);return new T(a.fromBytes(C),a.fromBytes(P),_)}static fromHex(x,I){return this.fromBytes(Mt(x),I)}assertRecovery(){let{recovery:x}=this;if(x==null)throw new Error("invalid recovery id: must be present");return x}addRecoveryBit(x){return new T(this.r,this.s,x)}recoverPublicKey(x){let{r:I,s:_}=this,D=this.assertRecovery(),C=D===2||D===3?I+c:I;if(!i.isValid(C))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let P=i.toBytes(C),F=t.fromBytes(oe(_c((D&1)===0),P)),M=a.inv(C),U=k(K(x,void 0,"msgHash")),ne=a.create(-U*M),se=a.create(_*M),ie=t.BASE.multiplyUnsafe(ne).add(F.multiplyUnsafe(se));if(ie.is0())throw new Error("invalid recovery: point at infinify");return ie.assertValidity(),ie}hasHighS(){return y(this.s)}toBytes(x=g.format){if(Xs(x),x==="der")return Mt(Ce.hexFromSig(this));let{r:I,s:_}=this,D=a.toBytes(I),C=a.toBytes(_);return x==="recovered"?(S(),oe(Uint8Array.of(this.assertRecovery()),D,C)):oe(D,C)}toHex(x){return Kt(this.toBytes(x))}}Object.freeze(T.prototype),Object.freeze(T);let R=r.bits2int===void 0?function(x){if(x.length>8192)throw new Error("input is too large");let I=gt(x),_=x.length*8-u;return _>0?I>>BigInt(_):I}:r.bits2int,k=r.bits2int_modN===void 0?function(x){return a.create(R(x))}:r.bits2int_modN,B=wr(u);function N(E){return qt("num < 2^"+u,E,Ke,B),a.toBytes(E)}function V(E,x){return K(E,void 0,"message"),x?K(n(E),void 0,"prehashed message"):E}function O(E,x,I){let{lowS:_,prehash:D,extraEntropy:C}=Gs(I,g);E=V(E,D);let P=k(E),F=a.fromBytes(x);if(!a.isValidNot0(F))throw new Error("invalid private key");let M=[N(F),N(P)];if(C!=null&&C!==!1){let ie=C===!0?s(p.secretKey):C;M.push(K(ie,void 0,"extraEntropy"))}let U=oe(...M),ne=P;function se(ie){let Q=R(ie);if(!a.isValidNot0(Q))return;let be=a.inv(Q),Lt=t.BASE.multiply(Q).toAffine(),nr=a.create(Lt.x);if(nr===Ke)return;let Wr=a.create(be*a.create(ne+nr*F));if(Wr===Ke)return;let pi=(Lt.x===nr?0:2)|Number(Lt.y<),mi=Wr;return _&&y(Wr)&&(mi=a.neg(Wr),pi^=1),new T(nr,mi,b?void 0:pi)}return{seed:U,k2sig:se}}function m(E,x,I={}){let{seed:_,k2sig:D}=O(E,x,I);return ca(n.outputLen,a.BYTES,o)(_,D).toBytes(I.format)}function w(E,x,I,_={}){let{lowS:D,prehash:C,format:P}=Gs(_,g);if(I=K(I,void 0,"publicKey"),x=V(x,C),!yt(E)){let F=E instanceof T?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+F)}L(E,P);try{let F=T.fromBytes(E,P),M=t.fromBytes(I);if(D&&F.hasHighS())return!1;let{r:U,s:ne}=F,se=k(x),ie=a.inv(ne),Q=a.create(se*ie),be=a.create(U*ie),Lt=t.BASE.multiplyUnsafe(Q).add(M.multiplyUnsafe(be));return Lt.is0()?!1:a.create(Lt.x)===U}catch{return!1}}function A(E,x,I={}){let{prehash:_}=Gs(I,g);return x=V(x,_),T.fromBytes(E,"recovered").recoverPublicKey(x).toBytes()}return Object.freeze({keygen:f,getPublicKey:h,getSharedSecret:l,utils:d,lengths:p,Point:t,sign:m,verify:w,recoverPublicKey:A,Signature:T,hash:n})}var Qs={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},jh={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Rc=BigInt(2);function Zh(t){let e=Qs.p,r=BigInt(3),n=BigInt(6),s=BigInt(11),o=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=t*t*t%e,f=u*u*t%e,h=Z(f,r,e)*f%e,l=Z(h,r,e)*f%e,d=Z(l,Rc,e)*u%e,p=Z(d,s,e)*d%e,g=Z(p,o,e)*p%e,b=Z(g,a,e)*g%e,y=Z(b,c,e)*b%e,v=Z(y,a,e)*g%e,S=Z(v,r,e)*f%e,L=Z(S,i,e)*p%e,T=Z(L,n,e)*u%e,R=Z(T,Rc,e);if(!Js.eql(Js.sqr(R),t))throw new Error("Cannot find square root");return R}var Js=zt(Qs.p,{sqrt:Zh}),Yh=Dc(Qs,{Fp:Js,endo:jh}),er=Cc(Yh,Ft);function Pc(t,e,r,n){let s=pt.digest(r instanceof Uint8Array?r:r.subarray());if(Bn(s))return s.then(({digest:o})=>(n?.signal?.throwIfAborted(),er.verify(e,o,t,{prehash:!1,format:"der"}))).catch(o=>{throw o.name==="AbortError"?o:new Sr(String(o))});try{return n?.signal?.throwIfAborted(),er.verify(e,s.digest,t,{prehash:!1,format:"der"})}catch(o){throw new Sr(String(o))}}var Un=class{type="secp256k1";raw;_key;constructor(e){this._key=Oc(e),this.raw=Nc(this._key)}toMultihash(){return Be.digest(ze(this))}toCID(){return le.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:Ae(this.raw,e.raw)}verify(e,r,n){return Pc(this._key,r,e,n)}};function ei(t){return new Un(t)}function Nc(t){return er.Point.fromBytes(t).toBytes()}function Oc(t){try{return er.Point.fromBytes(t),t}catch(e){throw new Dt(String(e))}}function ti(t,e){let{Type:r,Data:n}=Fe.decode(t),s=n??new Uint8Array;switch(r){case G.RSA:return js(s,e);case G.Ed25519:return Jo(s);case G.secp256k1:return ei(s);case G.ECDSA:return Eo(s);default:throw new ht}}function Uc(t){let{Type:e,Data:r}=Fe.decode(t.digest),n=r??new Uint8Array;switch(e){case G.Ed25519:return Jo(n);case G.secp256k1:return ei(n);case G.ECDSA:return Eo(n);default:throw new ht}}function ze(t){return Fe.encode({Type:G[t.type],Data:t.raw})}var Fc=Symbol.for("nodejs.util.inspect.custom"),Gh=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()})`}[$n]=!0;toString(){return this.string==null&&(this.string=Y.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return le.createV1(Gh,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return Ae(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return Ae(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[Fc](){return`PeerId(${this.toString()})`}},Nr=class extends Pr{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Or=class extends Pr{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},Ur=class extends Pr{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},Xh=2336,Fn=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=Be.digest(j(this.url))}[Fc](){return`PeerId(${this.url})`}[$n]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return le.createV1(Xh,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=z(e)),e.toString()===this.toString())}};function ri(t){if(t.type==="Ed25519")return new Or({multihash:t.toCID().multihash,publicKey:t});if(t.type==="secp256k1")return new Ur({multihash:t.toCID().multihash,publicKey:t});if(t.type==="RSA")return new Nr({multihash:t.toCID().multihash,publicKey:t});throw new ht}function Kc(t){return ri(t.publicKey)}function Fr(t){if(Jh(t))return new Nr({multihash:t});if(Wh(t))try{let e=Uc(t);if(e.type==="Ed25519")return new Or({multihash:t,publicKey:e});if(e.type==="secp256k1")return new Ur({multihash:t,publicKey:e})}catch{let r=z(t.digest);return new Fn(new URL(r))}throw new Qr("Supplied PeerID Multihash is invalid")}function Wh(t){return t.code===Be.code}function Jh(t){return t.code===pt.code}function It(t,e){let r={[Symbol.iterator]:()=>r,next:()=>{let n=t.next(),s=n.value;return n.done===!0||s==null?{done:!0,value:void 0}:{done:!1,value:e(s)}}};return r}function Kn(t){let e=Je(Y.decode(`z${t}`));return Fr(e)}var Kr=class{map;constructor(e){if(this.map=new Map,e!=null)for(let[r,n]of e.entries())this.map.set(r.toString(),{key:r,value:n})}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(e){return this.map.delete(e.toString())}entries(){return It(this.map.entries(),e=>[e[1].key,e[1].value])}forEach(e){this.map.forEach((r,n)=>{e(r.value,r.key,this)})}get(e){return this.map.get(e.toString())?.value}has(e){return this.map.has(e.toString())}set(e,r){this.map.set(e.toString(),{key:e,value:r})}keys(){return It(this.map.values(),e=>e.key)}values(){return It(this.map.values(),e=>e.value)}get size(){return this.map.size}};var Mr=class t{set;constructor(e){if(this.set=new Set,e!=null)for(let r of e)this.set.add(r.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(e){this.set.add(e.toString())}clear(){this.set.clear()}delete(e){this.set.delete(e.toString())}entries(){return It(this.set.entries(),e=>{let r=Kn(e[0]);return[r,r]})}forEach(e){this.set.forEach(r=>{let n=Kn(r);e(n,n,this)})}has(e){return this.set.has(e.toString())}values(){return It(this.set.values(),e=>Kn(e))}intersection(e){let r=new t;for(let n of e)this.has(n)&&r.add(n);return r}difference(e){let r=new t;for(let n of this)e.has(n)||r.add(n);return r}union(e){let r=new t;for(let n of e)r.add(n);for(let n of this)r.add(n);return r}};var ni=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},Mc=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function qr(t,e){let{milliseconds:r,fallback:n,message:s,customTimers:o={setTimeout,clearTimeout},signal:i}=e,a,c,f=new Promise((h,l)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(i?.aborted){l(Mc(i));return}if(i&&(c=()=>{l(Mc(i))},i.addEventListener("abort",c,{once:!0})),t.then(h,l),r===Number.POSITIVE_INFINITY)return;let d=new ni;a=o.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(p){l(p)}return}typeof t.cancel=="function"&&t.cancel(),s===!1?h():s instanceof Error?l(s):(d.message=s??`Promise timed out after ${r} milliseconds`,l(d))},r)}).finally(()=>{f.clear(),c&&i&&i.removeEventListener("abort",c)});return f.clear=()=>{o.clearTimeout.call(void 0,a),a=void 0},f}var Qh=t=>{let e=t.addEventListener||t.on||t.addListener,r=t.removeEventListener||t.off||t.removeListener;if(!e||!r)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(t),removeListener:r.bind(t)}};function ed(t,e,r){let n,s=new Promise((o,i)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[e].flat(),c=[],{addListener:u,removeListener:f}=Qh(t),h=async(...d)=>{let p=r.multiArgs?d:d[0];if(r.filter)try{if(!await r.filter(p))return}catch(g){n(),i(g);return}c.push(p),r.count===c.length&&(n(),o(c))},l=(...d)=>{n(),i(r.rejectionMultiArgs?d:d[0])};n=()=>{for(let d of a)f(d,h);for(let d of r.rejectionEvents)a.includes(d)||f(d,l)};for(let d of a)u(d,h);for(let d of r.rejectionEvents)a.includes(d)||u(d,l);r.signal&&r.signal.addEventListener("abort",()=>{l(r.signal.reason)},{once:!0}),r.resolveImmediately&&o(c)});if(s.cancel=n,typeof r.timeout=="number"){let o=qr(s,{milliseconds:r.timeout});return o.cancel=()=>{n(),o.clear()},o}return s}function qc(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=ed(t,e,r),s=n.then(o=>o[0]);return s.cancel=n.cancel,s}var Bt=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function td(t){return t.reason}async function oi(t,e,r){if(e==null)return t;let n=r?.translateError??td;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let s;try{return await Promise.race([t,new Promise((o,i)=>{s=()=>{i(n(e))},e.addEventListener("abort",s)})])}finally{s!=null&&e.removeEventListener("abort",s)}}var nd=4194304,Mn=class extends Error{static name="UnwrappedError";name="UnwrappedError"},ii=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},ai=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},ci=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function od(t){return typeof t?.closeRead=="function"}function sd(t){return typeof t?.close=="function"}function si(t){return od(t)?t.remoteWriteStatus!=="writable"&&t.readBufferLength===0:sd(t)?t.status!=="open":!1}function id(t){return t?.addEventListener!=null&&t?.removeEventListener!=null&&t?.send!=null&&t?.push!=null&&t?.log!=null}function ad(t,e){let r=e?.maxBufferSize??nd,n=new ae,s,o=!1;if(!id(t))throw new $("Argument should be a Stream or a Multiaddr");let i=f=>{if(n.append(f.data),n.byteLength>r){let h=n.byteLength;n.consume(n.byteLength),s?.reject(new Error(`Read buffer overflow - ${h} > ${r}`))}s?.resolve()};t.addEventListener("message",i);let a=f=>{f.error!=null?s?.reject(f.error):s?.resolve()};t.addEventListener("close",a);let c=()=>{s?.resolve()};t.addEventListener("remoteCloseWrite",c);let u={readBuffer:n,async read(f){if(o===!0)throw new Mn("Stream was unwrapped");if(si(t)){if(n.byteLength===0&&f?.bytes==null)return null;if(f?.bytes!=null&&n.byteLength<f.bytes)throw t.log.error("closed after reading %d/%d bytes",n.byteLength,f.bytes),new Bt(`Unexpected EOF - stream closed after reading ${n.byteLength}/${f.bytes} bytes`)}let h=f?.bytes??1;for(s=Promise.withResolvers();;){if(n.byteLength>=h){s.resolve();break}if(await oi(s.promise,f?.signal),si(t)){if(n.byteLength===0&&f?.bytes==null)return null;break}s=Promise.withResolvers()}let l=f?.bytes??n.byteLength;if(n.byteLength<l){if(si(t))throw t.log.error("closed while reading %d/%d bytes",n.byteLength,l),new Bt(`Unexpected EOF - stream closed while reading ${n.byteLength}/${l} bytes`);return u.read(f)}let d=n.sublist(0,l);return n.consume(l),d},async write(f,h){if(o===!0)throw new Mn("Stream was unwrapped");t.send(f)||await qc(t,"drain",{signal:h?.signal,rejectionEvents:["close"]})},unwrap(){return o||(o=!0,t.removeEventListener("message",i),t.removeEventListener("close",a),t.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(t.log("stream unwrapped with %d unread bytes",n.byteLength),t.unshift(n))),t}};return u}function cd(t,e={}){let r=ad(t,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=Ge(e.maxDataLength));let n=e?.lengthDecoder??Ka,s=e?.lengthEncoder??Fa;return{async read(i){let a=-1,c=new ae;for(;;){let f=await r.read({...i,bytes:1});if(f==null)break;c.append(f);try{a=n(c)}catch(h){if(h instanceof RangeError)continue;throw h}if(a<0)throw new ii("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new ci(`Message length length too long - ${c.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new ai(`Message length too long - ${a} > ${e.maxDataLength}`);let u=await r.read({...i,bytes:a});if(u==null)throw t.log.error("tried to read %d bytes but the stream closed",a),new Bt(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(u.byteLength!==a)throw t.log.error("read %d/%d bytes before the stream closed",u.byteLength,a),new Bt(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(i,a){await r.write(new ae(s(i.byteLength),i),a)},async writeV(i,a){let c=new ae(...i.flatMap(u=>[s(u.byteLength),u]));await r.write(c,a)},unwrap(){return r.unwrap()}}}function ui(t,e){let r=cd(t,e),n={read:async(s,o)=>{let i=await r.read(o);return s.decode(i)},write:async(s,o,i)=>{await r.write(o.encode(s),i)},writeV:async(s,o,i)=>{await r.writeV(s.map(a=>o.encode(a)),i)},pb:s=>({read:async o=>n.read(s,o),write:async(o,i)=>n.write(o,s,i),writeV:async(o,i)=>n.writeV(o,s,i),unwrap:()=>n}),unwrap:()=>r.unwrap()};return n}var li=nu(zc(),1);function hi(t,e,r){let n=0,s=t.length;for(;s>0;){let o=Math.trunc(s/2),i=n+o;r(t[i],e)<=0?(n=++i,s-=o+1):s=o}return n}var ld=100,tr=class{#e=[];#t=0;enqueue(e,r){let{priority:n=0,id:s}=r??{},{size:o}=this,i={priority:n,id:s,run:e};if(o===0){this.#e.length=0,this.#t=0,this.#e.push(i);return}if(this.#e.at(-1).priority>=n){this.#e.push(i);return}this.#s();let a=hi(this.#e,i,(c,u)=>u.priority-c.priority);this.#e.splice(a,0,i)}setPriority(e,r){let n=this.#e.findIndex((o,i)=>i>=this.#t&&o.id===e);if(n===-1)throw new ReferenceError(`No promise function with the id "${e}" exists in the queue.`);let[s]=this.#e.splice(n,1);this.enqueue(s.run,{priority:r,id:e})}remove(e){let r=this.#e.findIndex((n,s)=>s<this.#t?!1:typeof e=="string"?n.id===e:n.run===e);r!==-1&&this.#e.splice(r,1)}dequeue(){if(this.#t===this.#e.length)return;let e=this.#e[this.#t];return this.#t++,this.#t===this.#e.length?(this.#e.length=0,this.#t=0):this.#t>ld&&this.#t>this.#e.length/2&&this.#s(),e?.run}filter(e){let r=[];for(let n=this.#t;n<this.#e.length;n++){let s=this.#e[n];s.priority===e.priority&&r.push(s.run)}return r}get size(){return this.#e.length-this.#t}#s(){this.#t!==0&&(this.#e.splice(0,this.#t),this.#t=0)}};var zr=class extends li.default{#e;#t;#s=0;#d;#m=!1;#w=!1;#c;#T=0;#x=0;#u;#f;#a;#i=[];#o=0;#r;#L;#n=0;#b;#l;#R=1n;#y=new Map;#E=new Set;timeout;constructor(e){if(super(),e={carryoverIntervalCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:tr,strict:!1,...e},!(typeof e.intervalCap=="number"&&e.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${e.intervalCap?.toString()??""}\` (${typeof e.intervalCap})`);if(e.interval===void 0||!(Number.isFinite(e.interval)&&e.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${e.interval?.toString()??""}\` (${typeof e.interval})`);if(e.strict&&e.interval===0)throw new TypeError("The `strict` option requires a non-zero `interval`");if(e.strict&&e.intervalCap===Number.POSITIVE_INFINITY)throw new TypeError("The `strict` option requires a finite `intervalCap`");if(this.#e=e.carryoverIntervalCount??e.carryoverConcurrencyCount??!1,this.#t=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#d=e.intervalCap,this.#c=e.interval,this.#a=e.strict,this.#r=new e.queueClass,this.#L=e.queueClass,this.concurrency=e.concurrency,e.timeout!==void 0&&!(Number.isFinite(e.timeout)&&e.timeout>0))throw new TypeError(`Expected \`timeout\` to be a positive finite number, got \`${e.timeout}\` (${typeof e.timeout})`);this.timeout=e.timeout,this.#l=e.autoStart===!1,this.#q()}#v(e){for(;this.#o<this.#i.length;){let n=this.#i[this.#o];if(n!==void 0&&e-n>=this.#c)this.#o++;else break}(this.#o>100&&this.#o>this.#i.length/2||this.#o===this.#i.length)&&(this.#i=this.#i.slice(this.#o),this.#o=0)}#P(e){this.#a?this.#i.push(e):this.#s++}#N(){this.#a?this.#i.length>this.#o&&this.#i.pop():this.#s>0&&this.#s--}#S(){return this.#i.length-this.#o}get#O(){return this.#t?!0:this.#a?this.#S()<this.#d:this.#s<this.#d}get#U(){return this.#n<this.#b}#F(){this.#n--,this.#n===0&&this.emit("pendingZero"),this.#g(),this.emit("next")}#K(){this.#f=void 0,this.#k(),this.#_()}#M(e){if(this.#a){if(this.#v(e),this.#S()>=this.#d){let n=this.#i[this.#o],s=this.#c-(e-n);return this.#A(s),!0}return!1}if(this.#u===void 0){let r=this.#T-e;if(r<0){if(this.#x>0){let n=e-this.#x;if(n<this.#c)return this.#A(this.#c-n),!0}this.#s=this.#e?this.#n:0}else return this.#A(r),!0}return!1}#A(e){this.#f===void 0&&(this.#f=setTimeout(()=>{this.#K()},e))}#I(){this.#u&&(clearInterval(this.#u),this.#u=void 0)}#D(){this.#f&&(clearTimeout(this.#f),this.#f=void 0)}#g(){if(this.#r.size===0){if(this.#I(),this.emit("empty"),this.#n===0){if(this.#D(),this.#a&&this.#o>0){let r=Date.now();this.#v(r)}this.emit("idle")}return!1}let e=!1;if(!this.#l){let r=Date.now(),n=!this.#M(r);if(this.#O&&this.#U){let s=this.#r.dequeue();this.#t||(this.#P(r),this.#p()),this.emit("active"),s(),n&&this.#_(),e=!0}}return e}#_(){this.#t||this.#u!==void 0||this.#a||(this.#u=setInterval(()=>{this.#k()},this.#c),this.#T=Date.now()+this.#c)}#k(){this.#a||(this.#s===0&&this.#n===0&&this.#u&&this.#I(),this.#s=this.#e?this.#n:0),this.#B(),this.#p()}#B(){for(;this.#g(););}get concurrency(){return this.#b}set concurrency(e){if(!(typeof e=="number"&&e>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);this.#b=e,this.#B()}setPriority(e,r){if(typeof r!="number"||!Number.isFinite(r))throw new TypeError(`Expected \`priority\` to be a finite number, got \`${r}\` (${typeof r})`);this.#r.setPriority(e,r)}async add(e,r={}){return r={timeout:this.timeout,...r,id:r.id??(this.#R++).toString()},new Promise((n,s)=>{let o=Symbol(`task-${r.id}`),i=()=>{},a=async()=>{i(),this.#n++,this.#y.set(o,{id:r.id,priority:r.priority??0,startTime:Date.now(),timeout:r.timeout});let u;try{try{r.signal?.throwIfAborted()}catch(l){throw this.#V(),this.#y.delete(o),l}this.#x=Date.now();let f=e({signal:r.signal});if(r.timeout&&(f=qr(Promise.resolve(f),{milliseconds:r.timeout,message:`Task timed out after ${r.timeout}ms (queue has ${this.#n} running, ${this.#r.size} waiting)`})),r.signal){let{signal:l}=r;f=Promise.race([f,new Promise((d,p)=>{u=()=>{p(l.reason)},l.addEventListener("abort",u,{once:!0})})])}let h=await f;n(h),this.emit("completed",h)}catch(f){s(f),this.emit("error",f)}finally{u&&r.signal?.removeEventListener("abort",u),this.#y.delete(o),queueMicrotask(()=>{this.#F()})}};this.#r.enqueue(a,r);let c=()=>{if(this.#r instanceof tr){this.#r.remove(a);return}this.#r.remove?.(r.id)};if(r.signal){let{signal:u}=r,f=()=>{i(),c(),s(u.reason),this.#g(),this.emit("next")};if(i=()=>{u.removeEventListener("abort",f),this.#E.delete(i)},u.aborted){f();return}u.addEventListener("abort",f,{once:!0}),this.#E.add(i)}this.emit("add"),this.#g()})}async addAll(e,r){return Promise.all(e.map(async n=>this.add(n,r)))}start(){return this.#l?(this.#l=!1,this.#B(),this):this}pause(){this.#l=!0}clear(){for(let e of this.#E)e();this.#r=new this.#L,this.#I(),this.#C(),this.emit("empty"),this.#n===0&&(this.#D(),this.emit("idle")),this.emit("next")}async onEmpty(){this.#r.size!==0&&await this.#h("empty")}async onSizeLessThan(e){this.#r.size<e||await this.#h("next",()=>this.#r.size<e)}async onIdle(){this.#n===0&&this.#r.size===0||await this.#h("idle")}async onPendingZero(){this.#n!==0&&await this.#h("pendingZero")}async onRateLimit(){this.isRateLimited||await this.#h("rateLimit")}async onRateLimitCleared(){this.isRateLimited&&await this.#h("rateLimitCleared")}onError(){return new Promise((e,r)=>{let n=s=>{this.off("error",n),r(s)};this.on("error",n)})}async#h(e,r){return new Promise(n=>{let s=()=>{r&&!r()||(this.off(e,s),n())};this.on(e,s)})}get size(){return this.#r.size}sizeBy(e){return this.#r.filter(e).length}get pending(){return this.#n}get isPaused(){return this.#l}#q(){this.#t||(this.on("add",()=>{this.#r.size>0&&this.#p()}),this.on("next",()=>{this.#p()}))}#p(){this.#t||this.#w||(this.#w=!0,queueMicrotask(()=>{this.#w=!1,this.#C()}))}#V(){this.#t||(this.#N(),this.#p())}#C(){let e=this.#m;if(this.#t||this.#r.size===0){e&&(this.#m=!1,this.emit("rateLimitCleared"));return}let r;if(this.#a){let s=Date.now();this.#v(s),r=this.#S()}else r=this.#s;let n=r>=this.#d;n!==e&&(this.#m=n,this.emit(n?"rateLimit":"rateLimitCleared"))}get isRateLimited(){return this.#m}get isSaturated(){return this.#n===this.#b&&this.#r.size>0||this.isRateLimited&&this.#r.size>0}get runningTasks(){return[...this.#y.values()].map(e=>({...e,timeoutRemaining:e.timeout?Math.max(0,e.startTime+e.timeout-Date.now()):void 0}))}};var Vn=class{entries;validityMs;lastPruneTime=0;constructor(e){this.entries=new Map,this.validityMs=e.validityMs}put(e,r){this.entries.set(e,{value:r,validUntilMs:Date.now()+this.validityMs}),this.prune()}prune(){let e=Date.now();if(!(e-this.lastPruneTime<200)){this.lastPruneTime=e;for(let[r,n]of this.entries.entries())if(n.validUntilMs<e)this.entries.delete(r);else break}}has(e){return this.entries.has(e)}get(e){let r=this.entries.get(e);return r!=null&&r.validUntilMs>=Date.now()?r.value:void 0}clear(){this.entries=new Map,this.lastPruneTime=0}};var Tt;(function(t){let e;(function(a){let c;a.codec=()=>(c==null&&(c=Ee((l,d,p={})=>{p.lengthDelimited!==!1&&d.fork(),l.subscribe!=null&&(d.uint32(8),d.bool(l.subscribe)),l.topic!=null&&(d.uint32(18),d.string(l.topic)),p.lengthDelimited!==!1&&d.ldelim()},(l,d,p={})=>{let g={},b=d==null?l.len:l.pos+d;for(;l.pos<b;){let y=l.uint32();switch(y>>>3){case 1:{g.subscribe=l.bool();break}case 2:{g.topic=l.string();break}default:{l.skipType(y&7);break}}}return g},function*(l,d,p,g={}){let b=d==null?l.len:l.pos+d;for(;l.pos<b;){let y=l.uint32();switch(y>>>3){case 1:{yield{field:`${p}.subscribe`,value:l.bool()};break}case 2:{yield{field:`${p}.topic`,value:l.string()};break}default:{l.skipType(y&7);break}}}})),c);function u(l){return we(l,a.codec())}a.encode=u;function f(l,d){return ge(l,a.codec(),d)}a.decode=f;function h(l,d){return xe(l,a.codec(),d)}a.stream=h})(e=t.SubOpts||(t.SubOpts={}));let r;(function(a){let c;a.codec=()=>(c==null&&(c=Ee((l,d,p={})=>{p.lengthDelimited!==!1&&d.fork(),l.from!=null&&(d.uint32(10),d.bytes(l.from)),l.data!=null&&(d.uint32(18),d.bytes(l.data)),l.sequenceNumber!=null&&(d.uint32(26),d.bytes(l.sequenceNumber)),l.topic!=null&&(d.uint32(34),d.string(l.topic)),l.signature!=null&&(d.uint32(42),d.bytes(l.signature)),l.key!=null&&(d.uint32(50),d.bytes(l.key)),p.lengthDelimited!==!1&&d.ldelim()},(l,d,p={})=>{let g={},b=d==null?l.len:l.pos+d;for(;l.pos<b;){let y=l.uint32();switch(y>>>3){case 1:{g.from=l.bytes();break}case 2:{g.data=l.bytes();break}case 3:{g.sequenceNumber=l.bytes();break}case 4:{g.topic=l.string();break}case 5:{g.signature=l.bytes();break}case 6:{g.key=l.bytes();break}default:{l.skipType(y&7);break}}}return g},function*(l,d,p,g={}){let b=d==null?l.len:l.pos+d;for(;l.pos<b;){let y=l.uint32();switch(y>>>3){case 1:{yield{field:`${p}.from`,value:l.bytes()};break}case 2:{yield{field:`${p}.data`,value:l.bytes()};break}case 3:{yield{field:`${p}.sequenceNumber`,value:l.bytes()};break}case 4:{yield{field:`${p}.topic`,value:l.string()};break}case 5:{yield{field:`${p}.signature`,value:l.bytes()};break}case 6:{yield{field:`${p}.key`,value:l.bytes()};break}default:{l.skipType(y&7);break}}}})),c);function u(l){return we(l,a.codec())}a.encode=u;function f(l,d){return ge(l,a.codec(),d)}a.decode=f;function h(l,d){return xe(l,a.codec(),d)}a.stream=h})(r=t.Message||(t.Message={}));let n;t.codec=()=>(n==null&&(n=Ee((a,c,u={})=>{if(u.lengthDelimited!==!1&&c.fork(),a.subscriptions!=null&&a.subscriptions.length>0)for(let f of a.subscriptions)c.uint32(10),t.SubOpts.codec().encode(f,c);if(a.messages!=null&&a.messages.length>0)for(let f of a.messages)c.uint32(18),t.Message.codec().encode(f,c);a.control!=null&&(c.uint32(26),Hr.codec().encode(a.control,c)),u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={subscriptions:[],messages:[]},h=c==null?a.len:a.pos+c;for(;a.pos<h;){let l=a.uint32();switch(l>>>3){case 1:{if(u.limits?.subscriptions!=null&&f.subscriptions.length===u.limits.subscriptions)throw new re('Decode error - repeated field "subscriptions" had too many elements');f.subscriptions.push(t.SubOpts.codec().decode(a,a.uint32(),{limits:u.limits?.subscriptions$}));break}case 2:{if(u.limits?.messages!=null&&f.messages.length===u.limits.messages)throw new re('Decode error - repeated field "messages" had too many elements');f.messages.push(t.Message.codec().decode(a,a.uint32(),{limits:u.limits?.messages$}));break}case 3:{f.control=Hr.codec().decode(a,a.uint32(),{limits:u.limits?.control});break}default:{a.skipType(l&7);break}}}return f},function*(a,c,u,f={}){let h={subscriptions:0,messages:0},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let d=a.uint32();switch(d>>>3){case 1:{if(f.limits?.subscriptions!=null&&h.subscriptions===f.limits.subscriptions)throw new re('Streaming decode error - repeated field "subscriptions" had too many elements');for(let p of t.SubOpts.codec().stream(a,a.uint32(),`${u}.subscriptions[]`,{limits:f.limits?.subscriptions$}))yield{...p,index:h.subscriptions};h.subscriptions++;break}case 2:{if(f.limits?.messages!=null&&h.messages===f.limits.messages)throw new re('Streaming decode error - repeated field "messages" had too many elements');for(let p of t.Message.codec().stream(a,a.uint32(),`${u}.messages[]`,{limits:f.limits?.messages$}))yield{...p,index:h.messages};h.messages++;break}case 3:{yield*Hr.codec().stream(a,a.uint32(),`${u}.control`,{limits:f.limits?.control});break}default:{a.skipType(d&7);break}}}})),n);function s(a){return we(a,t.codec())}t.encode=s;function o(a,c){return ge(a,t.codec(),c)}t.decode=o;function i(a,c){return xe(a,t.codec(),c)}t.stream=i})(Tt||(Tt={}));var Hr;(function(t){let e;t.codec=()=>(e==null&&(e=Ee((o,i,a={})=>{if(a.lengthDelimited!==!1&&i.fork(),o.ihave!=null&&o.ihave.length>0)for(let c of o.ihave)i.uint32(10),$r.codec().encode(c,i);if(o.iwant!=null&&o.iwant.length>0)for(let c of o.iwant)i.uint32(18),jr.codec().encode(c,i);if(o.graft!=null&&o.graft.length>0)for(let c of o.graft)i.uint32(26),Zr.codec().encode(c,i);if(o.prune!=null&&o.prune.length>0)for(let c of o.prune)i.uint32(34),Yr.codec().encode(c,i);a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={ihave:[],iwant:[],graft:[],prune:[]},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{if(a.limits?.ihave!=null&&c.ihave.length===a.limits.ihave)throw new re('Decode error - repeated field "ihave" had too many elements');c.ihave.push($r.codec().decode(o,o.uint32(),{limits:a.limits?.ihave$}));break}case 2:{if(a.limits?.iwant!=null&&c.iwant.length===a.limits.iwant)throw new re('Decode error - repeated field "iwant" had too many elements');c.iwant.push(jr.codec().decode(o,o.uint32(),{limits:a.limits?.iwant$}));break}case 3:{if(a.limits?.graft!=null&&c.graft.length===a.limits.graft)throw new re('Decode error - repeated field "graft" had too many elements');c.graft.push(Zr.codec().decode(o,o.uint32(),{limits:a.limits?.graft$}));break}case 4:{if(a.limits?.prune!=null&&c.prune.length===a.limits.prune)throw new re('Decode error - repeated field "prune" had too many elements');c.prune.push(Yr.codec().decode(o,o.uint32(),{limits:a.limits?.prune$}));break}default:{o.skipType(f&7);break}}}return c},function*(o,i,a,c={}){let u={ihave:0,iwant:0,graft:0,prune:0},f=i==null?o.len:o.pos+i;for(;o.pos<f;){let h=o.uint32();switch(h>>>3){case 1:{if(c.limits?.ihave!=null&&u.ihave===c.limits.ihave)throw new re('Streaming decode error - repeated field "ihave" had too many elements');for(let l of $r.codec().stream(o,o.uint32(),`${a}.ihave[]`,{limits:c.limits?.ihave$}))yield{...l,index:u.ihave};u.ihave++;break}case 2:{if(c.limits?.iwant!=null&&u.iwant===c.limits.iwant)throw new re('Streaming decode error - repeated field "iwant" had too many elements');for(let l of jr.codec().stream(o,o.uint32(),`${a}.iwant[]`,{limits:c.limits?.iwant$}))yield{...l,index:u.iwant};u.iwant++;break}case 3:{if(c.limits?.graft!=null&&u.graft===c.limits.graft)throw new re('Streaming decode error - repeated field "graft" had too many elements');for(let l of Zr.codec().stream(o,o.uint32(),`${a}.graft[]`,{limits:c.limits?.graft$}))yield{...l,index:u.graft};u.graft++;break}case 4:{if(c.limits?.prune!=null&&u.prune===c.limits.prune)throw new re('Streaming decode error - repeated field "prune" had too many elements');for(let l of Yr.codec().stream(o,o.uint32(),`${a}.prune[]`,{limits:c.limits?.prune$}))yield{...l,index:u.prune};u.prune++;break}default:{o.skipType(h&7);break}}}})),e);function r(o){return we(o,t.codec())}t.encode=r;function n(o,i){return ge(o,t.codec(),i)}t.decode=n;function s(o,i){return xe(o,t.codec(),i)}t.stream=s})(Hr||(Hr={}));var $r;(function(t){let e;t.codec=()=>(e==null&&(e=Ee((o,i,a={})=>{if(a.lengthDelimited!==!1&&i.fork(),o.topic!=null&&(i.uint32(10),i.string(o.topic)),o.messageIDs!=null&&o.messageIDs.length>0)for(let c of o.messageIDs)i.uint32(18),i.bytes(c);a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={messageIDs:[]},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{c.topic=o.string();break}case 2:{if(a.limits?.messageIDs!=null&&c.messageIDs.length===a.limits.messageIDs)throw new re('Decode error - repeated field "messageIDs" had too many elements');c.messageIDs.push(o.bytes());break}default:{o.skipType(f&7);break}}}return c},function*(o,i,a,c={}){let u={messageIDs:0},f=i==null?o.len:o.pos+i;for(;o.pos<f;){let h=o.uint32();switch(h>>>3){case 1:{yield{field:`${a}.topic`,value:o.string()};break}case 2:{if(c.limits?.messageIDs!=null&&u.messageIDs===c.limits.messageIDs)throw new re('Streaming decode error - repeated field "messageIDs" had too many elements');yield{field:`${a}.messageIDs[]`,index:u.messageIDs,value:o.bytes()},u.messageIDs++;break}default:{o.skipType(h&7);break}}}})),e);function r(o){return we(o,t.codec())}t.encode=r;function n(o,i){return ge(o,t.codec(),i)}t.decode=n;function s(o,i){return xe(o,t.codec(),i)}t.stream=s})($r||($r={}));var jr;(function(t){let e;t.codec=()=>(e==null&&(e=Ee((o,i,a={})=>{if(a.lengthDelimited!==!1&&i.fork(),o.messageIDs!=null&&o.messageIDs.length>0)for(let c of o.messageIDs)i.uint32(10),i.bytes(c);a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={messageIDs:[]},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{if(a.limits?.messageIDs!=null&&c.messageIDs.length===a.limits.messageIDs)throw new re('Decode error - repeated field "messageIDs" had too many elements');c.messageIDs.push(o.bytes());break}default:{o.skipType(f&7);break}}}return c},function*(o,i,a,c={}){let u={messageIDs:0},f=i==null?o.len:o.pos+i;for(;o.pos<f;){let h=o.uint32();switch(h>>>3){case 1:{if(c.limits?.messageIDs!=null&&u.messageIDs===c.limits.messageIDs)throw new re('Streaming decode error - repeated field "messageIDs" had too many elements');yield{field:`${a}.messageIDs[]`,index:u.messageIDs,value:o.bytes()},u.messageIDs++;break}default:{o.skipType(h&7);break}}}})),e);function r(o){return we(o,t.codec())}t.encode=r;function n(o,i){return ge(o,t.codec(),i)}t.decode=n;function s(o,i){return xe(o,t.codec(),i)}t.stream=s})(jr||(jr={}));var Zr;(function(t){let e;t.codec=()=>(e==null&&(e=Ee((o,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),o.topic!=null&&(i.uint32(10),i.string(o.topic)),a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();f>>>3===1?c.topic=o.string():o.skipType(f&7)}return c},function*(o,i,a,c={}){let u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();f>>>3===1?yield{field:`${a}.topic`,value:o.string()}:o.skipType(f&7)}})),e);function r(o){return we(o,t.codec())}t.encode=r;function n(o,i){return ge(o,t.codec(),i)}t.decode=n;function s(o,i){return xe(o,t.codec(),i)}t.stream=s})(Zr||(Zr={}));var Yr;(function(t){let e;t.codec=()=>(e==null&&(e=Ee((o,i,a={})=>{if(a.lengthDelimited!==!1&&i.fork(),o.topic!=null&&(i.uint32(10),i.string(o.topic)),o.peers!=null&&o.peers.length>0)for(let c of o.peers)i.uint32(18),Gr.codec().encode(c,i);o.backoff!=null&&(i.uint32(24),i.uint64(o.backoff)),a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={peers:[]},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{c.topic=o.string();break}case 2:{if(a.limits?.peers!=null&&c.peers.length===a.limits.peers)throw new re('Decode error - repeated field "peers" had too many elements');c.peers.push(Gr.codec().decode(o,o.uint32(),{limits:a.limits?.peers$}));break}case 3:{c.backoff=o.uint64();break}default:{o.skipType(f&7);break}}}return c},function*(o,i,a,c={}){let u={peers:0},f=i==null?o.len:o.pos+i;for(;o.pos<f;){let h=o.uint32();switch(h>>>3){case 1:{yield{field:`${a}.topic`,value:o.string()};break}case 2:{if(c.limits?.peers!=null&&u.peers===c.limits.peers)throw new re('Streaming decode error - repeated field "peers" had too many elements');for(let l of Gr.codec().stream(o,o.uint32(),`${a}.peers[]`,{limits:c.limits?.peers$}))yield{...l,index:u.peers};u.peers++;break}case 3:{yield{field:`${a}.backoff`,value:o.uint64()};break}default:{o.skipType(h&7);break}}}})),e);function r(o){return we(o,t.codec())}t.encode=r;function n(o,i){return ge(o,t.codec(),i)}t.decode=n;function s(o,i){return xe(o,t.codec(),i)}t.stream=s})(Yr||(Yr={}));var Gr;(function(t){let e;t.codec=()=>(e==null&&(e=Ee((o,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),o.peerID!=null&&(i.uint32(10),i.bytes(o.peerID)),o.signedPeerRecord!=null&&(i.uint32(18),i.bytes(o.signedPeerRecord)),a.lengthDelimited!==!1&&i.ldelim()},(o,i,a={})=>{let c={},u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{c.peerID=o.bytes();break}case 2:{c.signedPeerRecord=o.bytes();break}default:{o.skipType(f&7);break}}}return c},function*(o,i,a,c={}){let u=i==null?o.len:o.pos+i;for(;o.pos<u;){let f=o.uint32();switch(f>>>3){case 1:{yield{field:`${a}.peerID`,value:o.bytes()};break}case 2:{yield{field:`${a}.signedPeerRecord`,value:o.bytes()};break}default:{o.skipType(f&7);break}}}})),e);function r(o){return we(o,t.codec())}t.encode=r;function n(o,i){return ge(o,t.codec(),i)}t.decode=n;function s(o,i){return xe(o,t.codec(),i)}t.stream=s})(Gr||(Gr={}));var zn=class extends _t{peerId;shutDownController;inboundPb;outboundPb;constructor(e){super(),this.peerId=e,this.shutDownController=new AbortController}attachInboundStream(e,r){this.inboundPb=ui(e,r).pb(Tt),Promise.resolve().then(async()=>{for(;;){if(this.inboundPb==null)return;let n=await this.inboundPb.read({signal:this.shutDownController.signal});this.safeDispatchEvent("message",{detail:n})}}).catch(n=>{this.inboundPb?.unwrap().unwrap().abort(n)})}attachOutboundStream(e,r){this.outboundPb=ui(e,r).pb(Tt)}write(e){this.outboundPb!=null&&this.outboundPb.write(e,{signal:this.shutDownController.signal}).catch(r=>{this.outboundPb?.unwrap().unwrap().abort(r)})}close(){this.shutDownController.abort(),Promise.all([this.inboundPb?.unwrap().unwrap().close().catch(e=>{this.inboundPb?.unwrap().unwrap().abort(e)}),this.outboundPb?.unwrap().unwrap().close().catch(e=>{this.inboundPb?.unwrap().unwrap().abort(e)})]).finally(()=>{this.safeDispatchEvent("close")})}};function Hc(){return BigInt(`0x${z(Pn(8),"base16")}`)}var $c=(t,e)=>{let r=j(e.toString(16).padStart(16,"0"),"base16"),n=ze(t),s=new Uint8Array(n.byteLength+r.length);return s.set(n,0),s.set(r,n.byteLength),s},jc=t=>pt.encode(t);var hd=async t=>{if(t.sequenceNumber==null||t.from==null||t.signature==null)return!1;let e=Fr(Je(t.from));if(e.publicKey!=null)return!0;if(t.key!=null){let r=t.key;return ri(ti(r)).equals(e)}return!1},Zc=async t=>{if(t.from==null)throw new ee("RPC message was missing from");if(!await hd(t))return{type:"unsigned",topic:t.topic??"",data:t.data??new Uint8Array(0)};let e=Fr(Je(t.from)),r=t.key??e.publicKey;if(r==null)throw new ee("RPC message was missing public key");return{type:"signed",from:e,topic:t.topic??"",sequenceNumber:pd(t.sequenceNumber??new Uint8Array(0)),data:t.data??new Uint8Array(0),signature:t.signature??new Uint8Array(0),key:r instanceof Uint8Array?ti(r):r}},Xr=t=>t.type==="signed"?{from:t.from.toMultihash().bytes,data:t.data,sequenceNumber:dd(t.sequenceNumber),topic:t.topic,signature:t.signature,key:t.key?ze(t.key):void 0}:{data:t.data,topic:t.topic},dd=t=>{let e=t.toString(16);return e.length%2!==0&&(e=`0${e}`),j(e,"base16")},pd=t=>BigInt(`0x${z(t,"base16")}`);var Yc=j("libp2p-pubsub:");async function Gc(t,e,r){let n={type:"signed",topic:e.topic,data:e.data,sequenceNumber:e.sequenceNumber,from:Kc(t)},s=In([Yc,r(Xr(n)).subarray()]);return n.signature=await t.sign(s),n.key=t.publicKey,n}async function Xc(t,e){if(t.type!=="signed")throw new Error('Message type must be "signed" to be verified');if(t.signature==null)throw new Error("Message must contain a signature to be verified");if(t.from==null)throw new Error("Message must contain a from property to be verified");let r=In([Yc,e({...Xr(t),signature:void 0,key:void 0}).subarray()]);return md(t).verify(r,t.signature)}function md(t){if(t.type!=="signed")throw new Error('Message type must be "signed" to have a public key');if(t.from==null)throw new Error("Could not get the public key from the originator id");if(t.key!=null)return t.key;if(t.from.publicKey!=null)return t.from.publicKey;throw new Error("Could not get the public key from the originator id")}var Hn=class extends _t{log;started;topics;subscriptions;peers;globalSignaturePolicy;canRelayMessage;emitSelf;topicValidators;queue;protocol;components;_registrarTopologyId;maxInboundStreams;maxOutboundStreams;seenCache;constructor(e,r){super(),this.log=e.logger.forComponent("libp2p:floodsub"),this.components=e,this.protocol=r.protocol??di,this.started=!1,this.topics=new Map,this.subscriptions=new Set,this.peers=new Kr,this.globalSignaturePolicy=r.globalSignaturePolicy==="StrictNoSign"?"StrictNoSign":"StrictSign",this.canRelayMessage=r.canRelayMessage??!0,this.emitSelf=r.emitSelf??!1,this.topicValidators=new Map,this.queue=new zr({concurrency:r.messageProcessingConcurrency??10}),this.maxInboundStreams=r.maxInboundStreams??1,this.maxOutboundStreams=r.maxOutboundStreams??1,this.seenCache=new Vn({validityMs:r?.seenTTL??3e4}),this._onIncomingStream=this._onIncomingStream.bind(this),this._onPeerConnected=this._onPeerConnected.bind(this),this._onPeerDisconnected=this._onPeerDisconnected.bind(this)}[or]=!0;[Symbol.toStringTag]="@libp2p/floodsub";[yi]=["@libp2p/pubsub"];[gi]=["@libp2p/identify"];async start(){this.started||(this.log("starting"),await this.components.registrar.handle(this.protocol,this._onIncomingStream,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this._registrarTopologyId=await this.components.registrar.register(this.protocol,{onConnect:this._onPeerConnected,onDisconnect:this._onPeerDisconnected}),this.log("started"),this.started=!0)}async stop(){if(!this.started)return;let e=this.components.registrar;this._registrarTopologyId!=null&&e.unregister(this._registrarTopologyId),await e.unhandle(this.protocol),this.log("stopping");for(let r of this.peers.values())r.close();this.peers.clear(),this.subscriptions=new Set,this.started=!1,this.log("stopped")}isStarted(){return this.started}_onIncomingStream(e,r){this.addPeer(r.remotePeer,e).attachInboundStream(e)}async _onPeerConnected(e,r){if(this.log("connected %p",e),r.streams.find(o=>o.direction==="outbound"&&o.protocol===this.protocol)){this.log("outbound pubsub stream already present on connection from %p",e);return}let n=await r.newStream(this.protocol);this.addPeer(e,n).attachOutboundStream(n),this.send(e,{subscriptions:Array.from(this.subscriptions).map(o=>o.toString()),subscribe:!0})}_onPeerDisconnected(e,r){this.log("connection ended %p",e),this._removePeer(e)}addPeer(e,r){let n=this.peers.get(e);if(n!=null)return n;this.log("new peer %p",e);let s=new zn(e);return this.peers.set(e,s),s.addEventListener("message",o=>{let i=o.detail,a=[];for(let c of i.messages??[]){if(c.from==null||c.data==null||c.topic==null){this.log("message from %p was missing from, data or topic fields, dropping",e);continue}a.push({from:c.from,data:c.data,topic:c.topic,sequenceNumber:c.sequenceNumber??void 0,signature:c.signature??void 0,key:c.key??void 0})}this.processRpc(s,{subscriptions:(i.subscriptions??[]).map(c=>({subscribe:!!c.subscribe,topic:c.topic??""})),messages:a}).catch(c=>{this.log(c)})}),s.addEventListener("close",()=>this._removePeer(e),{once:!0}),s}_removePeer(e){let r=this.peers.get(e);if(r!=null){r.close(),this.log("delete peer %p",e),this.peers.delete(e);for(let n of this.topics.values())n.delete(e)}}async processRpc(e,r){this.log("rpc from %p",e.peerId);let{subscriptions:n,messages:s}=r;return n!=null&&n.length>0&&(this.log("subscription update from %p",e.peerId),n.forEach(o=>{this.processRpcSubOpt(e.peerId,o)}),super.dispatchEvent(new CustomEvent("subscription-change",{detail:{peerId:e.peerId,subscriptions:n.map(({topic:o,subscribe:i})=>({topic:`${o??""}`,subscribe:!!i}))}}))),s!=null&&s.length>0&&(this.log("messages from %p",e.peerId),this.queue.addAll(s.map(o=>async()=>{if(o.topic==null||!this.subscriptions.has(o.topic)&&!this.canRelayMessage)return this.log("received message we didn't subscribe to. Dropping."),!1;try{let i=await Zc(o);await this.processMessage(e.peerId,i)}catch(i){this.log.error("failed to queue messages from %p - %e",e.peerId,i)}})).catch(o=>{this.log(o)})),!0}processRpcSubOpt(e,r){let n=r.topic;if(n==null)return;let s=this.topics.get(n);s==null&&(s=new Mr,this.topics.set(n,s)),r.subscribe===!0?s.add(e):s.delete(e)}async processMessage(e,r){if(this.components.peerId.equals(e)&&!this.emitSelf)return;let n=await this.getMsgId(r),s=z(n,"base64");if(!this.seenCache.has(s)){this.seenCache.put(s,!0);try{await this.validate(e,r)}catch(o){this.log("Message is invalid, dropping it. %O",o);return}this.subscriptions.has(r.topic)&&(!this.components.peerId.equals(e)||this.emitSelf)&&super.dispatchEvent(new CustomEvent("message",{detail:r})),await this.publishMessage(e,r)}}getMsgId(e){switch(this.globalSignaturePolicy){case"StrictSign":if(e.type!=="signed")throw new ee('Message type should be "signed" when signature policy is StrictSign but it was not');if(e.sequenceNumber==null)throw new ee("Need sequence number when signature policy is StrictSign but it was missing");if(e.key==null)throw new ee("Need key when signature policy is StrictSign but it was missing");return $c(e.key,e.sequenceNumber);case"StrictNoSign":return jc(e.data);default:throw new ee("Cannot get message id: unhandled signature policy")}}encodeMessage(e){return Tt.Message.encode(e)}send(e,r){let{messages:n,subscriptions:s,subscribe:o}=r;this.sendRpc(e,{subscriptions:(s??[]).map(i=>({topic:i,subscribe:!!o})),messages:(n??[]).map(Xr)})}sendRpc(e,r){let n=this.peers.get(e);if(n==null){this.log.error("cannot send RPC to %p as there are no streams to it available",e);return}n.write(r)}async validate(e,r){switch(this.globalSignaturePolicy){case"StrictNoSign":if(r.type!=="unsigned")throw new ee('Message type should be "unsigned" when signature policy is StrictNoSign but it was not');if(r.signature!=null)throw new ee("StrictNoSigning: signature should not be present");if(r.key!=null)throw new ee("StrictNoSigning: key should not be present");if(r.sequenceNumber!=null)throw new ee("StrictNoSigning: seqno should not be present");break;case"StrictSign":if(r.type!=="signed")throw new ee('Message type should be "signed" when signature policy is StrictSign but it was not');if(r.signature==null)throw new ee("StrictSigning: Signing required and no signature was present");if(r.sequenceNumber==null)throw new ee("StrictSigning: Signing required and no sequenceNumber was present");if(!await Xc(r,this.encodeMessage.bind(this)))throw new ee("StrictSigning: Invalid message signature");break;default:throw new ee("Cannot validate message: unhandled signature policy")}let s=this.topicValidators.get(r.topic);if(s!=null){let o=await s(e,r);if(o===rr.Reject||o===rr.Ignore)throw new ee("Message validation failed")}}async buildMessage(e){switch(this.globalSignaturePolicy){case"StrictSign":return Gc(this.components.privateKey,e,this.encodeMessage.bind(this));case"StrictNoSign":return Promise.resolve({type:"unsigned",...e});default:throw new ee("Cannot build message: unhandled signature policy")}}getSubscribers(e){if(!this.started)throw new en("not started yet");if(e==null)throw new $("Topic is required");let r=this.topics.get(e.toString());return r==null?[]:Array.from(r.values())}async publish(e,r){if(!this.started)throw new Error("Pubsub has not started");let n={from:this.components.peerId,topic:e,data:r??new Uint8Array(0),sequenceNumber:Hc()};this.log("publish topic: %s from: %p data: %m",e,n.from,n.data);let s=await this.buildMessage(n),o=!1;this.emitSelf&&this.subscriptions.has(e)&&(o=!0,super.dispatchEvent(new CustomEvent("message",{detail:s})));let i=await this.publishMessage(this.components.peerId,s);return o&&(i.recipients=[...i.recipients,this.components.peerId]),i}async publishMessage(e,r){let n=this.getSubscribers(r.topic),s=[];return n==null||n.length===0?(this.log("no peers are subscribed to topic %s",r.topic),{recipients:s}):(n.forEach(o=>{if(this.components.peerId.equals(o)){this.log("not sending message on topic %s to myself",r.topic);return}if(o.equals(e)){this.log("not sending message on topic %s to sender %p",r.topic,o);return}this.log("publish msgs on topics %s %p",r.topic,o),s.push(o),this.send(o,{messages:[r]})}),{recipients:s})}subscribe(e){if(!this.started)throw new Error("Pubsub has not started");if(!this.subscriptions.has(e)){this.log("subscribe to topic: %s",e),this.subscriptions.add(e);for(let r of this.peers.keys())this.send(r,{subscriptions:[e],subscribe:!0})}}unsubscribe(e){if(!this.started)throw new Error("Pubsub is not started");if(this.subscriptions.has(e)){this.log("unsubscribe from %s",e),this.subscriptions.delete(e);for(let r of this.peers.keys())this.send(r,{subscriptions:[e],subscribe:!1})}}getTopics(){if(!this.started)throw new Error("Pubsub is not started");return Array.from(this.subscriptions)}getPeers(){if(!this.started)throw new Error("Pubsub is not started");return Array.from(this.peers.keys())}};var di="/floodsub/1.0.0",bd="StrictSign",yd="StrictNoSign",rr;(function(t){t.Accept="accept",t.Ignore="ignore",t.Reject="reject"})(rr||(rr={}));function gd(t){return!!t?.[or]}function wd(t={}){return e=>new Hn(e,t)}return ou(xd);})();
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
@noble/curves/utils.js:
|