@libp2p/floodsub 11.0.24 → 11.0.25-4bb8fbe8d

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,5 +1,5 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PFloodsub = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PFloodsub=(()=>{var Fa=Object.create;var Nr=Object.defineProperty;var Na=Object.getOwnPropertyDescriptor;var Ka=Object.getOwnPropertyNames;var Ua=Object.getPrototypeOf,Ma=Object.prototype.hasOwnProperty;var qa=(t,e)=>()=>{try{return e||t((e={exports:{}}).exports,e),e.exports}catch(r){throw e=0,r}},me=(t,e)=>{for(var r in e)Nr(t,r,{get:e[r],enumerable:!0})},Ii=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Ka(e))!Ma.call(t,i)&&i!==r&&Nr(t,i,{get:()=>e[i],enumerable:!(n=Na(e,i))||n.enumerable});return t};var Va=(t,e,r)=>(r=t!=null?Fa(Ua(t)):{},Ii(e||!t||!t.__esModule?Nr(r,"default",{value:t,enumerable:!0}):r,t)),Ha=t=>Ii(Nr({},"__esModule",{value:!0}),t);var La=qa((sy,wi)=>{"use strict";var Uf=Object.prototype.hasOwnProperty,de="~";function Tr(){}Object.create&&(Tr.prototype=Object.create(null),new Tr().__proto__||(de=!1));function Mf(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function Ta(t,e,r,n,i){if(typeof r!="function")throw new TypeError("The listener must be a function");var s=new Mf(r,n||t,i),o=de?de+e:e;return t._events[o]?t._events[o].fn?t._events[o]=[t._events[o],s]:t._events[o].push(s):(t._events[o]=s,t._eventsCount++),t}function xn(t,e){--t._eventsCount===0?t._events=new Tr:delete t._events[e]}function he(){this._events=new Tr,this._eventsCount=0}he.prototype.eventNames=function(){var e=[],r,n;if(this._eventsCount===0)return e;for(n in r=this._events)Uf.call(r,n)&&e.push(de?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(r)):e};he.prototype.listeners=function(e){var r=de?de+e:e,n=this._events[r];if(!n)return[];if(n.fn)return[n.fn];for(var i=0,s=n.length,o=new Array(s);i<s;i++)o[i]=n[i].fn;return o};he.prototype.listenerCount=function(e){var r=de?de+e:e,n=this._events[r];return n?n.fn?1:n.length:0};he.prototype.emit=function(e,r,n,i,s,o){var a=de?de+e:e;if(!this._events[a])return!1;var c=this._events[a],u=arguments.length,f,l;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,i),!0;case 5:return c.fn.call(c.context,r,n,i,s),!0;case 6:return c.fn.call(c.context,r,n,i,s,o),!0}for(l=1,f=new Array(u-1);l<u;l++)f[l-1]=arguments[l];c.fn.apply(c.context,f)}else{var h=c.length,d;for(l=0;l<h;l++)switch(c[l].once&&this.removeListener(e,c[l].fn,void 0,!0),u){case 1:c[l].fn.call(c[l].context);break;case 2:c[l].fn.call(c[l].context,r);break;case 3:c[l].fn.call(c[l].context,r,n);break;case 4:c[l].fn.call(c[l].context,r,n,i);break;default:if(!f)for(d=1,f=new Array(u-1);d<u;d++)f[d-1]=arguments[d];c[l].fn.apply(c[l].context,f)}}return!0};he.prototype.on=function(e,r,n){return Ta(this,e,r,n,!1)};he.prototype.once=function(e,r,n){return Ta(this,e,r,n,!0)};he.prototype.removeListener=function(e,r,n,i){var s=de?de+e:e;if(!this._events[s])return this;if(!r)return xn(this,s),this;var o=this._events[s];if(o.fn)o.fn===r&&(!i||o.once)&&(!n||o.context===n)&&xn(this,s);else{for(var a=0,c=[],u=o.length;a<u;a++)(o[a].fn!==r||i&&!o[a].once||n&&o[a].context!==n)&&c.push(o[a]);c.length?this._events[s]=c.length===1?c[0]:c:xn(this,s)}return this};he.prototype.removeAllListeners=function(e){var r;return e?(r=de?de+e:e,this._events[r]&&xn(this,r)):(this._events=new Tr,this._eventsCount=0),this};he.prototype.off=he.prototype.removeListener;he.prototype.addListener=he.prototype.on;he.prefixed=de;he.EventEmitter=he;typeof wi<"u"&&(wi.exports=he)});var Xf={};me(Xf,{StrictNoSign:()=>Zf,StrictSign:()=>jf,TopicValidatorResult:()=>Zt,floodsub:()=>Gf,isPubSub:()=>Yf,protocol:()=>vi,pubSubSymbol:()=>Gt});var Gt=Symbol.for("@libp2p/pubsub");var j=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},Bt=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var Kr=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var J=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var Ur=class extends Error{static name="NotStartedError";constructor(e="Not started"){super(e),this.name="NotStartedError"}};var ut=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var An=Symbol.for("@libp2p/peer-id");function za(t){return typeof t?.handleEvent=="function"}function $a(t){return(t!==!0&&t!==!1&&t?.once)??!1}var Tt=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 i=$a(n);super.addEventListener(e,o=>{if(i){let a=this.#e.get(o.type);a!=null&&(a=a.filter(({callback:c})=>c!==r),this.#e.set(o.type,a))}za(r)?r.handleEvent(o):r(o)},n);let s=this.#e.get(e);s==null&&(s=[],this.#e.set(e,s)),s.push({callback:r,once:i})}removeEventListener(e,r,n){super.removeEventListener(e.toString(),r??null,n);let i=this.#e.get(e);i!=null&&(i=i.filter(({callback:s})=>s!==r),this.#e.set(e,i))}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};var Bi=Symbol.for("@libp2p/service-capabilities"),Ti=Symbol.for("@libp2p/service-dependencies");var _n={};me(_n,{base58btc:()=>Z,base58flickr:()=>Qa});var Tl=new Uint8Array(0);function Li(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 Ue(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return ft(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return ft(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function _i(t){return new TextEncoder().encode(t)}function Di(t){return new TextDecoder().decode(t)}function ja(t){return t?.buffer instanceof ArrayBuffer}function ft(t){return ja(t)?t:t.slice()}function Za(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 i=0;i<t.length;i++){var s=t.charAt(i),o=s.charCodeAt(0);if(r[o]!==255)throw new TypeError(s+" is ambiguous");r[o]=i}var a=t.length,c=t.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function l(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var x=0,y=0,b=0,S=m.length;b!==S&&m[b]===0;)b++,x++;for(var I=(S-b)*f+1>>>0,k=new Uint8Array(I);b!==S;){for(var _=m[b],P=0,R=I-1;(_!==0||P<y)&&R!==-1;R--,P++)_+=256*k[R]>>>0,k[R]=_%a>>>0,_=_/a>>>0;if(_!==0)throw new Error("Non-zero carry");y=P,b++}for(var T=I-y;T!==I&&k[T]===0;)T++;for(var O=c.repeat(x);T<I;++T)O+=t.charAt(k[T]);return O}function h(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var x=0;if(m[x]!==" "){for(var y=0,b=0;m[x]===c;)y++,x++;for(var S=(m.length-x)*u+1>>>0,I=new Uint8Array(S);m[x];){var k=r[m.charCodeAt(x)];if(k===255)return;for(var _=0,P=S-1;(k!==0||_<b)&&P!==-1;P--,_++)k+=a*I[P]>>>0,I[P]=k%256>>>0,k=k/256>>>0;if(k!==0)throw new Error("Non-zero carry");b=_,x++}if(m[x]!==" "){for(var R=S-b;R!==S&&I[R]===0;)R++;for(var T=new Uint8Array(y+(S-R)),O=y;R!==S;)T[O++]=I[R++];return T}}}function d(m){var x=h(m);if(x)return x;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:h,decode:d}}var Ya=Za,Ga=Ya,Ri=Ga;var In=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")}},Bn=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let i=r.codePointAt(0);if(i===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=i,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 Ci(this,e)}},Tn=class{decoders;constructor(e){this.decoders=e}or(e){return Ci(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 Ci(t,e){return new Tn({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Ln=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,i){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=i,this.encoder=new In(e,r,n),this.decoder=new Bn(e,r,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Lt({name:t,prefix:e,encode:r,decode:n}){return new Ln(t,e,r,n)}function Ge({name:t,prefix:e,alphabet:r}){let{encode:n,decode:i}=Ri(r,t);return Lt({prefix:e,name:t,encode:n,decode:s=>Ue(i(s))})}function Xa(t,e,r,n){let i=t.length;for(;t[i-1]==="=";)--i;let s=new Uint8Array(i*r/8|0),o=0,a=0,c=0;for(let u=0;u<i;++u){let f=e[t[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,o+=r,o>=8&&(o-=8,s[c++]=255&a>>o)}if(o>=r||(255&a<<8-o)!==0)throw new SyntaxError("Unexpected end of data");return s}function Wa(t,e,r){let n=e[e.length-1]==="=",i=(1<<r)-1,s="",o=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],o+=8;o>r;)o-=r,s+=e[i&a>>o];if(o!==0&&(s+=e[i&a<<r-o]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function Ja(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function G({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let i=Ja(n);return Lt({prefix:e,name:t,encode(s){return Wa(s,n,r)},decode(s){return Xa(s,i,r,t)}})}var Z=Ge({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Qa=Ge({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Dn={};me(Dn,{base32:()=>_t,base32hex:()=>nc,base32hexpad:()=>ic,base32hexpadupper:()=>oc,base32hexupper:()=>sc,base32pad:()=>tc,base32padupper:()=>rc,base32upper:()=>ec,base32z:()=>ac});var _t=G({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),ec=G({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),tc=G({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),rc=G({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),nc=G({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),sc=G({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ic=G({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),oc=G({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ac=G({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var kn={};me(kn,{base36:()=>Xt,base36upper:()=>cc});var Xt=Ge({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),cc=Ge({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var uc=Fi,Pi=128,fc=127,lc=~fc,hc=Math.pow(2,31);function Fi(t,e,r){e=e||[],r=r||0;for(var n=r;t>=hc;)e[r++]=t&255|Pi,t/=128;for(;t&lc;)e[r++]=t&255|Pi,t>>>=7;return e[r]=t|0,Fi.bytes=r-n+1,e}var dc=Rn,pc=128,Oi=127;function Rn(t,n){var r=0,n=n||0,i=0,s=n,o,a=t.length;do{if(s>=a)throw Rn.bytes=0,new RangeError("Could not decode varint");o=t[s++],r+=i<28?(o&Oi)<<i:(o&Oi)*Math.pow(2,i),i+=7}while(o>=pc);return Rn.bytes=s-n,r}var mc=Math.pow(2,7),yc=Math.pow(2,14),bc=Math.pow(2,21),gc=Math.pow(2,28),wc=Math.pow(2,35),xc=Math.pow(2,42),Ec=Math.pow(2,49),vc=Math.pow(2,56),Sc=Math.pow(2,63),Ac=function(t){return t<mc?1:t<yc?2:t<bc?3:t<gc?4:t<wc?5:t<xc?6:t<Ec?7:t<vc?8:t<Sc?9:10},Ic={encode:uc,decode:dc,encodingLength:Ac},Bc=Ic,Wt=Bc;function Jt(t,e=0){return[Wt.decode(t,e),Wt.decode.bytes]}function Dt(t,e,r=0){return Wt.encode(t,e,r),e}function kt(t){return Wt.encodingLength(t)}function Pe(t,e){let r=e.byteLength,n=kt(t),i=n+kt(r),s=new Uint8Array(i+r);return Dt(t,s,0),Dt(r,s,n),s.set(e,i),new Rt(t,r,e,s)}function Xe(t){let e=Ue(t),[r,n]=Jt(e),[i,s]=Jt(e.subarray(n)),o=e.subarray(n+s);if(o.byteLength!==i)throw new Error("Incorrect length");return new Rt(r,i,o,e)}function Ni(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&Li(t.bytes,r.bytes)}}var Rt=class{code;size;digest;bytes;constructor(e,r,n,i){this.code=e,this.size=r,this.digest=ft(n),this.bytes=ft(i)}};function Ki(t,e){let{bytes:r,version:n}=t;return n===0?Lc(r,Cn(t),e??Z.encoder):_c(r,Cn(t),e??_t.encoder)}var Ui=new WeakMap;function Cn(t){let e=Ui.get(t);if(e==null){let r=new Map;return Ui.set(t,r),r}return e}var ue=class t{code;version;multihash;bytes;"/";constructor(e,r,n,i){this.code=r,this.version=e,this.multihash=n,this.bytes=ft(i),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!==Qt)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Dc)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=Pe(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&&Ni(e.multihash,n.multihash)}toString(e){return Ki(this,e)}toJSON(){return{"/":Ki(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:i,multihash:s,bytes:o}=r;return new t(n,i,s,o??Mi(n,i,s.bytes))}else if(r[kc]===!0){let{version:n,multihash:i,code:s}=r,o=Xe(i);return t.create(n,s,o)}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!==Qt)throw new Error(`Version 0 CID must use dag-pb (code: ${Qt}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let i=Mi(e,r,n.bytes);return new t(e,r,n,i)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,Qt,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,i=Ue(e.subarray(n,n+r.multihashSize));if(i.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=i.subarray(r.multihashSize-r.digestSize),o=new Rt(r.multihashCode,r.digestSize,s,i);return[r.version===0?t.createV0(o):t.createV1(r.codec,o),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[l,h]=Jt(e.subarray(r));return r+=h,l},i=n(),s=Qt;if(i===18?(i=0,r=0):s=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let o=r,a=n(),c=n(),u=r+c,f=u-o;return{version:i,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(e,r){let[n,i]=Tc(e,r),s=t.decode(i);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Cn(s).set(n,e),s}};function Tc(t,e){switch(t[0]){case"Q":{let r=e??Z;return[Z.prefix,r.decode(`${Z.prefix}${t}`)]}case Z.prefix:{let r=e??Z;return[Z.prefix,r.decode(t)]}case _t.prefix:{let r=e??_t;return[_t.prefix,r.decode(t)]}case Xt.prefix:{let r=e??Xt;return[Xt.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 Lc(t,e,r){let{prefix:n}=r;if(n!==Z.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let i=e.get(n);if(i==null){let s=r.encode(t).slice(1);return e.set(n,s),s}else return i}function _c(t,e,r){let{prefix:n}=r,i=e.get(n);if(i==null){let s=r.encode(t);return e.set(n,s),s}else return i}var Qt=112,Dc=18;function Mi(t,e,r){let n=kt(t),i=n+kt(e),s=new Uint8Array(i+r.byteLength);return Dt(t,s,0),Dt(e,s,n),s.set(r,i),s}var kc=Symbol.for("@ipld/js-cid/CID");var Pn={};me(Pn,{identity:()=>Te});var qi=0,Rc="identity",Vi=Ue;function Cc(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 Pe(qi,Vi(t))}var Te={code:qi,name:Rc,encode:Vi,digest:Cc};function ye(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 Pc(t){return t.buffer instanceof ArrayBuffer}function Ie(t){return Pc(t)?t:t.slice()}async function Hi(t,e,r,n){let i=await crypto.subtle.importKey("jwk",t,{name:"ECDSA",namedCurve:t.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},i,Ie(e),Ie(r.subarray()));return n?.signal?.throwIfAborted(),s}function Me(t=0){return new Uint8Array(t)}function be(t=0){return new Uint8Array(t)}function Oc(t){return t?.buffer instanceof ArrayBuffer}function zi(t){if(Oc(t))return t;let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function lt(t,e){e==null&&(e=t.reduce((i,s)=>i+s.length,0));let r=be(e),n=0;for(let i of t)r.set(i,n),n+=i.length;return zi(r)}var ji=Symbol.for("@achingbrain/uint8arraylist");function $i(t,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let r=0;for(let n of t){let i=r+n.byteLength;if(e<i)return{buf:n,index:e-r};r=i}throw new RangeError("index is out of bounds")}function qr(t){return!!t?.[ji]}var ie=class t{bufs;length;[ji]=!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(qr(n)){r+=n.byteLength;for(let i of n.bufs)this.bufs.push(i)}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(qr(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=$i(this.bufs,e);return r.buf[r.index]}set(e,r){let n=$i(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(qr(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:i}=this._subList(e,r);return lt(n,i)}subarray(e,r){let{bufs:n,length:i}=this._subList(e,r);return n.length===1?n[0]:lt(n,i)}sublist(e,r){let{bufs:n,length:i}=this._subList(e,r),s=new t;return s.length=i,s.bufs=n,s}_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=[],i=0;for(let s=0;s<this.bufs.length;s++){let o=this.bufs[s],a=i,c=a+o.byteLength;if(i=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(o);break}let l=e-a;n.push(o.subarray(l,l+(r-e)));break}if(u){if(e===0){n.push(o);continue}n.push(o.subarray(e-a));continue}if(f){if(r===c){n.push(o);break}n.push(o.subarray(0,r-a));break}n.push(o)}return{bufs:n,length:r-e}}indexOf(e,r=0){if(!qr(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(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 i=n.byteLength;if(i===0)throw new TypeError("search must be at least 1 byte long");let s=256,o=new Int32Array(s);for(let l=0;l<s;l++)o[l]=-1;for(let l=0;l<i;l++)o[n[l]]=l;let a=o,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=r;l<=c;l+=f){f=0;for(let h=u;h>=0;h--){let d=this.get(l+h);if(n[h]!==d){f=Math.max(1,h-a[d]);break}}if(f===0)return l}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=be(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 i=Me(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt16(0,r,n),this.write(i,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 i=Me(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt32(0,r,n),this.write(i,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 i=Me(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigInt64(0,r,n),this.write(i,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=be(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 i=Me(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint16(0,r,n),this.write(i,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 i=Me(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint32(0,r,n),this.write(i,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 i=Me(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigUint64(0,r,n),this.write(i,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 i=Me(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat32(0,r,n),this.write(i,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 i=Me(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat64(0,r,n),this.write(i,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(!ye(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((i,s)=>i+s.byteLength,0)),n.length=r,n}};var On={};me(On,{base10:()=>Fc});var Fc=Ge({prefix:"9",name:"base10",alphabet:"0123456789"});var Fn={};me(Fn,{base16:()=>Nc,base16upper:()=>Kc});var Nc=G({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Kc=G({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Nn={};me(Nn,{base2:()=>Uc});var Uc=G({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Kn={};me(Kn,{base256emoji:()=>zc});var Zi=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}"),Mc=Zi.reduce((t,e,r)=>(t[r]=e,t),[]),qc=Zi.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function Vc(t){return t.reduce((e,r)=>(e+=Mc[r],e),"")}function Hc(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let i=qc[n];if(i==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(i)}return new Uint8Array(e)}var zc=Lt({prefix:"\u{1F680}",name:"base256emoji",encode:Vc,decode:Hc});var Un={};me(Un,{base64:()=>$c,base64pad:()=>jc,base64url:()=>Zc,base64urlpad:()=>Yc});var $c=G({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),jc=G({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Zc=G({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Yc=G({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Mn={};me(Mn,{base8:()=>Gc});var Gc=G({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var qn={};me(qn,{identity:()=>Xc});var Xc=Lt({prefix:"\0",name:"identity",encode:t=>Di(t),decode:t=>_i(t)});var hh=new TextEncoder,dh=new TextDecoder;var zn={};me(zn,{sha256:()=>ht,sha512:()=>eu});var Qc=20;function Hn({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:i}){return new Vn(t,e,r,n,i)}var Vn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,i,s){this.name=e,this.code=r,this.encode=n,this.minDigestLength=i??Qc,this.maxDigestLength=s}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?Yi(n,this.code,r?.truncate):n.then(i=>Yi(i,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Yi(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 Pe(e,t)}function Xi(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var ht=Hn({name:"sha2-256",code:18,encode:Xi("SHA-256")}),eu=Hn({name:"sha2-512",code:19,encode:Xi("SHA-512")});var $n={...qn,...Nn,...Mn,...On,...Fn,...Dn,...kn,..._n,...Un,...Kn},Ih={...zn,...Pn};function Ji(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Wi=Ji("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),jn=Ji("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=be(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),tu={utf8:Wi,"utf-8":Wi,hex:$n.base16,latin1:jn,ascii:jn,binary:jn,...$n},Vr=tu;function z(t,e="utf8"){let r=Vr[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function H(t,e="utf8"){let r=Vr[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var ru=parseInt("11111",2),Zn=parseInt("10000000",2),nu=parseInt("01111111",2),Qi={0:er,1:er,2:su,3:au,4:cu,5:ou,6:iu,16:er,22:er,48:er};function qe(t,e={offset:0}){let r=t[e.offset]&ru;if(e.offset++,Qi[r]!=null)return Qi[r](t,e);throw new Error("No decoder for tag "+r)}function tr(t,e){let r=0;if((t[e.offset]&Zn)===Zn){let n=t[e.offset]&nu,i="0x";e.offset++;for(let s=0;s<n;s++,e.offset++)i+=t[e.offset].toString(16).padStart(2,"0");r=parseInt(i,16)}else r=t[e.offset],e.offset++;return r}function er(t,e){tr(t,e);let r=[];for(;!(e.offset>=t.byteLength);){let n=qe(t,e);if(n===null)break;r.push(n)}return r}function su(t,e){let r=tr(t,e),n=e.offset,i=e.offset+r,s=[];for(let o=n;o<i;o++)o===n&&t[o]===0||s.push(t[o]);return e.offset+=r,Uint8Array.from(s)}function iu(t,e){let r=tr(t,e),n=e.offset+r,i=t[e.offset];e.offset++;let s=0,o=0;i<40?(s=0,o=i):i<80?(s=1,o=i-40):(s=2,o=i-80);let a=`${s}.${o}`,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 l=0;l<c.length;l++)f+=c[l]<<l*7;a+=`.${f}`,c=[]}}return a}function ou(t,e){return e.offset++,null}function au(t,e){let r=tr(t,e),n=t[e.offset];e.offset++;let i=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 i}function cu(t,e){let r=tr(t,e),n=t.subarray(e.offset,e.offset+r);return e.offset+=r,n}function uu(t){let e=t.toString(16);e.length%2===1&&(e="0"+e);let r=new ie;for(let n=0;n<e.length;n+=2)r.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return r}function Yn(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=uu(t.byteLength);return new ie(Uint8Array.from([e.byteLength|Zn]),e)}function ge(t){let e=new ie,r=128;return(t.subarray()[0]&r)===r&&e.append(Uint8Array.from([0])),e.append(t),new ie(Uint8Array.from([2]),Yn(e),e)}function Hr(t){let e=Uint8Array.from([0]),r=new ie(e,t);return new ie(Uint8Array.from([3]),Yn(r),r)}function Je(t,e=48){let r=new ie;for(let n of t)r.append(n);return new ie(Uint8Array.from([e]),Yn(r),r)}var fu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),lu=Uint8Array.from([6,5,43,129,4,0,34]),hu=Uint8Array.from([6,5,43,129,4,0,35]),du={ext:!0,kty:"EC",crv:"P-256"},pu={ext:!0,kty:"EC",crv:"P-384"},mu={ext:!0,kty:"EC",crv:"P-521"},Gn=32,Xn=48,Wn=66;function Jn(t){let e=qe(t);return eo(e)}function eo(t){let e=t[1][1][0],r=1,n,i;if(e.byteLength===Gn*2+1)return n=H(e.subarray(r,r+Gn),"base64url"),i=H(e.subarray(r+Gn),"base64url"),new Ct({...du,key_ops:["verify"],x:n,y:i});if(e.byteLength===Xn*2+1)return n=H(e.subarray(r,r+Xn),"base64url"),i=H(e.subarray(r+Xn),"base64url"),new Ct({...pu,key_ops:["verify"],x:n,y:i});if(e.byteLength===Wn*2+1)return n=H(e.subarray(r,r+Wn),"base64url"),i=H(e.subarray(r+Wn),"base64url"),new Ct({...mu,key_ops:["verify"],x:n,y:i});throw new j(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function to(t){return Je([ge(Uint8Array.from([1])),Je([yu(t.crv)],160),Je([Hr(new ie(Uint8Array.from([4]),z(t.x??"","base64url"),z(t.y??"","base64url")))],161)]).subarray()}function yu(t){if(t==="P-256")return fu;if(t==="P-384")return lu;if(t==="P-521")return hu;throw new j(`Invalid curve ${t}`)}var Ct=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=to(this.jwk)),this._raw}toMultihash(){return Te.digest(Ve(this))}toCID(){return ue.createV1(114,this.toMultihash())}toString(){return Z.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ye(this.raw,e.raw)}async verify(e,r,n){return Hi(this.jwk,r,e,n)}};function Qn(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}function Qe(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 Se(t,e,r=""){let n=Qn(t),i=t?.length,s=e!==void 0;if(!n||s&&i!==e){let o=r&&`"${r}" `,a=s?` of length ${e}`:"",c=n?`length=${i}`:`type=${typeof t}`,u=o+"expected Uint8Array"+a+", got "+c;throw n?new RangeError(u):new TypeError(u)}return t}function zr(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(Qe(t.outputLen),Qe(t.blockLen),t.outputLen<1)throw new Error('"outputLen" must be >= 1');if(t.blockLen<1)throw new Error('"blockLen" must be >= 1')}function Pt(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 $r(t,e){Se(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 ze(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function jr(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Le(t,e){return t<<32-e|t>>>e}var no=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",bu=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Zr(t){if(Se(t),no)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=bu[t[r]];return e}var He={_0:48,_9:57,A:65,F:70,a:97,f:102};function ro(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 rr(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(no)try{return Uint8Array.fromHex(t)}catch(i){throw i instanceof SyntaxError?new RangeError(i.message):i}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 i=0,s=0;i<r;i++,s+=2){let o=ro(t.charCodeAt(s)),a=ro(t.charCodeAt(s+1));if(o===void 0||a===void 0){let c=t[s]+t[s+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+s)}n[i]=o*16+a}return n}function es(...t){let e=0;for(let n=0;n<t.length;n++){let i=t[n];Se(i),e+=i.length}let r=new Uint8Array(e);for(let n=0,i=0;n<t.length;n++){let s=t[n];r.set(s,i),i+=s.length}return r}function ts(t,e={}){let r=(i,s)=>t(s).update(i).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=i=>t(i),Object.assign(r,e),Object.freeze(r)}function so(t=32){Qe(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 rs=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function io(t,e,r){return t&e^~t&r}function oo(t,e,r){return t&e^t&r^e&r}var nr=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,r,n,i){this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=i,this.buffer=new Uint8Array(e),this.view=jr(this.buffer)}update(e){Pt(this),Se(e);let{view:r,buffer:n,blockLen:i}=this,s=e.length;for(let o=0;o<s;){let a=Math.min(i-this.pos,s-o);if(a===i){let c=jr(e);for(;i<=s-o;o+=i)this.process(c,o);continue}n.set(e.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===i&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Pt(this),$r(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:i,isLE:s}=this,{pos:o}=this;r[o++]=128,ze(this.buffer.subarray(o)),this.padOffset>i-o&&(this.process(n,0),o=0);for(let l=o;l<i;l++)r[l]=0;n.setBigUint64(i-8,BigInt(this.length*8),s),this.process(n,0);let a=jr(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 l=0;l<u;l++)a.setUint32(4*l,f[l],s)}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:i,finished:s,destroyed:o,pos:a}=this;return e.destroyed=o,e.finished=s,e.length=i,e.pos=a,i%r&&e.buffer.set(n),e}clone(){return this._cloneInto()}},$e=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ae=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Yr=BigInt(4294967295),ao=BigInt(32);function gu(t,e=!1){return e?{h:Number(t&Yr),l:Number(t>>ao&Yr)}:{h:Number(t>>ao&Yr)|0,l:Number(t&Yr)|0}}function co(t,e=!1){let r=t.length,n=new Uint32Array(r),i=new Uint32Array(r);for(let s=0;s<r;s++){let{h:o,l:a}=gu(t[s],e);[n[s],i[s]]=[o,a]}return[n,i]}var ns=(t,e,r)=>t>>>r,ss=(t,e,r)=>t<<32-r|e>>>r,dt=(t,e,r)=>t>>>r|e<<32-r,pt=(t,e,r)=>t<<32-r|e>>>r,sr=(t,e,r)=>t<<64-r|e>>>r-32,ir=(t,e,r)=>t>>>r-32|e<<64-r;function Oe(t,e,r,n){let i=(e>>>0)+(n>>>0);return{h:t+r+(i/2**32|0)|0,l:i|0}}var uo=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),fo=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,lo=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),ho=(t,e,r,n,i)=>e+r+n+i+(t/2**32|0)|0,po=(t,e,r,n,i)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(i>>>0),mo=(t,e,r,n,i,s)=>e+r+n+i+s+(t/2**32|0)|0;var xu=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]),et=new Uint32Array(64),is=class extends nr{constructor(e){super(64,e,8,!1)}get(){let{A:e,B:r,C:n,D:i,E:s,F:o,G:a,H:c}=this;return[e,r,n,i,s,o,a,c]}set(e,r,n,i,s,o,a,c){this.A=e|0,this.B=r|0,this.C=n|0,this.D=i|0,this.E=s|0,this.F=o|0,this.G=a|0,this.H=c|0}process(e,r){for(let l=0;l<16;l++,r+=4)et[l]=e.getUint32(r,!1);for(let l=16;l<64;l++){let h=et[l-15],d=et[l-2],m=Le(h,7)^Le(h,18)^h>>>3,x=Le(d,17)^Le(d,19)^d>>>10;et[l]=x+et[l-7]+m+et[l-16]|0}let{A:n,B:i,C:s,D:o,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let h=Le(a,6)^Le(a,11)^Le(a,25),d=f+h+io(a,c,u)+xu[l]+et[l]|0,x=(Le(n,2)^Le(n,13)^Le(n,22))+oo(n,i,s)|0;f=u,u=c,c=a,a=o+d|0,o=s,s=i,i=n,n=d+x|0}n=n+this.A|0,i=i+this.B|0,s=s+this.C|0,o=o+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,i,s,o,a,c,u,f)}roundClean(){ze(et)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),ze(this.buffer)}},os=class extends is{A=$e[0]|0;B=$e[1]|0;C=$e[2]|0;D=$e[3]|0;E=$e[4]|0;F=$e[5]|0;G=$e[6]|0;H=$e[7]|0;constructor(){super(32)}};var yo=co(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(t=>BigInt(t))),Eu=yo[0],vu=yo[1],tt=new Uint32Array(80),rt=new Uint32Array(80),as=class extends nr{constructor(e){super(128,e,16,!1)}get(){let{Ah:e,Al:r,Bh:n,Bl:i,Ch:s,Cl:o,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:h,Gh:d,Gl:m,Hh:x,Hl:y}=this;return[e,r,n,i,s,o,a,c,u,f,l,h,d,m,x,y]}set(e,r,n,i,s,o,a,c,u,f,l,h,d,m,x,y){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=i|0,this.Ch=s|0,this.Cl=o|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=h|0,this.Gh=d|0,this.Gl=m|0,this.Hh=x|0,this.Hl=y|0}process(e,r){for(let I=0;I<16;I++,r+=4)tt[I]=e.getUint32(r),rt[I]=e.getUint32(r+=4);for(let I=16;I<80;I++){let k=tt[I-15]|0,_=rt[I-15]|0,P=dt(k,_,1)^dt(k,_,8)^ns(k,_,7),R=pt(k,_,1)^pt(k,_,8)^ss(k,_,7),T=tt[I-2]|0,O=rt[I-2]|0,V=dt(T,O,19)^sr(T,O,61)^ns(T,O,6),F=pt(T,O,19)^ir(T,O,61)^ss(T,O,6),p=lo(R,F,rt[I-7],rt[I-16]),g=ho(p,P,V,tt[I-7],tt[I-16]);tt[I]=g|0,rt[I]=p|0}let{Ah:n,Al:i,Bh:s,Bl:o,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:h,Fh:d,Fl:m,Gh:x,Gl:y,Hh:b,Hl:S}=this;for(let I=0;I<80;I++){let k=dt(l,h,14)^dt(l,h,18)^sr(l,h,41),_=pt(l,h,14)^pt(l,h,18)^ir(l,h,41),P=l&d^~l&x,R=h&m^~h&y,T=po(S,_,R,vu[I],rt[I]),O=mo(T,b,k,P,Eu[I],tt[I]),V=T|0,F=dt(n,i,28)^sr(n,i,34)^sr(n,i,39),p=pt(n,i,28)^ir(n,i,34)^ir(n,i,39),g=n&s^n&a^s&a,v=i&o^i&c^o&c;b=x|0,S=y|0,x=d|0,y=m|0,d=l|0,m=h|0,{h:l,l:h}=Oe(u|0,f|0,O|0,V|0),u=a|0,f=c|0,a=s|0,c=o|0,s=n|0,o=i|0;let E=uo(V,p,v);n=fo(E,O,F,g),i=E|0}({h:n,l:i}=Oe(this.Ah|0,this.Al|0,n|0,i|0)),{h:s,l:o}=Oe(this.Bh|0,this.Bl|0,s|0,o|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,l:h}=Oe(this.Eh|0,this.El|0,l|0,h|0),{h:d,l:m}=Oe(this.Fh|0,this.Fl|0,d|0,m|0),{h:x,l:y}=Oe(this.Gh|0,this.Gl|0,x|0,y|0),{h:b,l:S}=Oe(this.Hh|0,this.Hl|0,b|0,S|0),this.set(n,i,s,o,a,c,u,f,l,h,d,m,x,y,b,S)}roundClean(){ze(tt,rt)}destroy(){this.destroyed=!0,ze(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},cs=class extends as{Ah=ae[0]|0;Al=ae[1]|0;Bh=ae[2]|0;Bl=ae[3]|0;Ch=ae[4]|0;Cl=ae[5]|0;Dh=ae[6]|0;Dl=ae[7]|0;Eh=ae[8]|0;El=ae[9]|0;Fh=ae[10]|0;Fl=ae[11]|0;Gh=ae[12]|0;Gl=ae[13]|0;Hh=ae[14]|0;Hl=ae[15]|0;constructor(){super(64)}};var Ot=ts(()=>new os,rs(1));var Gr=ts(()=>new cs,rs(3));var U=(t,e,r)=>Se(t,e,r),fs=Qe,Ft=Zr,re=(...t)=>es(...t),Nt=t=>rr(t),mt=Qn,or=t=>so(t),Wr=BigInt(0),us=BigInt(1);function _e(t,e=""){if(typeof t!="boolean"){let r=e&&`"${e}" `;throw new TypeError(r+"expected boolean, got type="+typeof t)}return t}function Jr(t){if(typeof t=="bigint"){if(!Xr(t))throw new RangeError("positive bigint expected, got "+t)}else fs(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 ar(t){let e=Jr(t).toString(16);return e.length&1?"0"+e:e}function bo(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?Wr:BigInt("0x"+t)}function yt(t){return bo(Zr(t))}function Fe(t){return bo(Zr(cr(Se(t)).reverse()))}function Qr(t,e){if(Qe(e),e===0)throw new RangeError("zero length");t=Jr(t);let r=t.toString(16);if(r.length>e*2)throw new RangeError("number too large");return rr(r.padStart(e*2,"0"))}function ls(t,e){return Qr(t,e).reverse()}function go(t,e){if(t=U(t),e=U(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 cr(t){return Uint8Array.from(U(t))}function en(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 Xr=t=>typeof t=="bigint"&&Wr<=t;function Su(t,e,r){return Xr(t)&&Xr(e)&&Xr(r)&&e<=t&&t<r}function Kt(t,e,r,n){if(!Su(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function Ut(t){if(t<Wr)throw new Error("expected non-negative bigint, got "+t);let e;for(e=0;t>Wr;t>>=us,e+=1);return e}var ur=t=>(us<<BigInt(t))-us;function wo(t,e,r){if(Qe(t,"hashLen"),Qe(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=y=>new Uint8Array(y),i=Uint8Array.of(),s=Uint8Array.of(0),o=Uint8Array.of(1),a=1e3,c=n(t),u=n(t),f=0,l=()=>{c.fill(1),u.fill(0),f=0},h=(...y)=>r(u,re(c,...y)),d=(y=i)=>{u=h(s,y),c=h(),y.length!==0&&(u=h(o,y),c=h())},m=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let y=0,b=[];for(;y<e;){c=h();let S=c.slice();b.push(S),y+=c.length}return re(...b)};return(y,b)=>{l(),d(y);let S;for(;(S=b(m()))===void 0;)d();return l(),S}}function ke(t,e={},r={}){if(Object.prototype.toString.call(t)!=="[object Object]")throw new TypeError("expected valid options object");function n(s,o,a){if(!a&&o!=="function"&&!Object.hasOwn(t,s))throw new TypeError(`param "${s}" is invalid: expected own property`);let c=t[s];if(a&&c===void 0)return;let u=typeof c;if(u!==o||c===null)throw new TypeError(`param "${s}" is invalid: expected ${o}, got ${u}`)}let i=(s,o)=>Object.entries(s).forEach(([a,c])=>n(a,c,o));i(e,!1),i(r,!0)}var hs=()=>{throw new Error("not implemented")};var ce=BigInt(0),X=BigInt(1),bt=BigInt(2),So=BigInt(3),Ao=BigInt(4),Io=BigInt(5),Au=BigInt(7),Bo=BigInt(8),Iu=BigInt(9),To=BigInt(16);function Q(t,e){if(e<=ce)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=ce?r:e+r}function $(t,e,r){if(e<ce)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >ce;)n*=n,n%=r;return n}function xo(t,e){if(t===ce)throw new Error("invert: expected non-zero number");if(e<=ce)throw new Error("invert: expected positive modulus, got "+e);let r=Q(t,e),n=e,i=ce,s=X,o=X,a=ce;for(;r!==ce;){let u=n/r,f=n-r*u,l=i-o*u,h=s-a*u;n=r,r=f,i=o,s=a,o=l,a=h}if(n!==X)throw new Error("invert: does not exist");return Q(i,e)}function ds(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function Lo(t,e){let r=t,n=(r.ORDER+X)/Ao,i=r.pow(e,n);return ds(r,i,e),i}function Bu(t,e){let r=t,n=(r.ORDER-Io)/Bo,i=r.mul(e,bt),s=r.pow(i,n),o=r.mul(e,s),a=r.mul(r.mul(o,bt),s),c=r.mul(o,r.sub(a,r.ONE));return ds(r,c,e),c}function Tu(t){let e=Mt(t),r=_o(t),n=r(e,e.neg(e.ONE)),i=r(e,n),s=r(e,e.neg(n)),o=(t+Au)/To;return((a,c)=>{let u=a,f=u.pow(c,o),l=u.mul(f,n),h=u.mul(f,i),d=u.mul(f,s),m=u.eql(u.sqr(l),c),x=u.eql(u.sqr(h),c);f=u.cmov(f,l,m),l=u.cmov(d,h,x);let y=u.eql(u.sqr(l),c),b=u.cmov(f,l,y);return ds(u,b,c),b})}function _o(t){if(t<So)throw new Error("sqrt is not defined for small field");let e=t-X,r=0;for(;e%bt===ce;)e/=bt,r++;let n=bt,i=Mt(t);for(;Eo(i,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Lo;let s=i.pow(n,e),o=(e+X)/bt;return function(c,u){let f=c;if(f.is0(u))return u;if(Eo(f,u)!==1)throw new Error("Cannot find square root");let l=r,h=f.mul(f.ONE,s),d=f.pow(u,e),m=f.pow(u,o);for(;!f.eql(d,f.ONE);){if(f.is0(d))return f.ZERO;let x=1,y=f.sqr(d);for(;!f.eql(y,f.ONE);)if(x++,y=f.sqr(y),x===l)throw new Error("Cannot find square root");let b=X<<BigInt(l-x-1),S=f.pow(h,b);l=x,h=f.sqr(S),d=f.mul(d,h),m=f.mul(m,S)}return m}}function Lu(t){return t%Ao===So?Lo:t%Bo===Io?Bu:t%To===Iu?Tu(t):_o(t)}var je=(t,e)=>(Q(t,e)&X)===X,_u=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ps(t){let e={ORDER:"bigint",BYTES:"number",BITS:"number"},r=_u.reduce((n,i)=>(n[i]="function",n),e);if(ke(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<=X)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function Du(t,e,r){let n=t;if(r<ce)throw new Error("invalid exponent, negatives unsupported");if(r===ce)return n.ONE;if(r===X)return e;let i=n.ONE,s=e;for(;r>ce;)r&X&&(i=n.mul(i,s)),s=n.sqr(s),r>>=X;return i}function fr(t,e,r=!1){let n=t,i=new Array(e.length).fill(r?n.ZERO:void 0),s=e.reduce((a,c,u)=>n.is0(c)?a:(i[u]=a,n.mul(a,c)),n.ONE),o=n.inv(s);return e.reduceRight((a,c,u)=>n.is0(c)?a:(i[u]=n.mul(a,i[u]),n.mul(a,c)),o),i}function Eo(t,e){let r=t,n=(r.ORDER-X)/bt,i=r.pow(e,n),s=r.eql(i,r.ONE),o=r.eql(i,r.ZERO),a=r.eql(i,r.neg(r.ONE));if(!s&&!o&&!a)throw new Error("invalid Legendre symbol result");return s?1:o?0:-1}function ku(t,e){if(e!==void 0&&fs(e),t<=ce)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=Ut(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,i=Math.ceil(n/8);return{nBitLength:n,nByteLength:i}}var vo=new WeakMap,tn=class{ORDER;BITS;BYTES;isLE;ZERO=ce;ONE=X;_lengths;_mod;constructor(e,r={}){if(e<=X)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:i,nByteLength:s}=ku(e,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=i,this.BYTES=s,Object.freeze(this)}create(e){return Q(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return ce<=e&&e<this.ORDER}is0(e){return e===ce}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&X)===X}neg(e){return Q(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return Q(e*e,this.ORDER)}add(e,r){return Q(e+r,this.ORDER)}sub(e,r){return Q(e-r,this.ORDER)}mul(e,r){return Q(e*r,this.ORDER)}pow(e,r){return Du(this,e,r)}div(e,r){return Q(e*xo(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 xo(e,this.ORDER)}sqrt(e){let r=vo.get(this);return r||vo.set(this,r=Lu(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?ls(e,this.BYTES):Qr(e,this.BYTES)}fromBytes(e,r=!1){U(e);let{_lengths:n,BYTES:i,isLE:s,ORDER:o,_mod:a}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>i)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let u=new Uint8Array(i);u.set(e,s?0:u.length-e.length),e=u}if(e.length!==i)throw new Error("Field.fromBytes: expected "+i+" bytes, got "+e.length);let c=s?Fe(e):yt(e);if(a&&(c=Q(c,o)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return fr(this,e)}cmov(e,r,n){return _e(n,"condition"),n?r:e}};Object.freeze(tn.prototype);function Mt(t,e={}){return new tn(t,e)}function Do(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=X)throw new Error("field order must be greater than 1");let e=Ut(t-X);return Math.ceil(e/8)}function ms(t){let e=Do(t);return e+Math.ceil(e/2)}function ys(t,e,r=!1){U(t);let n=t.length,i=Do(e),s=Math.max(ms(e),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let o=r?Fe(t):yt(t),a=Q(o,e-X)+X;return r?ls(a,i):Qr(a,i)}var qt=BigInt(0),gt=BigInt(1);function lr(t,e){let r=e.negate();return t?r:e}function wt(t,e){let r=fr(t.Fp,e.map(n=>n.Z));return e.map((n,i)=>t.fromAffine(n.toAffine(r[i])))}function Po(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function bs(t,e){Po(t,e);let r=Math.ceil(e/t)+1,n=2**(t-1),i=2**t,s=ur(t),o=BigInt(t);return{windows:r,windowSize:n,mask:s,maxNumber:i,shiftBy:o}}function ko(t,e,r){let{windowSize:n,mask:i,maxNumber:s,shiftBy:o}=r,a=Number(t&i),c=t>>o;a>n&&(a-=s,c+=gt);let u=e*n,f=u+Math.abs(a)-1,l=a===0,h=a<0,d=e%2!==0;return{nextN:c,offset:f,isZero:l,isNeg:h,isNegF:d,offsetF:u}}var gs=new WeakMap,Oo=new WeakMap;function ws(t){return Oo.get(t)||1}function Ro(t){if(t!==qt)throw new Error("invalid wNAF")}var Vt=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 i=e;for(;r>qt;)r&gt&&(n=n.add(i)),i=i.double(),r>>=gt;return n}precomputeWindow(e,r){let{windows:n,windowSize:i}=bs(r,this.bits),s=[],o=e,a=o;for(let c=0;c<n;c++){a=o,s.push(a);for(let u=1;u<i;u++)a=a.add(o),s.push(a);o=a.double()}return s}wNAF(e,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let i=this.ZERO,s=this.BASE,o=bs(e,this.bits);for(let a=0;a<o.windows;a++){let{nextN:c,offset:u,isZero:f,isNeg:l,isNegF:h,offsetF:d}=ko(n,a,o);n=c,f?s=s.add(lr(h,r[d])):i=i.add(lr(l,r[u]))}return Ro(n),{p:i,f:s}}wNAFUnsafe(e,r,n,i=this.ZERO){let s=bs(e,this.bits);for(let o=0;o<s.windows&&n!==qt;o++){let{nextN:a,offset:c,isZero:u,isNeg:f}=ko(n,o,s);if(n=a,!u){let l=r[c];i=i.add(f?l.negate():l)}}return Ro(n),i}getPrecomputes(e,r,n){let i=gs.get(r);return i||(i=this.precomputeWindow(r,e),e!==1&&(typeof n=="function"&&(i=n(i)),gs.set(r,i))),i}cached(e,r,n){let i=ws(e);return this.wNAF(i,this.getPrecomputes(i,e,n),r)}unsafe(e,r,n,i){let s=ws(e);return s===1?this._unsafeLadder(e,r,i):this.wNAFUnsafe(s,this.getPrecomputes(s,e,n),r,i)}createCache(e,r){Po(r,this.bits),Oo.set(e,r),gs.delete(e)}hasCache(e){return ws(e)!==1}};function Fo(t,e,r,n){let i=e,s=t.ZERO,o=t.ZERO;for(;r>qt||n>qt;)r&gt&&(s=s.add(i)),n&gt&&(o=o.add(i)),i=i.double(),r>>=gt,n>>=gt;return{p1:s,p2:o}}function Co(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return ps(e),e}else return Mt(t,{isLE:r})}function rn(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>qt))throw new Error(`CURVE.${c} must be positive bigint`)}let i=Co(e.p,r.Fp,n),s=Co(e.n,r.Fn,n),a=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let c of a)if(!i.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:i,Fn:s}}function nn(t,e){return function(n){let i=t(n);return{secretKey:i,publicKey:e(i)}}}var nt=BigInt(0),oe=BigInt(1),xs=BigInt(2),Ru=BigInt(8);function Cu(t,e,r,n){let i=t.sqr(r),s=t.sqr(n),o=t.add(t.mul(e.a,i),s),a=t.add(t.ONE,t.mul(e.d,t.mul(i,s)));return t.eql(o,a)}function No(t,e={}){let r=e,n=rn("edwards",t,r,r.FpFnLE),{Fp:i,Fn:s}=n,o=n.CURVE,{h:a}=o;ke(r,{},{uvRatio:"function"});let c=xs<<BigInt(s.BYTES*8)-oe,u=x=>i.create(x),f=r.uvRatio===void 0?(x,y)=>{try{return{isValid:!0,value:i.sqrt(i.div(x,y))}}catch{return{isValid:!1,value:nt}}}:r.uvRatio;if(!Cu(i,o,o.Gx,o.Gy))throw new Error("bad curve params: generator point");function l(x,y,b=!1){let S=b?oe:nt;return Kt("coordinate "+x,y,S,c),y}function h(x){if(!(x instanceof d))throw new Error("EdwardsPoint expected")}class d{static BASE=new d(o.Gx,o.Gy,oe,u(o.Gx*o.Gy));static ZERO=new d(nt,oe,oe,nt);static Fp=i;static Fn=s;X;Y;Z;T;constructor(y,b,S,I){this.X=l("x",y),this.Y=l("y",b),this.Z=l("z",S,!0),this.T=l("t",I),Object.freeze(this)}static CURVE(){return o}static fromAffine(y){if(y instanceof d)throw new Error("extended point not allowed");let{x:b,y:S}=y||{};return l("x",b),l("y",S),new d(b,S,oe,u(b*S))}static fromBytes(y,b=!1){let S=i.BYTES,{a:I,d:k}=o;y=cr(U(y,S,"point")),_e(b,"zip215");let _=cr(y),P=y[S-1];_[S-1]=P&-129;let R=Fe(_),T=b?c:i.ORDER;Kt("point.y",R,nt,T);let O=u(R*R),V=u(O-oe),F=u(k*O-I),{isValid:p,value:g}=f(V,F);if(!p)throw new Error("bad point: invalid y coordinate");let v=(g&oe)===oe,E=(P&128)!==0;if(!b&&g===nt&&E)throw new Error("bad point: x=0 and x_0=1");return E!==v&&(g=u(-g)),d.fromAffine({x:g,y:R})}static fromHex(y,b=!1){return d.fromBytes(Nt(y),b)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=8,b=!0){return m.createCache(this,y),b||this.multiply(xs),this}assertValidity(){let y=this,{a:b,d:S}=o;if(y.is0())throw new Error("bad point: ZERO");let{X:I,Y:k,Z:_,T:P}=y,R=u(I*I),T=u(k*k),O=u(_*_),V=u(O*O),F=u(R*b),p=u(O*u(F+T)),g=u(V+u(S*u(R*T)));if(p!==g)throw new Error("bad point: equation left != right (1)");let v=u(I*k),E=u(_*P);if(v!==E)throw new Error("bad point: equation left != right (2)")}equals(y){h(y);let{X:b,Y:S,Z:I}=this,{X:k,Y:_,Z:P}=y,R=u(b*P),T=u(k*I),O=u(S*P),V=u(_*I);return R===T&&O===V}is0(){return this.equals(d.ZERO)}negate(){return new d(u(-this.X),this.Y,this.Z,u(-this.T))}double(){let{a:y}=o,{X:b,Y:S,Z:I}=this,k=u(b*b),_=u(S*S),P=u(xs*u(I*I)),R=u(y*k),T=b+S,O=u(u(T*T)-k-_),V=R+_,F=V-P,p=R-_,g=u(O*F),v=u(V*p),E=u(O*p),w=u(F*V);return new d(g,v,w,E)}add(y){h(y);let{a:b,d:S}=o,{X:I,Y:k,Z:_,T:P}=this,{X:R,Y:T,Z:O,T:V}=y,F=u(I*R),p=u(k*T),g=u(P*S*V),v=u(_*O),E=u((I+k)*(R+T)-F-p),w=v-g,A=v+g,L=u(p-b*F),B=u(E*w),D=u(A*L),C=u(E*L),K=u(w*A);return new d(B,D,K,C)}subtract(y){return h(y),this.add(y.negate())}multiply(y){if(!s.isValidNot0(y))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:b,f:S}=m.cached(this,y,I=>wt(d,I));return wt(d,[b,S])[0]}multiplyUnsafe(y){if(!s.isValid(y))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return y===nt?d.ZERO:this.is0()||y===oe?this:m.unsafe(this,y,b=>wt(d,b))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return m.unsafe(this,o.n).is0()}toAffine(y){let b=this,S=y,{X:I,Y:k,Z:_}=b,P=b.is0();S==null&&(S=P?Ru:i.inv(_));let R=u(I*S),T=u(k*S),O=i.mul(_,S);if(P)return{x:nt,y:oe};if(O!==oe)throw new Error("invZ was invalid");return{x:R,y:T}}clearCofactor(){return a===oe?this:this.multiplyUnsafe(a)}toBytes(){let{x:y,y:b}=this.toAffine(),S=i.toBytes(b);return S[S.length-1]|=y&oe?128:0,S}toHex(){return Ft(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let m=new Vt(d,s.BITS);return s.BITS>=8&&d.BASE.precompute(8),Object.freeze(d.prototype),Object.freeze(d),d}var sn=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(e){this.ep=e}static fromBytes(e){hs()}static fromHex(e){hs()}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 Ft(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 Ko(t,e,r={}){if(typeof e!="function")throw new Error('"hash" function param is required');let n=e,i=r;ke(i,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function"});let{prehash:s}=i,{BASE:o,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 l=i.randomBytes===void 0?or:i.randomBytes,h=i.adjustScalarBytes===void 0?p=>p:i.adjustScalarBytes,d=i.domain===void 0?(p,g,v)=>{if(_e(v,"phflag"),g.length||v)throw new Error("Contexts/pre-hash are not supported");return p}:i.domain;function m(p){return c.create(Fe(p))}function x(p){let g=R.secretKey;U(p,R.secretKey,"secretKey");let v=U(n(p),2*g,"hashedSecretKey"),E=h(v.slice(0,g)),w=v.slice(g,2*g),A=m(E);return{head:E,prefix:w,scalar:A}}function y(p){let{head:g,prefix:v,scalar:E}=x(p),w=o.multiply(E),A=w.toBytes();return{head:g,prefix:v,scalar:E,point:w,pointBytes:A}}function b(p){return y(p).pointBytes}function S(p=Uint8Array.of(),...g){let v=re(...g);return m(n(d(v,U(p,void 0,"context"),!!s)))}function I(p,g,v={}){p=U(p,void 0,"message"),s&&(p=s(p));let{prefix:E,scalar:w,pointBytes:A}=y(g),L=S(v.context,E,p),B=o.multiply(L).toBytes(),D=S(v.context,B,A,p),C=c.create(L+D*w);if(!c.isValid(C))throw new Error("sign failed: invalid s");let K=re(B,c.toBytes(C));return U(K,R.signature,"result")}let k={zip215:i.zip215};function _(p,g,v,E=k){let{context:w}=E,A=E.zip215===void 0?!!k.zip215:E.zip215,L=R.signature;p=U(p,L,"signature"),g=U(g,void 0,"message"),v=U(v,R.publicKey,"publicKey"),A!==void 0&&_e(A,"zip215"),s&&(g=s(g));let B=L/2,D=p.subarray(0,B),C=Fe(p.subarray(B,L)),K,M,N;try{K=t.fromBytes(v,A),M=t.fromBytes(D,A),N=o.multiplyUnsafe(C)}catch{return!1}if(!A&&K.isSmallOrder())return!1;let te=S(w,D,v,g);return M.add(K.multiplyUnsafe(te)).subtract(N).clearCofactor().is0()}let P=a.BYTES,R={secretKey:P,publicKey:P,signature:2*P,seed:P};function T(p){return p=p===void 0?l(R.seed):p,U(p,R.seed,"seed")}function O(p){return mt(p)&&p.length===R.secretKey}function V(p,g){try{return!!t.fromBytes(p,g===void 0?k.zip215:g)}catch{return!1}}let F={getExtendedPublicKey:y,randomSecretKey:T,isValidSecretKey:O,isValidPublicKey:V,toMontgomery(p){let{y:g}=t.fromBytes(p),v=R.publicKey,E=v===32;if(!E&&v!==57)throw new Error("only defined for 25519 and 448");let w=E?a.div(oe+g,oe-g):a.div(g-oe,g+oe);return a.toBytes(w)},toMontgomerySecret(p){let g=R.secretKey;U(p,g);let v=n(p.subarray(0,g));return h(v).subarray(0,g)}};return Object.freeze(R),Object.freeze(F),Object.freeze({keygen:nn(T,b),getPublicKey:b,sign:I,verify:_,utils:F,Point:t,lengths:R})}function hr(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 Pu(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 Ou(t){if(!mt(t)&&typeof t!="string")throw new Error("DST must be Uint8Array or ascii string");let e=typeof t=="string"?en(t):t;if(e.length===0)throw new Error("DST must be non-empty");return e}function Es(t,e,r,n){U(t),De(r),e=Ou(e),e.length>255&&(e=n(re(en("H2C-OVERSIZE-DST-"),e)));let{outputLen:i,blockLen:s}=n,o=Math.ceil(r/i);if(r>65535||o>255)throw new Error("expand_message_xmd: invalid lenInBytes");let a=re(e,hr(e.length,1)),c=new Uint8Array(s),u=hr(r,2),f=new Array(o),l=n(re(c,t,u,hr(0,1),a));f[0]=n(re(l,hr(1,1),a));for(let d=1;d<o;d++){let m=[Pu(l,f[d-1]),hr(d+1,1),a];f[d]=n(re(...m))}return re(...f).slice(0,r)}var Uo="HashToScalar-";var Fu=BigInt(0),Ze=BigInt(1),Mo=BigInt(2);var Nu=BigInt(5),Ku=BigInt(8),Ht=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Is={p:Ht,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Ku,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Uu(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),i=BigInt(80),s=Ht,a=t*t%s*t%s,c=$(a,Mo,s)*a%s,u=$(c,Ze,s)*t%s,f=$(u,Nu,s)*u%s,l=$(f,e,s)*f%s,h=$(l,r,s)*l%s,d=$(h,n,s)*h%s,m=$(d,i,s)*d%s,x=$(m,i,s)*d%s,y=$(x,e,s)*f%s;return{pow_p_5_8:$(y,Mo,s)*t%s,b2:a}}function Mu(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var vs=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Bs(t,e){let r=Ht,n=Q(e*e*e,r),i=Q(n*n*e,r),s=Uu(t*i).pow_p_5_8,o=Q(t*n*s,r),a=Q(e*o*o,r),c=o,u=Q(o*vs,r),f=a===t,l=a===Q(-t,r),h=a===Q(-t*vs,r);return f&&(o=c),(l||h)&&(o=u),je(o,r)&&(o=Q(-o,r)),{isValid:f||l,value:o}}var it=No(Is,{uvRatio:Bs}),st=it.Fp,Ho=it.Fn;function qu(t){return Ko(it,Gr,Object.assign({adjustScalarBytes:Mu,zip215:!0},t))}var zo=qu({});var Ss=vs,Vu=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Hu=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),zu=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),$u=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),qo=t=>Bs(Ze,t),ju=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),As=t=>st.create(Fe(t)&ju);function Vo(t){let{d:e}=Is,r=Ht,n=b=>st.create(b),i=n(Ss*t*t),s=n((i+Ze)*zu),o=BigInt(-1),a=n((o-e*i)*n(i+e)),{isValid:c,value:u}=Bs(s,a),f=n(u*t);je(f,r)||(f=n(-f)),c||(u=f),c||(o=i);let l=n(o*(i-Ze)*$u-a),h=u*u,d=n((u+u)*a),m=n(l*Vu),x=n(Ze-h),y=n(Ze+h);return new it(n(d*y),n(x*m),n(m*y),n(d*x))}var ot=class t extends sn{static BASE=new t(it.BASE);static ZERO=new t(it.ZERO);static Fp=st;static Fn=Ho;constructor(e){super(e)}static fromAffine(e){return new t(it.fromAffine(e))}assertSame(e){if(!(e instanceof t))throw new Error("RistrettoPoint expected")}init(e){return new t(e)}static fromBytes(e){Se(e,32);let{a:r,d:n}=Is,i=Ht,s=k=>st.create(k),o=As(e);if(!go(st.toBytes(o),e)||je(o,i))throw new Error("invalid ristretto255 encoding 1");let a=s(o*o),c=s(Ze+r*a),u=s(Ze-r*a),f=s(c*c),l=s(u*u),h=s(r*n*f-l),{isValid:d,value:m}=qo(s(h*l)),x=s(m*u),y=s(m*x*h),b=s((o+o)*x);je(b,i)&&(b=s(-b));let S=s(c*y),I=s(b*S);if(!d||je(I,i)||S===Fu)throw new Error("invalid ristretto255 encoding 2");return new t(new it(b,S,Ze,I))}static fromHex(e){return t.fromBytes(rr(e))}toBytes(){let{X:e,Y:r,Z:n,T:i}=this.ep,s=Ht,o=y=>st.create(y),a=o(o(n+r)*o(n-r)),c=o(e*r),u=o(c*c),{value:f}=qo(o(a*u)),l=o(f*a),h=o(f*c),d=o(l*h*i),m;if(je(i*d,s)){let y=o(r*Ss),b=o(e*Ss);e=y,r=b,m=o(l*Hu)}else m=h;je(e*d,s)&&(r=o(-r));let x=o((n-r)*m);return je(x,s)&&(x=o(-x)),st.toBytes(x)}equals(e){this.assertSame(e);let{X:r,Y:n}=this.ep,{X:i,Y:s}=e.ep,o=u=>st.create(u),a=o(r*s)===o(n*i),c=o(n*s)===o(r*i);return a||c}is0(){return this.equals(t.ZERO)}};Object.freeze(ot.BASE);Object.freeze(ot.ZERO);Object.freeze(ot.prototype);Object.freeze(ot);var Zu=Object.freeze({Point:ot,hashToCurve(t,e){let r=e?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":e.DST,n=Es(t,r,64,Gr);return Zu.deriveToCurve(n)},hashToScalar(t,e={DST:Uo}){let r=Es(t,e.DST,64,Gr);return Ho.create(Fe(r))},deriveToCurve(t){Se(t,64);let e=As(t.subarray(0,32)),r=Vo(e),n=As(t.subarray(32,64)),i=Vo(n);return new ot(r.add(i))}});var dr=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},on=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var Be={get(t=globalThis){let e=t.crypto;if(e?.subtle==null)throw new on("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 Ts,Yu=(async()=>{try{return await Be.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Gu(t,e,r){if(t.buffer instanceof ArrayBuffer){let n=await Be.get().subtle.importKey("raw",t.buffer,{name:"Ed25519"},!1,["verify"]);return await Be.get().subtle.verify({name:"Ed25519"},n,Ie(e),Ie(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Xu(t,e,r){return zo.verify(e,r instanceof Uint8Array?r:r.subarray(),t)}async function $o(t,e,r){return Ts==null&&(Ts=await Yu),Ts?Gu(t,e,r):Xu(t,e,r)}function cn(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var un=class{type="Ed25519";raw;constructor(e){this.raw=Ls(e,an)}toMultihash(){return Te.digest(Ve(this))}toCID(){return ue.createV1(114,this.toMultihash())}toString(){return Z.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ye(this.raw,e.raw)}verify(e,r,n){n?.signal?.throwIfAborted();let i=$o(this.raw,r,e);return cn(i)?i.then(s=>(n?.signal?.throwIfAborted(),s)):i}};function _s(t){return t=Ls(t,an),new un(t)}function Ls(t,e){if(t=Uint8Array.from(t??[]),t.length!==e)throw new j(`Key must be a Uint8Array of length ${e}, got ${t.length}`);return t}var Ju=Math.pow(2,7),Qu=Math.pow(2,14),ef=Math.pow(2,21),Ds=Math.pow(2,28),ks=Math.pow(2,35),Rs=Math.pow(2,42),Cs=Math.pow(2,49),q=128,fe=127;function Ye(t){if(t<Ju)return 1;if(t<Qu)return 2;if(t<ef)return 3;if(t<Ds)return 4;if(t<ks)return 5;if(t<Rs)return 6;if(t<Cs)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ps(t,e,r=0){switch(Ye(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 tf(t,e,r=0){switch(Ye(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&fe,r<q||(r=t[e+1],n+=(r&fe)<<7,r<q)||(r=t[e+2],n+=(r&fe)<<14,r<q)||(r=t[e+3],n+=(r&fe)<<21,r<q)||(r=t[e+4],n+=(r&fe)*Ds,r<q)||(r=t[e+5],n+=(r&fe)*ks,r<q)||(r=t[e+6],n+=(r&fe)*Rs,r<q)||(r=t[e+7],n+=(r&fe)*Cs,r<q))return n;throw new RangeError("Could not decode varint")}function rf(t,e){let r=t.get(e),n=0;if(n+=r&fe,r<q||(r=t.get(e+1),n+=(r&fe)<<7,r<q)||(r=t.get(e+2),n+=(r&fe)<<14,r<q)||(r=t.get(e+3),n+=(r&fe)<<21,r<q)||(r=t.get(e+4),n+=(r&fe)*Ds,r<q)||(r=t.get(e+5),n+=(r&fe)*ks,r<q)||(r=t.get(e+6),n+=(r&fe)*Rs,r<q)||(r=t.get(e+7),n+=(r&fe)*Cs,r<q))return n;throw new RangeError("Could not decode varint")}function Zo(t,e,r=0){return e==null&&(e=be(Ye(t))),e instanceof Uint8Array?Ps(t,e,r):tf(t,e,r)}function Yo(t,e=0){return t instanceof Uint8Array?Os(t,e):rf(t,e)}var Fs=new Float32Array([-0]),at=new Uint8Array(Fs.buffer);function Go(t,e,r){Fs[0]=t,e[r]=at[0],e[r+1]=at[1],e[r+2]=at[2],e[r+3]=at[3]}function Xo(t,e){return at[0]=t[e],at[1]=t[e+1],at[2]=t[e+2],at[3]=t[e+3],Fs[0]}var Ns=new Float64Array([-0]),le=new Uint8Array(Ns.buffer);function Wo(t,e,r){Ns[0]=t,e[r]=le[0],e[r+1]=le[1],e[r+2]=le[2],e[r+3]=le[3],e[r+4]=le[4],e[r+5]=le[5],e[r+6]=le[6],e[r+7]=le[7]}function Jo(t,e){return le[0]=t[e],le[1]=t[e+1],le[2]=t[e+2],le[3]=t[e+3],le[4]=t[e+4],le[5]=t[e+5],le[6]=t[e+6],le[7]=t[e+7],Ns[0]}var sf=BigInt(Number.MAX_SAFE_INTEGER),of=BigInt(Number.MIN_SAFE_INTEGER),Ae=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 xt;if(e<sf&&e>of)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,i=e-(n<<32n);return r&&(n=~n|0n,i=~i|0n,++i>Qo&&(i=0n,++n>Qo&&(n=0n))),new t(Number(i),Number(n))}static fromNumber(e){if(e===0)return xt;let r=e<0;r&&(e=-e);let n=e>>>0,i=(e-n)/4294967296>>>0;return r&&(i=~i>>>0,n=~n>>>0,++n>4294967295&&(n=0,++i>4294967295&&(i=0))),new t(n,i)}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):xt}},xt=new Ae(0,0);xt.toBigInt=function(){return 0n};xt.zzEncode=xt.zzDecode=function(){return this};xt.length=function(){return 1};var Qo=4294967296n;function ea(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 ta(t,e,r){if(r-e<1)return"";let i,s=[],o=0,a;for(;e<r;)a=t[e++],a<128?s[o++]=a:a>191&&a<224?s[o++]=(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,s[o++]=55296+(a>>10),s[o++]=56320+(a&1023)):s[o++]=(a&15)<<12|(t[e++]&63)<<6|t[e++]&63,o>8191&&((i??(i=[])).push(String.fromCharCode.apply(String,s)),o=0);return i!=null?(o>0&&i.push(String.fromCharCode.apply(String,s.slice(0,o))),i.join("")):String.fromCharCode.apply(String,s.slice(0,o))}function Ks(t,e,r){let n=r,i,s;for(let o=0;o<t.length;++o)i=t.charCodeAt(o),i<128?e[r++]=i:i<2048?(e[r++]=i>>6|192,e[r++]=i&63|128):(i&64512)===55296&&((s=t.charCodeAt(o+1))&64512)===56320?(i=65536+((i&1023)<<10)+(s&1023),++o,e[r++]=i>>18|240,e[r++]=i>>12&63|128,e[r++]=i>>6&63|128,e[r++]=i&63|128):(e[r++]=i>>12|224,e[r++]=i>>6&63|128,e[r++]=i&63|128);return r-n}function Re(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function fn(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var Us=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=Ie(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,Re(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 Re(this,4);return fn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Re(this,4);return fn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Re(this,4);let e=Xo(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Re(this,4);let e=Jo(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 Re(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return ta(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Re(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Re(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 Ae(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 Re(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 Re(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 Re(this,8);let e=fn(this.buf,this.pos+=4),r=fn(this.buf,this.pos+=4);return new Ae(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+=Ye(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 pr(t){return new Us(t instanceof Uint8Array?t:t.subarray())}function we(t,e,r){let n=pr(t);return e.decode(n,void 0,r)}function Ms(t){let e=t??8192,r=e>>>1,n,i=e;return function(o){if(o<1||o>r)return be(o);i+o>e&&(n=be(e),i=0);let a=n.subarray(i,i+=o);return(i&7)!==0&&(i=(i|7)+1),a}}var Et=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function qs(){}var Hs=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},af=Ms();function cf(t){return globalThis.Buffer!=null?be(t):af(t)}var yr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Et(qs,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new Et(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new zs((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(ln,10,Ae.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=Ae.fromBigInt(e);return this._push(ln,r.length(),r)}uint64Number(e){return this._push(Ps,Ye(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=Ae.fromBigInt(e).zzEncode();return this._push(ln,r.length(),r)}sint64Number(e){let r=Ae.fromNumber(e).zzEncode();return this._push(ln,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Vs,1,e?1:0)}fixed32(e){return this._push(mr,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=Ae.fromBigInt(e);return this._push(mr,4,r.lo)._push(mr,4,r.hi)}fixed64Number(e){let r=Ae.fromNumber(e);return this._push(mr,4,r.lo)._push(mr,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(Go,4,e)}double(e){return this._push(Wo,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(Vs,1,0):this.uint32(r)._push(ff,r,e)}string(e){let r=ea(e);return r!==0?this.uint32(r)._push(Ks,r,e):this._push(Vs,1,0)}fork(){return this.states=new Hs(this),this.head=this.tail=new Et(qs,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 Et(qs,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=cf(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function Vs(t,e,r){e[r]=t&255}function uf(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var zs=class extends Et{next;constructor(e,r){super(uf,e,r),this.next=void 0}};function ln(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 mr(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 ff(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(yr.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(lf,e,t),this},yr.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(hf,e,t),this});function lf(t,e,r){e.set(t,r)}function hf(t,e,r){t.length<40?Ks(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(z(t),r)}function $s(){return new yr}function xe(t,e){let r=$s();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*Ee(t,e,r){let n=pr(t);yield*e.stream(n,void 0,"$",r)}var hn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function dn(t,e,r,n,i){return{name:t,type:e,encode:r,decode:n,stream:i}}function js(t){function e(s){if(t[s.toString()]==null)throw new Error("Invalid enum value");return t[s]}let r=function(o,a){let c=e(o);a.int32(c)},n=function(o){let a=o.int32();return e(a)},i=function*(o){let a=o.int32();yield e(a)};return dn("enum",hn.VARINT,r,n,i)}function ve(t,e,r){return dn("message",hn.LENGTH_DELIMITED,t,e,r)}var ee=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var Y;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.ECDSA="ECDSA"})(Y||(Y={}));var Zs;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(Zs||(Zs={}));(function(t){t.codec=()=>js(Zs)})(Y||(Y={}));var Ne;(function(t){let e;t.codec=()=>(e==null&&(e=ve((s,o,a={})=>{a.lengthDelimited!==!1&&o.fork(),s.Type!=null&&(o.uint32(8),Y.codec().encode(s.Type,o)),s.Data!=null&&(o.uint32(18),o.bytes(s.Data)),a.lengthDelimited!==!1&&o.ldelim()},(s,o,a={})=>{let c={},u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=Y.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,o,a,c={}){let u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:Y.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return xe(s,t.codec())}t.encode=r;function n(s,o){return we(s,t.codec(),o)}t.decode=n;function i(s,o){return Ee(s,t.codec(),o)}t.stream=i})(Ne||(Ne={}));var Ys;(function(t){let e;t.codec=()=>(e==null&&(e=ve((s,o,a={})=>{a.lengthDelimited!==!1&&o.fork(),s.Type!=null&&(o.uint32(8),Y.codec().encode(s.Type,o)),s.Data!=null&&(o.uint32(18),o.bytes(s.Data)),a.lengthDelimited!==!1&&o.ldelim()},(s,o,a={})=>{let c={},u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=Y.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,o,a,c={}){let u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:Y.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return xe(s,t.codec())}t.encode=r;function n(s,o){return we(s,t.codec(),o)}t.decode=n;function i(s,o){return Ee(s,t.codec(),o)}t.stream=i})(Ys||(Ys={}));var gr={};me(gr,{MAX_RSA_KEY_SIZE:()=>Gs,generateRSAKeyPair:()=>aa,jwkToJWKKeyPair:()=>ca,jwkToPkcs1:()=>yf,jwkToPkix:()=>Qs,jwkToRSAPrivateKey:()=>ni,pkcs1MessageToJwk:()=>Ws,pkcs1MessageToRSAPrivateKey:()=>ei,pkcs1ToJwk:()=>mf,pkcs1ToRSAPrivateKey:()=>oa,pkixMessageToJwk:()=>Js,pkixMessageToRSAPublicKey:()=>ri,pkixToJwk:()=>bf,pkixToRSAPublicKey:()=>ti});var zt=class{type="RSA";jwk;_raw;_multihash;constructor(e,r){this.jwk=e,this._multihash=r}get raw(){return this._raw==null&&(this._raw=gr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return ue.createV1(114,this._multihash)}toString(){return Z.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ye(this.raw,e.raw)}verify(e,r,n){return ia(this.jwk,r,e,n)}},br=class{type="RSA";jwk;_raw;publicKey;constructor(e,r){this.jwk=e,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=gr.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ye(this.raw,e.raw)}sign(e,r){return sa(this.jwk,e,r)}};var Gs=8192,Xs=18,df=1062,pf=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function mf(t){let e=qe(t);return Ws(e)}function Ws(t){return{n:H(t[1],"base64url"),e:H(t[2],"base64url"),d:H(t[3],"base64url"),p:H(t[4],"base64url"),q:H(t[5],"base64url"),dp:H(t[6],"base64url"),dq:H(t[7],"base64url"),qi:H(t[8],"base64url"),kty:"RSA"}}function yf(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 j("JWK was missing components");return Je([ge(Uint8Array.from([0])),ge(z(t.n,"base64url")),ge(z(t.e,"base64url")),ge(z(t.d,"base64url")),ge(z(t.p,"base64url")),ge(z(t.q,"base64url")),ge(z(t.dp,"base64url")),ge(z(t.dq,"base64url")),ge(z(t.qi,"base64url"))]).subarray()}function bf(t){let e=qe(t,{offset:0});return Js(e)}function Js(t){let e=qe(t[1],{offset:0});return{kty:"RSA",n:H(e[0],"base64url"),e:H(e[1],"base64url")}}function Qs(t){if(t.n==null||t.e==null)throw new j("JWK was missing components");return Je([pf,Hr(Je([ge(z(t.n,"base64url")),ge(z(t.e,"base64url"))]))]).subarray()}function oa(t){let e=qe(t);return ei(e)}function ei(t){let e=Ws(t);return ni(e)}function ti(t,e){if(t.byteLength>=df)throw new Bt("Key size is too large");let r=qe(t,{offset:0});return ri(r,t,e)}function ri(t,e,r){let n=Js(t);if(r==null){let i=Ot(Ne.encode({Type:Y.RSA,Data:e}));r=Pe(Xs,i)}return new zt(n,r)}function ni(t){if(fa(t)>Gs)throw new j("Key size is too large");let e=ca(t),r=Ot(Ne.encode({Type:Y.RSA,Data:Qs(e.publicKey)})),n=Pe(Xs,r);return new br(e.privateKey,new zt(e.publicKey,n))}async function aa(t){if(t>Gs)throw new j("Key size is too large");let e=await ua(t),r=Ot(Ne.encode({Type:Y.RSA,Data:Qs(e.publicKey)})),n=Pe(Xs,r);return new br(e.privateKey,new zt(e.publicKey,n))}function ca(t){if(t==null)throw new j("Missing key parameter");return{privateKey:t,publicKey:{kty:t.kty,n:t.n,e:t.e}}}async function ua(t,e){let r=await Be.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 gf(r,e);return{privateKey:n[0],publicKey:n[1]}}async function sa(t,e,r){let n=await Be.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let i=await Be.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,Ie(e instanceof Uint8Array?e:e.subarray()));return r?.signal?.throwIfAborted(),new Uint8Array(i,0,i.byteLength)}async function ia(t,e,r,n){let i=await Be.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await Be.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},i,Ie(e),Ie(r instanceof Uint8Array?r:r.subarray()));return n?.signal?.throwIfAborted(),s}async function gf(t,e){if(t.privateKey==null||t.publicKey==null)throw new j("Private and public key are required");let r=await Promise.all([Be.get().subtle.exportKey("jwk",t.privateKey),Be.get().subtle.exportKey("jwk",t.publicKey)]);return e?.signal?.throwIfAborted(),r}function fa(t){if(t.kty!=="RSA")throw new j("invalid key type");if(t.n==null)throw new j("invalid key modulus");return z(t.n,"base64url").length*8}var pn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,r){if(zr(e),Se(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,i=new Uint8Array(n);i.set(r.length>n?e.create().update(r).digest():r);for(let s=0;s<i.length;s++)i[s]^=54;this.iHash.update(i),this.oHash=e.create();for(let s=0;s<i.length;s++)i[s]^=106;this.oHash.update(i),ze(i)}update(e){return Pt(this),this.iHash.update(e),this}digestInto(e){Pt(this),$r(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:i,destroyed:s,blockLen:o,outputLen:a}=this;return e=e,e.finished=i,e.destroyed=s,e.blockLen=o,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()}},la=(()=>{let t=((e,r,n)=>new pn(e,r).update(n).digest());return t.create=(e,r)=>new pn(e,r),t})();var ha=(t,e)=>(t+(t>=0?e:-e)/da)/e;function wf(t,e,r){Kt("scalar",t,Ke,r);let[[n,i],[s,o]]=e,a=ha(o*t,r),c=ha(-i*t,r),u=t-a*n-c*s,f=-a*i-c*o,l=u<Ke,h=f<Ke;l&&(u=-u),h&&(f=-f);let d=ur(Math.ceil(Ut(r)/2))+ct;if(u<Ke||u>=d||f<Ke||f>=d)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:u,k2neg:h,k2:f}}function ii(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function si(t,e){ke(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return _e(r.lowS,"lowS"),_e(r.prehash,"prehash"),r.format!==void 0&&ii(r.format),r}var oi=class extends Error{constructor(e=""){super(e)}},Ce={Err:oi,_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,i=ar(n);if(i.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?ar(i.length/2|128):"";return ar(t)+s+i+e},decode(t,e){let{Err:r}=Ce;e=U(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 i=e[n++],s=!!(i&128),o=0;if(!s)o=i;else{let c=i&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)o=o<<8|f;if(n+=c,o<128)throw new r("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+o);if(a.length!==o)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+o)}}},_int:{encode(t){let{Err:e}=Ce;if(Jr(t),t<Ke)throw new e("integer: negative integers are not allowed");let r=ar(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,i=U(t,void 0,"signature"),{v:s,l:o}=n.decode(48,i);if(o.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{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)),i=e.encode(2,r.encode(t.s)),s=n+i;return e.encode(48,s)}};Object.freeze(Ce._tlv);Object.freeze(Ce._int);Object.freeze(Ce);var Ke=BigInt(0),ct=BigInt(1),da=BigInt(2),mn=BigInt(3),xf=BigInt(4);function pa(t,e={}){let r=rn("weierstrass",t,e),n=r.Fp,i=r.Fn,s=r.CURVE,{h:o,n:a}=s;ke(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c,allowInfinityPoint:u}=e;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let f=ya(n,i);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function h(F,p,g){if(u&&p.is0())return Uint8Array.of(0);let{x:v,y:E}=p.toAffine(),w=n.toBytes(v);if(_e(g,"isCompressed"),g){l();let A=!n.isOdd(E);return re(ma(A),w)}else return re(Uint8Array.of(4),w,n.toBytes(E))}function d(F){U(F,void 0,"Point");let{publicKey:p,publicKeyUncompressed:g}=f,v=F.length,E=F[0],w=F.subarray(1);if(u&&v===1&&E===0)return{x:n.ZERO,y:n.ZERO};if(v===p&&(E===2||E===3)){let A=n.fromBytes(w);if(!n.isValid(A))throw new Error("bad point: is not on curve, wrong x");let L=y(A),B;try{B=n.sqrt(L)}catch(K){let M=K instanceof Error?": "+K.message:"";throw new Error("bad point: is not on curve, sqrt error"+M)}l();let D=n.isOdd(B);return(E&1)===1!==D&&(B=n.neg(B)),{x:A,y:B}}else if(v===g&&E===4){let A=n.BYTES,L=n.fromBytes(w.subarray(0,A)),B=n.fromBytes(w.subarray(A,A*2));if(!b(L,B))throw new Error("bad point: is not on curve");return{x:L,y:B}}else throw new Error(`bad point: got length ${v}, expected compressed=${p} or uncompressed=${g}`)}let m=e.toBytes===void 0?h:e.toBytes,x=e.fromBytes===void 0?d:e.fromBytes;function y(F){let p=n.sqr(F),g=n.mul(p,F);return n.add(n.add(g,n.mul(F,s.a)),s.b)}function b(F,p){let g=n.sqr(p),v=y(F);return n.eql(g,v)}if(!b(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let S=n.mul(n.pow(s.a,mn),xf),I=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(S,I)))throw new Error("bad curve params: a or b");function k(F,p,g=!1){if(!n.isValid(p)||g&&n.is0(p))throw new Error(`bad point coordinate ${F}`);return p}function _(F){if(!(F instanceof T))throw new Error("Weierstrass Point expected")}function P(F){if(!c||!c.basises)throw new Error("no endo");return wf(F,c.basises,i.ORDER)}function R(F,p,g,v,E){return g=new T(n.mul(g.X,F),g.Y,g.Z),p=lr(v,p),g=lr(E,g),p.add(g)}class T{static BASE=new T(s.Gx,s.Gy,n.ONE);static ZERO=new T(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=i;X;Y;Z;constructor(p,g,v){this.X=k("x",p),this.Y=k("y",g,!0),this.Z=k("z",v),Object.freeze(this)}static CURVE(){return s}static fromAffine(p){let{x:g,y:v}=p||{};if(!p||!n.isValid(g)||!n.isValid(v))throw new Error("invalid affine point");if(p instanceof T)throw new Error("projective point not allowed");return n.is0(g)&&n.is0(v)?T.ZERO:new T(g,v,n.ONE)}static fromBytes(p){let g=T.fromAffine(x(U(p,void 0,"point")));return g.assertValidity(),g}static fromHex(p){return T.fromBytes(Nt(p))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=8,g=!0){return V.createCache(this,p),g||this.multiply(mn),this}assertValidity(){let p=this;if(p.is0()){if(e.allowInfinityPoint&&n.is0(p.X)&&n.eql(p.Y,n.ONE)&&n.is0(p.Z))return;throw new Error("bad point: ZERO")}let{x:g,y:v}=p.toAffine();if(!n.isValid(g)||!n.isValid(v))throw new Error("bad point: x or y not field elements");if(!b(g,v))throw new Error("bad point: equation left != right");if(!p.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:p}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(p)}equals(p){_(p);let{X:g,Y:v,Z:E}=this,{X:w,Y:A,Z:L}=p,B=n.eql(n.mul(g,L),n.mul(w,E)),D=n.eql(n.mul(v,L),n.mul(A,E));return B&&D}negate(){return new T(this.X,n.neg(this.Y),this.Z)}double(){let{a:p,b:g}=s,v=n.mul(g,mn),{X:E,Y:w,Z:A}=this,L=n.ZERO,B=n.ZERO,D=n.ZERO,C=n.mul(E,E),K=n.mul(w,w),M=n.mul(A,A),N=n.mul(E,w);return N=n.add(N,N),D=n.mul(E,A),D=n.add(D,D),L=n.mul(p,D),B=n.mul(v,M),B=n.add(L,B),L=n.sub(K,B),B=n.add(K,B),B=n.mul(L,B),L=n.mul(N,L),D=n.mul(v,D),M=n.mul(p,M),N=n.sub(C,M),N=n.mul(p,N),N=n.add(N,D),D=n.add(C,C),C=n.add(D,C),C=n.add(C,M),C=n.mul(C,N),B=n.add(B,C),M=n.mul(w,A),M=n.add(M,M),C=n.mul(M,N),L=n.sub(L,C),D=n.mul(M,K),D=n.add(D,D),D=n.add(D,D),new T(L,B,D)}add(p){_(p);let{X:g,Y:v,Z:E}=this,{X:w,Y:A,Z:L}=p,B=n.ZERO,D=n.ZERO,C=n.ZERO,K=s.a,M=n.mul(s.b,mn),N=n.mul(g,w),te=n.mul(v,A),ne=n.mul(E,L),se=n.add(g,v),W=n.add(w,A);se=n.mul(se,W),W=n.add(N,te),se=n.sub(se,W),W=n.add(g,E);let pe=n.add(w,L);return W=n.mul(W,pe),pe=n.add(N,ne),W=n.sub(W,pe),pe=n.add(v,E),B=n.add(A,L),pe=n.mul(pe,B),B=n.add(te,ne),pe=n.sub(pe,B),C=n.mul(K,W),B=n.mul(M,ne),C=n.add(B,C),B=n.sub(te,C),C=n.add(te,C),D=n.mul(B,C),te=n.add(N,N),te=n.add(te,N),ne=n.mul(K,ne),W=n.mul(M,W),te=n.add(te,ne),ne=n.sub(N,ne),ne=n.mul(K,ne),W=n.add(W,ne),N=n.mul(te,W),D=n.add(D,N),N=n.mul(pe,W),B=n.mul(se,B),B=n.sub(B,N),N=n.mul(se,te),C=n.mul(pe,C),C=n.add(C,N),new T(B,D,C)}subtract(p){return _(p),this.add(p.negate())}is0(){return this.equals(T.ZERO)}multiply(p){let{endo:g}=e;if(!i.isValidNot0(p))throw new RangeError("invalid scalar: out of range");let v,E,w=A=>V.cached(this,A,L=>wt(T,L));if(g){let{k1neg:A,k1:L,k2neg:B,k2:D}=P(p),{p:C,f:K}=w(L),{p:M,f:N}=w(D);E=K.add(N),v=R(g.beta,C,M,A,B)}else{let{p:A,f:L}=w(p);v=A,E=L}return wt(T,[v,E])[0]}multiplyUnsafe(p){let{endo:g}=e,v=this,E=p;if(!i.isValid(E))throw new RangeError("invalid scalar: out of range");if(E===Ke||v.is0())return T.ZERO;if(E===ct)return v;if(V.hasCache(this))return this.multiply(E);if(g){let{k1neg:w,k1:A,k2neg:L,k2:B}=P(E),{p1:D,p2:C}=Fo(T,v,A,B);return R(g.beta,D,C,w,L)}else return V.unsafe(v,E)}toAffine(p){let g=this,v=p,{X:E,Y:w,Z:A}=g;if(n.eql(A,n.ONE))return{x:E,y:w};let L=g.is0();v==null&&(v=L?n.ONE:n.inv(A));let B=n.mul(E,v),D=n.mul(w,v),C=n.mul(A,v);if(L)return{x:n.ZERO,y:n.ZERO};if(!n.eql(C,n.ONE))throw new Error("invZ was invalid");return{x:B,y:D}}isTorsionFree(){let{isTorsionFree:p}=e;return o===ct?!0:p?p(T,this):V.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:p}=e;return o===ct?this:p?p(T,this):this.multiplyUnsafe(o)}isSmallOrder(){return o===ct?this.is0():this.clearCofactor().is0()}toBytes(p=!0){return _e(p,"isCompressed"),this.assertValidity(),m(T,this,p)}toHex(p=!0){return Ft(this.toBytes(p))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let O=i.BITS,V=new Vt(T,e.endo?Math.ceil(O/2):O);return O>=8&&T.BASE.precompute(8),Object.freeze(T.prototype),Object.freeze(T),T}function ma(t){return Uint8Array.of(t?2:3)}function ya(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function Ef(t,e={}){let{Fn:r}=t,n=e.randomBytes===void 0?or:e.randomBytes,i=Object.assign(ya(t.Fp,r),{seed:Math.max(ms(r.ORDER),16)});function s(d){try{let m=r.fromBytes(d);return r.isValidNot0(m)}catch{return!1}}function o(d,m){let{publicKey:x,publicKeyUncompressed:y}=i;try{let b=d.length;return m===!0&&b!==x||m===!1&&b!==y?!1:!!t.fromBytes(d)}catch{return!1}}function a(d){return d=d===void 0?n(i.seed):d,ys(U(d,i.seed,"seed"),r.ORDER)}function c(d,m=!0){return t.BASE.multiply(r.fromBytes(d)).toBytes(m)}function u(d){let{secretKey:m,publicKey:x,publicKeyUncompressed:y}=i,b=r._lengths;if(!mt(d))return;let S=U(d,void 0,"key").length,I=S===x||S===y,k=S===m||!!b?.includes(S);if(!(I&&k))return I}function f(d,m,x=!0){if(u(d)===!0)throw new Error("first arg must be private key");if(u(m)===!1)throw new Error("second arg must be public key");let y=r.fromBytes(d);return t.fromBytes(m).multiply(y).toBytes(x)}let l={isValidSecretKey:s,isValidPublicKey:o,randomSecretKey:a},h=nn(a,c);return Object.freeze(l),Object.freeze(i),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:h,Point:t,utils:l,lengths:i})}function ba(t,e,r={}){let n=e;zr(n),ke(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let i=r.randomBytes===void 0?or:r.randomBytes,s=r.hmac===void 0?(E,w)=>la(n,E,w):r.hmac,{Fp:o,Fn:a}=t,{ORDER:c,BITS:u}=a,{keygen:f,getPublicKey:l,getSharedSecret:h,utils:d,lengths:m}=Ef(t,r),x={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},y=c*da+ct<o.ORDER;function b(E){let w=c>>ct;return E>w}function S(E,w){if(!a.isValidNot0(w))throw new Error(`invalid signature ${E}: out of range 1..Point.Fn.ORDER`);return w}function I(){if(y)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function k(E,w){ii(w);let A=m.signature,L=w==="compact"?A:w==="recovered"?A+1:void 0;return U(E,L)}class _{r;s;recovery;constructor(w,A,L){if(this.r=S("r",w),this.s=S("s",A),L!=null){if(I(),![0,1,2,3].includes(L))throw new Error("invalid recovery id");this.recovery=L}Object.freeze(this)}static fromBytes(w,A=x.format){k(w,A);let L;if(A==="der"){let{r:K,s:M}=Ce.toSig(U(w));return new _(K,M)}A==="recovered"&&(L=w[0],A="compact",w=w.subarray(1));let B=m.signature/2,D=w.subarray(0,B),C=w.subarray(B,B*2);return new _(a.fromBytes(D),a.fromBytes(C),L)}static fromHex(w,A){return this.fromBytes(Nt(w),A)}assertRecovery(){let{recovery:w}=this;if(w==null)throw new Error("invalid recovery id: must be present");return w}addRecoveryBit(w){return new _(this.r,this.s,w)}recoverPublicKey(w){let{r:A,s:L}=this,B=this.assertRecovery(),D=B===2||B===3?A+c:A;if(!o.isValid(D))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let C=o.toBytes(D),K=t.fromBytes(re(ma((B&1)===0),C)),M=a.inv(D),N=R(U(w,void 0,"msgHash")),te=a.create(-N*M),ne=a.create(L*M),se=t.BASE.multiplyUnsafe(te).add(K.multiplyUnsafe(ne));if(se.is0())throw new Error("invalid recovery: point at infinify");return se.assertValidity(),se}hasHighS(){return b(this.s)}toBytes(w=x.format){if(ii(w),w==="der")return Nt(Ce.hexFromSig(this));let{r:A,s:L}=this,B=a.toBytes(A),D=a.toBytes(L);return w==="recovered"?(I(),re(Uint8Array.of(this.assertRecovery()),B,D)):re(B,D)}toHex(w){return Ft(this.toBytes(w))}}Object.freeze(_.prototype),Object.freeze(_);let P=r.bits2int===void 0?function(w){if(w.length>8192)throw new Error("input is too large");let A=yt(w),L=w.length*8-u;return L>0?A>>BigInt(L):A}:r.bits2int,R=r.bits2int_modN===void 0?function(w){return a.create(P(w))}:r.bits2int_modN,T=ur(u);function O(E){return Kt("num < 2^"+u,E,Ke,T),a.toBytes(E)}function V(E,w){return U(E,void 0,"message"),w?U(n(E),void 0,"prehashed message"):E}function F(E,w,A){let{lowS:L,prehash:B,extraEntropy:D}=si(A,x);E=V(E,B);let C=R(E),K=a.fromBytes(w);if(!a.isValidNot0(K))throw new Error("invalid private key");let M=[O(K),O(C)];if(D!=null&&D!==!1){let se=D===!0?i(m.secretKey):D;M.push(U(se,void 0,"extraEntropy"))}let N=re(...M),te=C;function ne(se){let W=P(se);if(!a.isValidNot0(W))return;let pe=a.inv(W),It=t.BASE.multiply(W).toAffine(),Yt=a.create(It.x);if(Yt===Ke)return;let Fr=a.create(pe*a.create(te+Yt*K));if(Fr===Ke)return;let Si=(It.x===Yt?0:2)|Number(It.y&ct),Ai=Fr;return L&&b(Fr)&&(Ai=a.neg(Fr),Si^=1),new _(Yt,Ai,y?void 0:Si)}return{seed:N,k2sig:ne}}function p(E,w,A={}){let{seed:L,k2sig:B}=F(E,w,A);return wo(n.outputLen,a.BYTES,s)(L,B).toBytes(A.format)}function g(E,w,A,L={}){let{lowS:B,prehash:D,format:C}=si(L,x);if(A=U(A,void 0,"publicKey"),w=V(w,D),!mt(E)){let K=E instanceof _?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+K)}k(E,C);try{let K=_.fromBytes(E,C),M=t.fromBytes(A);if(B&&K.hasHighS())return!1;let{r:N,s:te}=K,ne=R(w),se=a.inv(te),W=a.create(ne*se),pe=a.create(N*se),It=t.BASE.multiplyUnsafe(W).add(M.multiplyUnsafe(pe));return It.is0()?!1:a.create(It.x)===N}catch{return!1}}function v(E,w,A={}){let{prehash:L}=si(A,x);return w=V(w,L),_.fromBytes(E,"recovered").recoverPublicKey(w).toBytes()}return Object.freeze({keygen:f,getPublicKey:l,getSharedSecret:h,utils:d,lengths:m,Point:t,sign:p,verify:g,recoverPublicKey:v,Signature:_,hash:n})}var ci={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},vf={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var ga=BigInt(2);function Sf(t){let e=ci.p,r=BigInt(3),n=BigInt(6),i=BigInt(11),s=BigInt(22),o=BigInt(23),a=BigInt(44),c=BigInt(88),u=t*t*t%e,f=u*u*t%e,l=$(f,r,e)*f%e,h=$(l,r,e)*f%e,d=$(h,ga,e)*u%e,m=$(d,i,e)*d%e,x=$(m,s,e)*m%e,y=$(x,a,e)*x%e,b=$(y,c,e)*y%e,S=$(b,a,e)*x%e,I=$(S,r,e)*f%e,k=$(I,o,e)*m%e,_=$(k,n,e)*u%e,P=$(_,ga,e);if(!ai.eql(ai.sqr(P),t))throw new Error("Cannot find square root");return P}var ai=Mt(ci.p,{sqrt:Sf}),Af=pa(ci,{Fp:ai,endo:vf}),$t=ba(Af,Ot);function wa(t,e,r,n){let i=ht.digest(r instanceof Uint8Array?r:r.subarray());if(cn(i))return i.then(({digest:s})=>(n?.signal?.throwIfAborted(),$t.verify(e,s,t,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new dr(String(s))});try{return n?.signal?.throwIfAborted(),$t.verify(e,i.digest,t,{prehash:!1,format:"der"})}catch(s){throw new dr(String(s))}}var yn=class{type="secp256k1";raw;_key;constructor(e){this._key=Ea(e),this.raw=xa(this._key)}toMultihash(){return Te.digest(Ve(this))}toCID(){return ue.createV1(114,this.toMultihash())}toString(){return Z.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ye(this.raw,e.raw)}verify(e,r,n){return wa(this._key,r,e,n)}};function ui(t){return new yn(t)}function xa(t){return $t.Point.fromBytes(t).toBytes()}function Ea(t){try{return $t.Point.fromBytes(t),t}catch(e){throw new Bt(String(e))}}function fi(t,e){let{Type:r,Data:n}=Ne.decode(t),i=n??new Uint8Array;switch(r){case Y.RSA:return ti(i,e);case Y.Ed25519:return _s(i);case Y.secp256k1:return ui(i);case Y.ECDSA:return Jn(i);default:throw new ut}}function va(t){let{Type:e,Data:r}=Ne.decode(t.digest),n=r??new Uint8Array;switch(e){case Y.Ed25519:return _s(n);case Y.secp256k1:return ui(n);case Y.ECDSA:return Jn(n);default:throw new ut}}function Ve(t){return Ne.encode({Type:Y[t.type],Data:t.raw})}var Sa=Symbol.for("nodejs.util.inspect.custom"),If=114,wr=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()})`}[An]=!0;toString(){return this.string==null&&(this.string=Z.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ue.createV1(If,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return ye(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return ye(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[Sa](){return`PeerId(${this.toString()})`}},xr=class extends wr{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Er=class extends wr{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},vr=class extends wr{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},Bf=2336,bn=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=Te.digest(z(this.url))}[Sa](){return`PeerId(${this.url})`}[An]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ue.createV1(Bf,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=H(e)),e.toString()===this.toString())}};function li(t){if(t.type==="Ed25519")return new Er({multihash:t.toCID().multihash,publicKey:t});if(t.type==="secp256k1")return new vr({multihash:t.toCID().multihash,publicKey:t});if(t.type==="RSA")return new xr({multihash:t.toCID().multihash,publicKey:t});throw new ut}function Aa(t){return li(t.publicKey)}function Sr(t){if(Lf(t))return new xr({multihash:t});if(Tf(t))try{let e=va(t);if(e.type==="Ed25519")return new Er({multihash:t,publicKey:e});if(e.type==="secp256k1")return new vr({multihash:t,publicKey:e})}catch{let r=H(t.digest);return new bn(new URL(r))}throw new Kr("Supplied PeerID Multihash is invalid")}function Tf(t){return t.code===Te.code}function Lf(t){return t.code===ht.code}function vt(t,e){let r={[Symbol.iterator]:()=>r,next:()=>{let n=t.next(),i=n.value;return n.done===!0||i==null?{done:!0,value:void 0}:{done:!1,value:e(i)}}};return r}function gn(t){let e=Xe(Z.decode(`z${t}`));return Sr(e)}var Ar=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 vt(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 vt(this.map.values(),e=>e.key)}values(){return vt(this.map.values(),e=>e.value)}get size(){return this.map.size}};var Ir=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 vt(this.set.entries(),e=>{let r=gn(e[0]);return[r,r]})}forEach(e){this.set.forEach(r=>{let n=gn(r);e(n,n,this)})}has(e){return this.set.has(e.toString())}values(){return vt(this.set.values(),e=>gn(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 hi=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},Ia=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function Br(t,e){let{milliseconds:r,fallback:n,message:i,customTimers:s={setTimeout,clearTimeout},signal:o}=e,a,c,f=new Promise((l,h)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(o?.aborted){h(Ia(o));return}if(o&&(c=()=>{h(Ia(o))},o.addEventListener("abort",c,{once:!0})),t.then(l,h),r===Number.POSITIVE_INFINITY)return;let d=new hi;a=s.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(m){h(m)}return}typeof t.cancel=="function"&&t.cancel(),i===!1?l():i instanceof Error?h(i):(d.message=i??`Promise timed out after ${r} milliseconds`,h(d))},r)}).finally(()=>{f.clear(),c&&o&&o.removeEventListener("abort",c)});return f.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},f}var _f=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 Df(t,e,r){let n,i=new Promise((s,o)=>{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}=_f(t),l=async(...d)=>{let m=r.multiArgs?d:d[0];if(r.filter)try{if(!await r.filter(m))return}catch(x){n(),o(x);return}c.push(m),r.count===c.length&&(n(),s(c))},h=(...d)=>{n(),o(r.rejectionMultiArgs?d:d[0])};n=()=>{for(let d of a)f(d,l);for(let d of r.rejectionEvents)a.includes(d)||f(d,h)};for(let d of a)u(d,l);for(let d of r.rejectionEvents)a.includes(d)||u(d,h);r.signal&&r.signal.addEventListener("abort",()=>{h(r.signal.reason)},{once:!0}),r.resolveImmediately&&s(c)});if(i.cancel=n,typeof r.timeout=="number"){let s=Br(i,{milliseconds:r.timeout});return s.cancel=()=>{n(),s.clear()},s}return i}function Ba(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=Df(t,e,r),i=n.then(s=>s[0]);return i.cancel=n.cancel,i}var St=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function kf(t){return t.reason}async function di(t,e,r){if(e==null)return t;let n=r?.translateError??kf;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let i;try{return await Promise.race([t,new Promise((s,o)=>{i=()=>{o(n(e))},e.addEventListener("abort",i)})])}finally{i!=null&&e.removeEventListener("abort",i)}}var Cf=4194304,wn=class extends Error{static name="UnwrappedError";name="UnwrappedError"},mi=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},yi=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},bi=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Pf(t){return typeof t?.closeRead=="function"}function Of(t){return typeof t?.close=="function"}function pi(t){return Pf(t)?t.remoteWriteStatus!=="writable"&&t.readBufferLength===0:Of(t)?t.status!=="open":!1}function Ff(t){return t?.addEventListener!=null&&t?.removeEventListener!=null&&t?.send!=null&&t?.push!=null&&t?.log!=null}function Nf(t,e){let r=e?.maxBufferSize??Cf,n=new ie,i,s=!1;if(!Ff(t))throw new j("Argument should be a Stream or a Multiaddr");let o=f=>{if(n.append(f.data),n.byteLength>r){let l=n.byteLength;n.consume(n.byteLength),i?.reject(new Error(`Read buffer overflow - ${l} > ${r}`))}i?.resolve()};t.addEventListener("message",o);let a=f=>{f.error!=null?i?.reject(f.error):i?.resolve()};t.addEventListener("close",a);let c=()=>{i?.resolve()};t.addEventListener("remoteCloseWrite",c);let u={readBuffer:n,async read(f){if(s===!0)throw new wn("Stream was unwrapped");if(pi(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 St(`Unexpected EOF - stream closed after reading ${n.byteLength}/${f.bytes} bytes`)}let l=f?.bytes??1;for(i=Promise.withResolvers();;){if(n.byteLength>=l){i.resolve();break}if(await di(i.promise,f?.signal),pi(t)){if(n.byteLength===0&&f?.bytes==null)return null;break}i=Promise.withResolvers()}let h=f?.bytes??n.byteLength;if(n.byteLength<h){if(pi(t))throw t.log.error("closed while reading %d/%d bytes",n.byteLength,h),new St(`Unexpected EOF - stream closed while reading ${n.byteLength}/${h} bytes`);return u.read(f)}let d=n.sublist(0,h);return n.consume(h),d},async write(f,l){if(s===!0)throw new wn("Stream was unwrapped");t.send(f)||await Ba(t,"drain",{signal:l?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,t.removeEventListener("message",o),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 Kf(t,e={}){let r=Nf(t,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=Ye(e.maxDataLength));let n=e?.lengthDecoder??Yo,i=e?.lengthEncoder??Zo;return{async read(o){let a=-1,c=new ie;for(;;){let f=await r.read({...o,bytes:1});if(f==null)break;c.append(f);try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new mi("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new bi(`Message length length too long - ${c.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new yi(`Message length too long - ${a} > ${e.maxDataLength}`);let u=await r.read({...o,bytes:a});if(u==null)throw t.log.error("tried to read %d bytes but the stream closed",a),new St(`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 St(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(o,a){await r.write(new ie(i(o.byteLength),o),a)},async writeV(o,a){let c=new ie(...o.flatMap(u=>[i(u.byteLength),u]));await r.write(c,a)},unwrap(){return r.unwrap()}}}function gi(t,e){let r=Kf(t,e),n={read:async(i,s)=>{let o=await r.read(s);return i.decode(o)},write:async(i,s,o)=>{await r.write(s.encode(i),o)},writeV:async(i,s,o)=>{await r.writeV(i.map(a=>s.encode(a)),o)},pb:i=>({read:async s=>n.read(i,s),write:async(s,o)=>n.write(s,i,o),writeV:async(s,o)=>n.writeV(s,i,o),unwrap:()=>n}),unwrap:()=>r.unwrap()};return n}var xi=Va(La(),1);function Ei(t,e,r){let n=0,i=t.length;for(;i>0;){let s=Math.trunc(i/2),o=n+s;r(t[o],e)<=0?(n=++o,i-=s+1):i=s}return n}var qf=100,jt=class{#e=[];#t=0;enqueue(e,r){let{priority:n=0,id:i}=r??{},{size:s}=this,o={priority:n,id:i,run:e};if(s===0){this.#e.length=0,this.#t=0,this.#e.push(o);return}if(this.#e.at(-1).priority>=n){this.#e.push(o);return}this.#i();let a=Ei(this.#e,o,(c,u)=>u.priority-c.priority);this.#e.splice(a,0,o)}setPriority(e,r){let n=this.#e.findIndex((s,o)=>o>=this.#t&&s.id===e);if(n===-1)throw new ReferenceError(`No promise function with the id "${e}" exists in the queue.`);let[i]=this.#e.splice(n,1);this.enqueue(i.run,{priority:r,id:e})}remove(e){let r=this.#e.findIndex((n,i)=>i<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>qf&&this.#t>this.#e.length/2&&this.#i(),e?.run}filter(e){let r=[];for(let n=this.#t;n<this.#e.length;n++){let i=this.#e[n];i.priority===e.priority&&r.push(i.run)}return r}get size(){return this.#e.length-this.#t}#i(){this.#t!==0&&(this.#e.splice(0,this.#t),this.#t=0)}};var Lr=class extends xi.default{#e;#t;#i=0;#d;#m=!1;#w=!1;#c;#T=0;#x=0;#u;#f;#a;#o=[];#s=0;#r;#L;#n=0;#y;#l;#C=1n;#b=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:jt,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.#s<this.#o.length;){let n=this.#o[this.#s];if(n!==void 0&&e-n>=this.#c)this.#s++;else break}(this.#s>100&&this.#s>this.#o.length/2||this.#s===this.#o.length)&&(this.#o=this.#o.slice(this.#s),this.#s=0)}#P(e){this.#a?this.#o.push(e):this.#i++}#O(){this.#a?this.#o.length>this.#s&&this.#o.pop():this.#i>0&&this.#i--}#S(){return this.#o.length-this.#s}get#F(){return this.#t?!0:this.#a?this.#S()<this.#d:this.#i<this.#d}get#N(){return this.#n<this.#y}#K(){this.#n--,this.#n===0&&this.emit("pendingZero"),this.#g(),this.emit("next")}#U(){this.#f=void 0,this.#k(),this.#D()}#M(e){if(this.#a){if(this.#v(e),this.#S()>=this.#d){let n=this.#o[this.#s],i=this.#c-(e-n);return this.#A(i),!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.#i=this.#e?this.#n:0}else return this.#A(r),!0}return!1}#A(e){this.#f===void 0&&(this.#f=setTimeout(()=>{this.#U()},e))}#I(){this.#u&&(clearInterval(this.#u),this.#u=void 0)}#_(){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.#_(),this.#a&&this.#s>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.#F&&this.#N){let i=this.#r.dequeue();this.#t||(this.#P(r),this.#p()),this.emit("active"),i(),n&&this.#D(),e=!0}}return e}#D(){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.#i===0&&this.#n===0&&this.#u&&this.#I(),this.#i=this.#e?this.#n:0),this.#B(),this.#p()}#B(){for(;this.#g(););}get concurrency(){return this.#y}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.#y=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.#C++).toString()},new Promise((n,i)=>{let s=Symbol(`task-${r.id}`),o=()=>{},a=async()=>{o(),this.#n++,this.#b.set(s,{id:r.id,priority:r.priority??0,startTime:Date.now(),timeout:r.timeout});let u;try{try{r.signal?.throwIfAborted()}catch(h){throw this.#V(),this.#b.delete(s),h}this.#x=Date.now();let f=e({signal:r.signal});if(r.timeout&&(f=Br(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:h}=r;f=Promise.race([f,new Promise((d,m)=>{u=()=>{m(h.reason)},h.addEventListener("abort",u,{once:!0})})])}let l=await f;n(l),this.emit("completed",l)}catch(f){i(f),this.emit("error",f)}finally{u&&r.signal?.removeEventListener("abort",u),this.#b.delete(s),queueMicrotask(()=>{this.#K()})}};this.#r.enqueue(a,r);let c=()=>{if(this.#r instanceof jt){this.#r.remove(a);return}this.#r.remove?.(r.id)};if(r.signal){let{signal:u}=r,f=()=>{o(),c(),i(u.reason),this.#g(),this.emit("next")};if(o=()=>{u.removeEventListener("abort",f),this.#E.delete(o)},u.aborted){f();return}u.addEventListener("abort",f,{once:!0}),this.#E.add(o)}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.#R(),this.emit("empty"),this.#n===0&&(this.#_(),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=i=>{this.off("error",n),r(i)};this.on("error",n)})}async#h(e,r){return new Promise(n=>{let i=()=>{r&&!r()||(this.off(e,i),n())};this.on(e,i)})}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.#R()}))}#V(){this.#t||(this.#O(),this.#p())}#R(){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 i=Date.now();this.#v(i),r=this.#S()}else r=this.#i;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.#y&&this.#r.size>0||this.isRateLimited&&this.#r.size>0}get runningTasks(){return[...this.#b.values()].map(e=>({...e,timeoutRemaining:e.timeout?Math.max(0,e.startTime+e.timeout-Date.now()):void 0}))}};var En=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 At;(function(t){let e;(function(a){let c;a.codec=()=>(c==null&&(c=ve((h,d,m={})=>{m.lengthDelimited!==!1&&d.fork(),h.subscribe!=null&&(d.uint32(8),d.bool(h.subscribe)),h.topic!=null&&(d.uint32(18),d.string(h.topic)),m.lengthDelimited!==!1&&d.ldelim()},(h,d,m={})=>{let x={},y=d==null?h.len:h.pos+d;for(;h.pos<y;){let b=h.uint32();switch(b>>>3){case 1:{x.subscribe=h.bool();break}case 2:{x.topic=h.string();break}default:{h.skipType(b&7);break}}}return x},function*(h,d,m,x={}){let y=d==null?h.len:h.pos+d;for(;h.pos<y;){let b=h.uint32();switch(b>>>3){case 1:{yield{field:`${m}.subscribe`,value:h.bool()};break}case 2:{yield{field:`${m}.topic`,value:h.string()};break}default:{h.skipType(b&7);break}}}})),c);function u(h){return xe(h,a.codec())}a.encode=u;function f(h,d){return we(h,a.codec(),d)}a.decode=f;function l(h,d){return Ee(h,a.codec(),d)}a.stream=l})(e=t.SubOpts||(t.SubOpts={}));let r;(function(a){let c;a.codec=()=>(c==null&&(c=ve((h,d,m={})=>{m.lengthDelimited!==!1&&d.fork(),h.from!=null&&(d.uint32(10),d.bytes(h.from)),h.data!=null&&(d.uint32(18),d.bytes(h.data)),h.sequenceNumber!=null&&(d.uint32(26),d.bytes(h.sequenceNumber)),h.topic!=null&&(d.uint32(34),d.string(h.topic)),h.signature!=null&&(d.uint32(42),d.bytes(h.signature)),h.key!=null&&(d.uint32(50),d.bytes(h.key)),m.lengthDelimited!==!1&&d.ldelim()},(h,d,m={})=>{let x={},y=d==null?h.len:h.pos+d;for(;h.pos<y;){let b=h.uint32();switch(b>>>3){case 1:{x.from=h.bytes();break}case 2:{x.data=h.bytes();break}case 3:{x.sequenceNumber=h.bytes();break}case 4:{x.topic=h.string();break}case 5:{x.signature=h.bytes();break}case 6:{x.key=h.bytes();break}default:{h.skipType(b&7);break}}}return x},function*(h,d,m,x={}){let y=d==null?h.len:h.pos+d;for(;h.pos<y;){let b=h.uint32();switch(b>>>3){case 1:{yield{field:`${m}.from`,value:h.bytes()};break}case 2:{yield{field:`${m}.data`,value:h.bytes()};break}case 3:{yield{field:`${m}.sequenceNumber`,value:h.bytes()};break}case 4:{yield{field:`${m}.topic`,value:h.string()};break}case 5:{yield{field:`${m}.signature`,value:h.bytes()};break}case 6:{yield{field:`${m}.key`,value:h.bytes()};break}default:{h.skipType(b&7);break}}}})),c);function u(h){return xe(h,a.codec())}a.encode=u;function f(h,d){return we(h,a.codec(),d)}a.decode=f;function l(h,d){return Ee(h,a.codec(),d)}a.stream=l})(r=t.Message||(t.Message={}));let n;t.codec=()=>(n==null&&(n=ve((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),_r.codec().encode(a.control,c)),u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={subscriptions:[],messages:[]},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let h=a.uint32();switch(h>>>3){case 1:{if(u.limits?.subscriptions!=null&&f.subscriptions.length===u.limits.subscriptions)throw new ee('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 ee('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=_r.codec().decode(a,a.uint32(),{limits:u.limits?.control});break}default:{a.skipType(h&7);break}}}return f},function*(a,c,u,f={}){let l={subscriptions:0,messages:0},h=c==null?a.len:a.pos+c;for(;a.pos<h;){let d=a.uint32();switch(d>>>3){case 1:{if(f.limits?.subscriptions!=null&&l.subscriptions===f.limits.subscriptions)throw new ee('Streaming decode error - repeated field "subscriptions" had too many elements');for(let m of t.SubOpts.codec().stream(a,a.uint32(),`${u}.subscriptions[]`,{limits:f.limits?.subscriptions$}))yield{...m,index:l.subscriptions};l.subscriptions++;break}case 2:{if(f.limits?.messages!=null&&l.messages===f.limits.messages)throw new ee('Streaming decode error - repeated field "messages" had too many elements');for(let m of t.Message.codec().stream(a,a.uint32(),`${u}.messages[]`,{limits:f.limits?.messages$}))yield{...m,index:l.messages};l.messages++;break}case 3:{yield*_r.codec().stream(a,a.uint32(),`${u}.control`,{limits:f.limits?.control});break}default:{a.skipType(d&7);break}}}})),n);function i(a){return xe(a,t.codec())}t.encode=i;function s(a,c){return we(a,t.codec(),c)}t.decode=s;function o(a,c){return Ee(a,t.codec(),c)}t.stream=o})(At||(At={}));var _r;(function(t){let e;t.codec=()=>(e==null&&(e=ve((s,o,a={})=>{if(a.lengthDelimited!==!1&&o.fork(),s.ihave!=null&&s.ihave.length>0)for(let c of s.ihave)o.uint32(10),Dr.codec().encode(c,o);if(s.iwant!=null&&s.iwant.length>0)for(let c of s.iwant)o.uint32(18),kr.codec().encode(c,o);if(s.graft!=null&&s.graft.length>0)for(let c of s.graft)o.uint32(26),Rr.codec().encode(c,o);if(s.prune!=null&&s.prune.length>0)for(let c of s.prune)o.uint32(34),Cr.codec().encode(c,o);a.lengthDelimited!==!1&&o.ldelim()},(s,o,a={})=>{let c={ihave:[],iwant:[],graft:[],prune:[]},u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{if(a.limits?.ihave!=null&&c.ihave.length===a.limits.ihave)throw new ee('Decode error - repeated field "ihave" had too many elements');c.ihave.push(Dr.codec().decode(s,s.uint32(),{limits:a.limits?.ihave$}));break}case 2:{if(a.limits?.iwant!=null&&c.iwant.length===a.limits.iwant)throw new ee('Decode error - repeated field "iwant" had too many elements');c.iwant.push(kr.codec().decode(s,s.uint32(),{limits:a.limits?.iwant$}));break}case 3:{if(a.limits?.graft!=null&&c.graft.length===a.limits.graft)throw new ee('Decode error - repeated field "graft" had too many elements');c.graft.push(Rr.codec().decode(s,s.uint32(),{limits:a.limits?.graft$}));break}case 4:{if(a.limits?.prune!=null&&c.prune.length===a.limits.prune)throw new ee('Decode error - repeated field "prune" had too many elements');c.prune.push(Cr.codec().decode(s,s.uint32(),{limits:a.limits?.prune$}));break}default:{s.skipType(f&7);break}}}return c},function*(s,o,a,c={}){let u={ihave:0,iwant:0,graft:0,prune:0},f=o==null?s.len:s.pos+o;for(;s.pos<f;){let l=s.uint32();switch(l>>>3){case 1:{if(c.limits?.ihave!=null&&u.ihave===c.limits.ihave)throw new ee('Streaming decode error - repeated field "ihave" had too many elements');for(let h of Dr.codec().stream(s,s.uint32(),`${a}.ihave[]`,{limits:c.limits?.ihave$}))yield{...h,index:u.ihave};u.ihave++;break}case 2:{if(c.limits?.iwant!=null&&u.iwant===c.limits.iwant)throw new ee('Streaming decode error - repeated field "iwant" had too many elements');for(let h of kr.codec().stream(s,s.uint32(),`${a}.iwant[]`,{limits:c.limits?.iwant$}))yield{...h,index:u.iwant};u.iwant++;break}case 3:{if(c.limits?.graft!=null&&u.graft===c.limits.graft)throw new ee('Streaming decode error - repeated field "graft" had too many elements');for(let h of Rr.codec().stream(s,s.uint32(),`${a}.graft[]`,{limits:c.limits?.graft$}))yield{...h,index:u.graft};u.graft++;break}case 4:{if(c.limits?.prune!=null&&u.prune===c.limits.prune)throw new ee('Streaming decode error - repeated field "prune" had too many elements');for(let h of Cr.codec().stream(s,s.uint32(),`${a}.prune[]`,{limits:c.limits?.prune$}))yield{...h,index:u.prune};u.prune++;break}default:{s.skipType(l&7);break}}}})),e);function r(s){return xe(s,t.codec())}t.encode=r;function n(s,o){return we(s,t.codec(),o)}t.decode=n;function i(s,o){return Ee(s,t.codec(),o)}t.stream=i})(_r||(_r={}));var Dr;(function(t){let e;t.codec=()=>(e==null&&(e=ve((s,o,a={})=>{if(a.lengthDelimited!==!1&&o.fork(),s.topic!=null&&(o.uint32(10),o.string(s.topic)),s.messageIDs!=null&&s.messageIDs.length>0)for(let c of s.messageIDs)o.uint32(18),o.bytes(c);a.lengthDelimited!==!1&&o.ldelim()},(s,o,a={})=>{let c={messageIDs:[]},u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.topic=s.string();break}case 2:{if(a.limits?.messageIDs!=null&&c.messageIDs.length===a.limits.messageIDs)throw new ee('Decode error - repeated field "messageIDs" had too many elements');c.messageIDs.push(s.bytes());break}default:{s.skipType(f&7);break}}}return c},function*(s,o,a,c={}){let u={messageIDs:0},f=o==null?s.len:s.pos+o;for(;s.pos<f;){let l=s.uint32();switch(l>>>3){case 1:{yield{field:`${a}.topic`,value:s.string()};break}case 2:{if(c.limits?.messageIDs!=null&&u.messageIDs===c.limits.messageIDs)throw new ee('Streaming decode error - repeated field "messageIDs" had too many elements');yield{field:`${a}.messageIDs[]`,index:u.messageIDs,value:s.bytes()},u.messageIDs++;break}default:{s.skipType(l&7);break}}}})),e);function r(s){return xe(s,t.codec())}t.encode=r;function n(s,o){return we(s,t.codec(),o)}t.decode=n;function i(s,o){return Ee(s,t.codec(),o)}t.stream=i})(Dr||(Dr={}));var kr;(function(t){let e;t.codec=()=>(e==null&&(e=ve((s,o,a={})=>{if(a.lengthDelimited!==!1&&o.fork(),s.messageIDs!=null&&s.messageIDs.length>0)for(let c of s.messageIDs)o.uint32(10),o.bytes(c);a.lengthDelimited!==!1&&o.ldelim()},(s,o,a={})=>{let c={messageIDs:[]},u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{if(a.limits?.messageIDs!=null&&c.messageIDs.length===a.limits.messageIDs)throw new ee('Decode error - repeated field "messageIDs" had too many elements');c.messageIDs.push(s.bytes());break}default:{s.skipType(f&7);break}}}return c},function*(s,o,a,c={}){let u={messageIDs:0},f=o==null?s.len:s.pos+o;for(;s.pos<f;){let l=s.uint32();switch(l>>>3){case 1:{if(c.limits?.messageIDs!=null&&u.messageIDs===c.limits.messageIDs)throw new ee('Streaming decode error - repeated field "messageIDs" had too many elements');yield{field:`${a}.messageIDs[]`,index:u.messageIDs,value:s.bytes()},u.messageIDs++;break}default:{s.skipType(l&7);break}}}})),e);function r(s){return xe(s,t.codec())}t.encode=r;function n(s,o){return we(s,t.codec(),o)}t.decode=n;function i(s,o){return Ee(s,t.codec(),o)}t.stream=i})(kr||(kr={}));var Rr;(function(t){let e;t.codec=()=>(e==null&&(e=ve((s,o,a={})=>{a.lengthDelimited!==!1&&o.fork(),s.topic!=null&&(o.uint32(10),o.string(s.topic)),a.lengthDelimited!==!1&&o.ldelim()},(s,o,a={})=>{let c={},u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();f>>>3===1?c.topic=s.string():s.skipType(f&7)}return c},function*(s,o,a,c={}){let u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();f>>>3===1?yield{field:`${a}.topic`,value:s.string()}:s.skipType(f&7)}})),e);function r(s){return xe(s,t.codec())}t.encode=r;function n(s,o){return we(s,t.codec(),o)}t.decode=n;function i(s,o){return Ee(s,t.codec(),o)}t.stream=i})(Rr||(Rr={}));var Cr;(function(t){let e;t.codec=()=>(e==null&&(e=ve((s,o,a={})=>{if(a.lengthDelimited!==!1&&o.fork(),s.topic!=null&&(o.uint32(10),o.string(s.topic)),s.peers!=null&&s.peers.length>0)for(let c of s.peers)o.uint32(18),Pr.codec().encode(c,o);s.backoff!=null&&(o.uint32(24),o.uint64(s.backoff)),a.lengthDelimited!==!1&&o.ldelim()},(s,o,a={})=>{let c={peers:[]},u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.topic=s.string();break}case 2:{if(a.limits?.peers!=null&&c.peers.length===a.limits.peers)throw new ee('Decode error - repeated field "peers" had too many elements');c.peers.push(Pr.codec().decode(s,s.uint32(),{limits:a.limits?.peers$}));break}case 3:{c.backoff=s.uint64();break}default:{s.skipType(f&7);break}}}return c},function*(s,o,a,c={}){let u={peers:0},f=o==null?s.len:s.pos+o;for(;s.pos<f;){let l=s.uint32();switch(l>>>3){case 1:{yield{field:`${a}.topic`,value:s.string()};break}case 2:{if(c.limits?.peers!=null&&u.peers===c.limits.peers)throw new ee('Streaming decode error - repeated field "peers" had too many elements');for(let h of Pr.codec().stream(s,s.uint32(),`${a}.peers[]`,{limits:c.limits?.peers$}))yield{...h,index:u.peers};u.peers++;break}case 3:{yield{field:`${a}.backoff`,value:s.uint64()};break}default:{s.skipType(l&7);break}}}})),e);function r(s){return xe(s,t.codec())}t.encode=r;function n(s,o){return we(s,t.codec(),o)}t.decode=n;function i(s,o){return Ee(s,t.codec(),o)}t.stream=i})(Cr||(Cr={}));var Pr;(function(t){let e;t.codec=()=>(e==null&&(e=ve((s,o,a={})=>{a.lengthDelimited!==!1&&o.fork(),s.peerID!=null&&(o.uint32(10),o.bytes(s.peerID)),s.signedPeerRecord!=null&&(o.uint32(18),o.bytes(s.signedPeerRecord)),a.lengthDelimited!==!1&&o.ldelim()},(s,o,a={})=>{let c={},u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.peerID=s.bytes();break}case 2:{c.signedPeerRecord=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,o,a,c={}){let u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.peerID`,value:s.bytes()};break}case 2:{yield{field:`${a}.signedPeerRecord`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return xe(s,t.codec())}t.encode=r;function n(s,o){return we(s,t.codec(),o)}t.decode=n;function i(s,o){return Ee(s,t.codec(),o)}t.stream=i})(Pr||(Pr={}));var vn=class extends Tt{peerId;shutDownController;inboundPb;outboundPb;constructor(e){super(),this.peerId=e,this.shutDownController=new AbortController}attachInboundStream(e,r){this.inboundPb=gi(e,r).pb(At),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=gi(e,r).pb(At)}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 _a(){return BigInt(`0x${H(crypto.getRandomValues(new Uint8Array(8)),"base16")}`)}var Da=(t,e)=>{let r=z(e.toString(16).padStart(16,"0"),"base16"),n=Ve(t),i=new Uint8Array(n.byteLength+r.length);return i.set(n,0),i.set(r,n.byteLength),i},ka=t=>ht.encode(t);var Vf=async t=>{if(t.sequenceNumber==null||t.from==null||t.signature==null)return!1;let e=Sr(Xe(t.from));if(e.publicKey!=null)return!0;if(t.key!=null){let r=t.key;return li(fi(r)).equals(e)}return!1},Ra=async t=>{if(t.from==null)throw new J("RPC message was missing from");if(!await Vf(t))return{type:"unsigned",topic:t.topic??"",data:t.data??new Uint8Array(0)};let e=Sr(Xe(t.from)),r=t.key??e.publicKey;if(r==null)throw new J("RPC message was missing public key");return{type:"signed",from:e,topic:t.topic??"",sequenceNumber:zf(t.sequenceNumber??new Uint8Array(0)),data:t.data??new Uint8Array(0),signature:t.signature??new Uint8Array(0),key:r instanceof Uint8Array?fi(r):r}},Or=t=>t.type==="signed"?{from:t.from.toMultihash().bytes,data:t.data,sequenceNumber:Hf(t.sequenceNumber),topic:t.topic,signature:t.signature,key:t.key?Ve(t.key):void 0}:{data:t.data,topic:t.topic},Hf=t=>{let e=t.toString(16);return e.length%2!==0&&(e=`0${e}`),z(e,"base16")},zf=t=>BigInt(`0x${H(t,"base16")}`);var Ca=z("libp2p-pubsub:");async function Pa(t,e,r){let n={type:"signed",topic:e.topic,data:e.data,sequenceNumber:e.sequenceNumber,from:Aa(t)},i=lt([Ca,r(Or(n)).subarray()]);return n.signature=await t.sign(i),n.key=t.publicKey,n}async function Oa(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=lt([Ca,e({...Or(t),signature:void 0,key:void 0}).subarray()]);return $f(t).verify(r,t.signature)}function $f(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 Sn=class extends Tt{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??vi,this.started=!1,this.topics=new Map,this.subscriptions=new Set,this.peers=new Ar,this.globalSignaturePolicy=r.globalSignaturePolicy==="StrictNoSign"?"StrictNoSign":"StrictSign",this.canRelayMessage=r.canRelayMessage??!0,this.emitSelf=r.emitSelf??!1,this.topicValidators=new Map,this.queue=new Lr({concurrency:r.messageProcessingConcurrency??10}),this.maxInboundStreams=r.maxInboundStreams??1,this.maxOutboundStreams=r.maxOutboundStreams??1,this.seenCache=new En({validityMs:r?.seenTTL??3e4}),this._onIncomingStream=this._onIncomingStream.bind(this),this._onPeerConnected=this._onPeerConnected.bind(this),this._onPeerDisconnected=this._onPeerDisconnected.bind(this)}[Gt]=!0;[Symbol.toStringTag]="@libp2p/floodsub";[Bi]=["@libp2p/pubsub"];[Ti]=["@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(s=>s.direction==="outbound"&&s.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(s=>s.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 i=new vn(e);return this.peers.set(e,i),i.addEventListener("message",s=>{let o=s.detail,a=[];for(let c of o.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(i,{subscriptions:(o.subscriptions??[]).map(c=>({subscribe:!!c.subscribe,topic:c.topic??""})),messages:a}).catch(c=>{this.log(c)})}),i.addEventListener("close",()=>this._removePeer(e),{once:!0}),i}_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:i}=r;return n!=null&&n.length>0&&(this.log("subscription update from %p",e.peerId),n.forEach(s=>{this.processRpcSubOpt(e.peerId,s)}),super.dispatchEvent(new CustomEvent("subscription-change",{detail:{peerId:e.peerId,subscriptions:n.map(({topic:s,subscribe:o})=>({topic:`${s??""}`,subscribe:!!o}))}}))),i!=null&&i.length>0&&(this.log("messages from %p",e.peerId),this.queue.addAll(i.map(s=>async()=>{if(s.topic==null||!this.subscriptions.has(s.topic)&&!this.canRelayMessage)return this.log("received message we didn't subscribe to. Dropping."),!1;try{let o=await Ra(s);await this.processMessage(e.peerId,o)}catch(o){this.log.error("failed to queue messages from %p - %e",e.peerId,o)}})).catch(s=>{this.log(s)})),!0}processRpcSubOpt(e,r){let n=r.topic;if(n==null)return;let i=this.topics.get(n);i==null&&(i=new Ir,this.topics.set(n,i)),r.subscribe===!0?i.add(e):i.delete(e)}async processMessage(e,r){if(this.components.peerId.equals(e)&&!this.emitSelf)return;let n=await this.getMsgId(r),i=H(n,"base64");if(!this.seenCache.has(i)){this.seenCache.put(i,!0);try{await this.validate(e,r)}catch(s){this.log("Message is invalid, dropping it. %O",s);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 J('Message type should be "signed" when signature policy is StrictSign but it was not');if(e.sequenceNumber==null)throw new J("Need sequence number when signature policy is StrictSign but it was missing");if(e.key==null)throw new J("Need key when signature policy is StrictSign but it was missing");return Da(e.key,e.sequenceNumber);case"StrictNoSign":return ka(e.data);default:throw new J("Cannot get message id: unhandled signature policy")}}encodeMessage(e){return At.Message.encode(e)}send(e,r){let{messages:n,subscriptions:i,subscribe:s}=r;this.sendRpc(e,{subscriptions:(i??[]).map(o=>({topic:o,subscribe:!!s})),messages:(n??[]).map(Or)})}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 J('Message type should be "unsigned" when signature policy is StrictNoSign but it was not');if(r.signature!=null)throw new J("StrictNoSigning: signature should not be present");if(r.key!=null)throw new J("StrictNoSigning: key should not be present");if(r.sequenceNumber!=null)throw new J("StrictNoSigning: seqno should not be present");break;case"StrictSign":if(r.type!=="signed")throw new J('Message type should be "signed" when signature policy is StrictSign but it was not');if(r.signature==null)throw new J("StrictSigning: Signing required and no signature was present");if(r.sequenceNumber==null)throw new J("StrictSigning: Signing required and no sequenceNumber was present");if(!await Oa(r,this.encodeMessage.bind(this)))throw new J("StrictSigning: Invalid message signature");break;default:throw new J("Cannot validate message: unhandled signature policy")}let i=this.topicValidators.get(r.topic);if(i!=null){let s=await i(e,r);if(s===Zt.Reject||s===Zt.Ignore)throw new J("Message validation failed")}}async buildMessage(e){switch(this.globalSignaturePolicy){case"StrictSign":return Pa(this.components.privateKey,e,this.encodeMessage.bind(this));case"StrictNoSign":return Promise.resolve({type:"unsigned",...e});default:throw new J("Cannot build message: unhandled signature policy")}}getSubscribers(e){if(!this.started)throw new Ur("not started yet");if(e==null)throw new j("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:_a()};this.log("publish topic: %s from: %p data: %m",e,n.from,n.data);let i=await this.buildMessage(n),s=!1;this.emitSelf&&this.subscriptions.has(e)&&(s=!0,super.dispatchEvent(new CustomEvent("message",{detail:i})));let o=await this.publishMessage(this.components.peerId,i);return s&&(o.recipients=[...o.recipients,this.components.peerId]),o}async publishMessage(e,r){let n=this.getSubscribers(r.topic),i=[];return n==null||n.length===0?(this.log("no peers are subscribed to topic %s",r.topic),{recipients:i}):(n.forEach(s=>{if(this.components.peerId.equals(s)){this.log("not sending message on topic %s to myself",r.topic);return}if(s.equals(e)){this.log("not sending message on topic %s to sender %p",r.topic,s);return}this.log("publish msgs on topics %s %p",r.topic,s),i.push(s),this.send(s,{messages:[r]})}),{recipients:i})}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 vi="/floodsub/1.0.0",jf="StrictSign",Zf="StrictNoSign",Zt;(function(t){t.Accept="accept",t.Ignore="ignore",t.Reject="reject"})(Zt||(Zt={}));function Yf(t){return!!t?.[Gt]}function Gf(t={}){return e=>new Sn(e,t)}return Ha(Xf);})();
2
+ "use strict";var Libp2PFloodsub=(()=>{var Fa=Object.create;var Fr=Object.defineProperty;var Ka=Object.getOwnPropertyDescriptor;var Ua=Object.getOwnPropertyNames;var Ma=Object.getPrototypeOf,qa=Object.prototype.hasOwnProperty;var Va=(t,e)=>()=>{try{return e||t((e={exports:{}}).exports,e),e.exports}catch(r){throw e=0,r}},me=(t,e)=>{for(var r in e)Fr(t,r,{get:e[r],enumerable:!0})},Ii=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Ua(e))!qa.call(t,i)&&i!==r&&Fr(t,i,{get:()=>e[i],enumerable:!(n=Ka(e,i))||n.enumerable});return t};var Ha=(t,e,r)=>(r=t!=null?Fa(Ma(t)):{},Ii(e||!t||!t.__esModule?Fr(r,"default",{value:t,enumerable:!0}):r,t)),za=t=>Ii(Fr({},"__esModule",{value:!0}),t);var _a=Va((iy,wi)=>{"use strict";var Mf=Object.prototype.hasOwnProperty,de="~";function Tr(){}Object.create&&(Tr.prototype=Object.create(null),new Tr().__proto__||(de=!1));function qf(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function La(t,e,r,n,i){if(typeof r!="function")throw new TypeError("The listener must be a function");var s=new qf(r,n||t,i),o=de?de+e:e;return t._events[o]?t._events[o].fn?t._events[o]=[t._events[o],s]:t._events[o].push(s):(t._events[o]=s,t._eventsCount++),t}function xn(t,e){--t._eventsCount===0?t._events=new Tr:delete t._events[e]}function he(){this._events=new Tr,this._eventsCount=0}he.prototype.eventNames=function(){var e=[],r,n;if(this._eventsCount===0)return e;for(n in r=this._events)Mf.call(r,n)&&e.push(de?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(r)):e};he.prototype.listeners=function(e){var r=de?de+e:e,n=this._events[r];if(!n)return[];if(n.fn)return[n.fn];for(var i=0,s=n.length,o=new Array(s);i<s;i++)o[i]=n[i].fn;return o};he.prototype.listenerCount=function(e){var r=de?de+e:e,n=this._events[r];return n?n.fn?1:n.length:0};he.prototype.emit=function(e,r,n,i,s,o){var a=de?de+e:e;if(!this._events[a])return!1;var c=this._events[a],u=arguments.length,f,l;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,i),!0;case 5:return c.fn.call(c.context,r,n,i,s),!0;case 6:return c.fn.call(c.context,r,n,i,s,o),!0}for(l=1,f=new Array(u-1);l<u;l++)f[l-1]=arguments[l];c.fn.apply(c.context,f)}else{var h=c.length,d;for(l=0;l<h;l++)switch(c[l].once&&this.removeListener(e,c[l].fn,void 0,!0),u){case 1:c[l].fn.call(c[l].context);break;case 2:c[l].fn.call(c[l].context,r);break;case 3:c[l].fn.call(c[l].context,r,n);break;case 4:c[l].fn.call(c[l].context,r,n,i);break;default:if(!f)for(d=1,f=new Array(u-1);d<u;d++)f[d-1]=arguments[d];c[l].fn.apply(c[l].context,f)}}return!0};he.prototype.on=function(e,r,n){return La(this,e,r,n,!1)};he.prototype.once=function(e,r,n){return La(this,e,r,n,!0)};he.prototype.removeListener=function(e,r,n,i){var s=de?de+e:e;if(!this._events[s])return this;if(!r)return xn(this,s),this;var o=this._events[s];if(o.fn)o.fn===r&&(!i||o.once)&&(!n||o.context===n)&&xn(this,s);else{for(var a=0,c=[],u=o.length;a<u;a++)(o[a].fn!==r||i&&!o[a].once||n&&o[a].context!==n)&&c.push(o[a]);c.length?this._events[s]=c.length===1?c[0]:c:xn(this,s)}return this};he.prototype.removeAllListeners=function(e){var r;return e?(r=de?de+e:e,this._events[r]&&xn(this,r)):(this._events=new Tr,this._eventsCount=0),this};he.prototype.off=he.prototype.removeListener;he.prototype.addListener=he.prototype.on;he.prefixed=de;he.EventEmitter=he;typeof wi<"u"&&(wi.exports=he)});var Wf={};me(Wf,{StrictNoSign:()=>Yf,StrictSign:()=>Zf,TopicValidatorResult:()=>Zt,floodsub:()=>Xf,isPubSub:()=>Gf,protocol:()=>vi,pubSubSymbol:()=>Gt});var Gt=Symbol.for("@libp2p/pubsub");var j=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},Bt=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var Kr=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var J=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var Ur=class extends Error{static name="NotStartedError";constructor(e="Not started"){super(e),this.name="NotStartedError"}};var ut=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var An=Symbol.for("@libp2p/peer-id");function $a(t){return typeof t?.handleEvent=="function"}function ja(t){return(t!==!0&&t!==!1&&t?.once)??!1}var Tt=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 i=ja(n);super.addEventListener(e,o=>{if(i){let a=this.#e.get(o.type);a!=null&&(a=a.filter(({callback:c})=>c!==r),this.#e.set(o.type,a))}$a(r)?r.handleEvent(o):r(o)},n);let s=this.#e.get(e);s==null&&(s=[],this.#e.set(e,s)),s.push({callback:r,once:i})}removeEventListener(e,r,n){super.removeEventListener(e.toString(),r??null,n);let i=this.#e.get(e);i!=null&&(i=i.filter(({callback:s})=>s!==r),this.#e.set(e,i))}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};var Bi=Symbol.for("@libp2p/service-capabilities"),Ti=Symbol.for("@libp2p/service-dependencies");var _n={};me(_n,{base58btc:()=>Z,base58flickr:()=>ec});var Ll=new Uint8Array(0);function _i(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 Ie(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return ft(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return ft(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function Di(t){let e=new Uint8Array(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}var Li=4096;function ki(t){let e=t.length;if(e<=Li)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.subarray(n,n+=Li));return r}function Za(t){return t?.buffer instanceof ArrayBuffer}function ft(t){return Za(t)?t:t.slice()}function Ya(t,e,r){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),i=0;i<n.length;i++)n[i]=255;for(var s=0;s<t.length;s++){var o=t.charAt(s),a=o.charCodeAt(0);if(n[a]!==255)throw new TypeError(o+" is ambiguous");if(n[a]=s,r){var c=o.toLowerCase().charCodeAt(0),u=o.toUpperCase().charCodeAt(0);c!==a&&(n[c]=s),u!==a&&(n[u]=s)}}var f=t.length,l=t.charAt(0),h=Math.log(f)/Math.log(256),d=Math.log(256)/Math.log(f);function g(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var v=0,I=0,R=0,_=m.length;R!==_&&m[R]===0;)R++,v++;for(var O=(_-R)*d+1>>>0,k=new Uint8Array(O);R!==_;){for(var B=m[R],N=0,F=O-1;(B!==0||N<I)&&F!==-1;F--,N++)B+=256*k[F]>>>0,k[F]=B%f>>>0,B=B/f>>>0;if(B!==0)throw new Error("Non-zero carry");I=N,R++}for(var P=O-I;P!==O&&k[P]===0;)P++;for(var p=l.repeat(v);P<O;++P)p+=t.charAt(k[P]);return p}function E(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var v=0;if(m[v]!==" "){for(var I=0,R=0;m[v]===l;)I++,v++;for(var _=(m.length-v)*h+1>>>0,O=new Uint8Array(_);m[v];){var k=n[m.charCodeAt(v)];if(k===255)return;for(var B=0,N=_-1;(k!==0||B<R)&&N!==-1;N--,B++)k+=f*O[N]>>>0,O[N]=k%256>>>0,k=k/256>>>0;if(k!==0)throw new Error("Non-zero carry");R=B,v++}if(m[v]!==" "){for(var F=_-R;F!==_&&O[F]===0;)F++;for(var P=new Uint8Array(I+(_-F)),p=I;F!==_;)P[p++]=O[F++];return P}}}function y(m){var v=E(m);if(v)return v;throw new Error(`Non-${e} character`)}return{encode:g,decodeUnsafe:E,decode:y}}var Ga=Ya,Xa=Ga,Ci=Xa;var In=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")}},Bn=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let i=r.codePointAt(0);if(i===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=i,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 Pi(this,e)}},Tn=class{decoders;constructor(e){this.decoders=e}or(e){return Pi(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 Pi(t,e){return new Tn({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Ln=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,i){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=i,this.encoder=new In(e,r,n),this.decoder=new Bn(e,r,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Lt({name:t,prefix:e,encode:r,decode:n}){return new Ln(t,e,r,n)}function Ge({name:t,prefix:e,alphabet:r,caseInsensitive:n=!1}){let{encode:i,decode:s}=Ci(r,t,n);return Lt({prefix:e,name:t,encode:i,decode:o=>Ie(s(o))})}function Wa(t,e,r,n){let i=t.length;for(;t[i-1]==="=";)--i;let s=new Uint8Array(i*r/8|0),o=0,a=0,c=0;for(let u=0;u<i;++u){let f=e[t[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,o+=r,o>=8&&(o-=8,s[c++]=255&a>>o)}if(o>=r||(255&a<<8-o)!==0)throw new SyntaxError("Unexpected end of data");return s}function Ja(t,e,r){let n=e[e.length-1]==="=",i=(1<<r)-1,s="",o=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],o+=8;o>r;)o-=r,s+=e[i&a>>o];if(o!==0&&(s+=e[i&a<<r-o]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function Qa(t,e){let r={};for(let n=0;n<t.length;++n)if(r[t[n]]=n,e){let i=t[n].toLowerCase(),s=t[n].toUpperCase();i!==t[n]&&(r[i]=n),s!==t[n]&&(r[s]=n)}return r}function G({name:t,prefix:e,bitsPerChar:r,alphabet:n,caseInsensitive:i=!1}){let s=Qa(n,i);return Lt({prefix:e,name:t,encode(o){return Ja(o,n,r)},decode(o){return Wa(o,s,r,t)}})}var Z=Ge({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ec=Ge({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Dn={};me(Dn,{base32:()=>_t,base32hex:()=>sc,base32hexpad:()=>oc,base32hexpadupper:()=>ac,base32hexupper:()=>ic,base32pad:()=>rc,base32padupper:()=>nc,base32upper:()=>tc,base32z:()=>cc});var _t=G({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),tc=G({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),rc=G({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),nc=G({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),sc=G({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),ic=G({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),oc=G({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),ac=G({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),cc=G({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var kn={};me(kn,{base36:()=>Xt,base36upper:()=>uc});var Xt=Ge({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),uc=Ge({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var fc=Fi,Oi=128,lc=127,hc=~lc,dc=Math.pow(2,31);function Fi(t,e,r){e=e||[],r=r||0;for(var n=r;t>=dc;)e[r++]=t&255|Oi,t/=128;for(;t&hc;)e[r++]=t&255|Oi,t>>>=7;return e[r]=t|0,Fi.bytes=r-n+1,e}var pc=Rn,mc=128,Ni=127;function Rn(t,n){var r=0,n=n||0,i=0,s=n,o,a=t.length;do{if(s>=a)throw Rn.bytes=0,new RangeError("Could not decode varint");o=t[s++],r+=i<28?(o&Ni)<<i:(o&Ni)*Math.pow(2,i),i+=7}while(o>=mc);return Rn.bytes=s-n,r}var yc=Math.pow(2,7),bc=Math.pow(2,14),gc=Math.pow(2,21),wc=Math.pow(2,28),xc=Math.pow(2,35),Ec=Math.pow(2,42),vc=Math.pow(2,49),Sc=Math.pow(2,56),Ac=Math.pow(2,63),Ic=function(t){return t<yc?1:t<bc?2:t<gc?3:t<wc?4:t<xc?5:t<Ec?6:t<vc?7:t<Sc?8:t<Ac?9:10},Bc={encode:fc,decode:pc,encodingLength:Ic},Tc=Bc,Wt=Tc;function Jt(t,e=0){return[Wt.decode(t,e),Wt.decode.bytes]}function Dt(t,e,r=0){return Wt.encode(t,e,r),e}function kt(t){return Wt.encodingLength(t)}function Oe(t,e){let r=e.byteLength,n=kt(t),i=n+kt(r),s=new Uint8Array(i+r);return Dt(t,s,0),Dt(r,s,n),s.set(e,i),new Rt(t,r,e,s)}function Xe(t){let e=Ie(t),[r,n]=Jt(e),[i,s]=Jt(e.subarray(n)),o=e.subarray(n+s);if(o.byteLength!==i)throw new Error("Incorrect length");return new Rt(r,i,o,e)}function Ki(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&_i(t.bytes,r.bytes)}}var Rt=class{code;size;digest;bytes;constructor(e,r,n,i){this.code=e,this.size=r,this.digest=ft(n),this.bytes=ft(i)}};function Ui(t,e){let{bytes:r,version:n}=t;return n===0?_c(r,Cn(t),e??Z.encoder):Dc(r,Cn(t),e??_t.encoder)}var Mi=new WeakMap;function Cn(t){let e=Mi.get(t);if(e==null){let r=new Map;return Mi.set(t,r),r}return e}var ue=class t{code;version;multihash;bytes;"/";constructor(e,r,n,i){this.code=r,this.version=e,this.multihash=n,this.bytes=ft(i),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!==Qt)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==kc)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=Oe(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&&Ki(e.multihash,n.multihash)}toString(e){return Ui(this,e)}toJSON(){return{"/":Ui(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:i,multihash:s,bytes:o}=r;return new t(n,i,s,o??qi(n,i,s.bytes))}else if(r[Rc]===!0){let{version:n,multihash:i,code:s}=r,o=Xe(i);return t.create(n,s,o)}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!==Qt)throw new Error(`Version 0 CID must use dag-pb (code: ${Qt}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let i=qi(e,r,n.bytes);return new t(e,r,n,i)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,Qt,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,i=Ie(e.subarray(n,n+r.multihashSize));if(i.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=i.subarray(r.multihashSize-r.digestSize),o=new Rt(r.multihashCode,r.digestSize,s,i);return[r.version===0?t.createV0(o):t.createV1(r.codec,o),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[l,h]=Jt(e.subarray(r));return r+=h,l},i=n(),s=Qt;if(i===18?(i=0,r=0):s=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let o=r,a=n(),c=n(),u=r+c,f=u-o;return{version:i,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(e,r){let[n,i]=Lc(e,r),s=t.decode(i);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Cn(s).set(n,e),s}};function Lc(t,e){switch(t[0]){case"Q":{let r=e??Z;return[Z.prefix,r.decode(`${Z.prefix}${t}`)]}case Z.prefix:{let r=e??Z;return[Z.prefix,r.decode(t)]}case _t.prefix:{let r=e??_t;return[_t.prefix,r.decode(t)]}case Xt.prefix:{let r=e??Xt;return[Xt.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 _c(t,e,r){let{prefix:n}=r;if(n!==Z.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let i=e.get(n);if(i==null){let s=r.encode(t).slice(1);return e.set(n,s),s}else return i}function Dc(t,e,r){let{prefix:n}=r,i=e.get(n);if(i==null){let s=r.encode(t);return e.set(n,s),s}else return i}var Qt=112,kc=18;function qi(t,e,r){let n=kt(t),i=n+kt(e),s=new Uint8Array(i+r.byteLength);return Dt(t,s,0),Dt(e,s,n),s.set(r,i),s}var Rc=Symbol.for("@ipld/js-cid/CID");var Pn={};me(Pn,{identity:()=>Le});var Vi=0,Cc="identity",Hi=Ie;function Pc(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 Oe(Vi,Hi(t))}var Le={code:Vi,name:Cc,encode:Hi,digest:Pc};function ye(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 Oc(t){return t.buffer instanceof ArrayBuffer}function Be(t){return Oc(t)?t:t.slice()}async function zi(t,e,r,n){let i=await crypto.subtle.importKey("jwk",t,{name:"ECDSA",namedCurve:t.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},i,Be(e),Be(r.subarray()));return n?.signal?.throwIfAborted(),s}function Me(t=0){return new Uint8Array(t)}function be(t=0){return new Uint8Array(t)}function Nc(t){return t?.buffer instanceof ArrayBuffer}function $i(t){if(Nc(t))return t;let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function lt(t,e){e==null&&(e=t.reduce((i,s)=>i+s.length,0));let r=be(e),n=0;for(let i of t)r.set(i,n),n+=i.length;return $i(r)}var Zi=Symbol.for("@achingbrain/uint8arraylist");function ji(t,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let r=0;for(let n of t){let i=r+n.byteLength;if(e<i)return{buf:n,index:e-r};r=i}throw new RangeError("index is out of bounds")}function qr(t){return!!t?.[Zi]}var ie=class t{bufs;length;[Zi]=!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(qr(n)){r+=n.byteLength;for(let i of n.bufs)this.bufs.push(i)}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(qr(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=ji(this.bufs,e);return r.buf[r.index]}set(e,r){let n=ji(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(qr(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:i}=this._subList(e,r);return lt(n,i)}subarray(e,r){let{bufs:n,length:i}=this._subList(e,r);return n.length===1?n[0]:lt(n,i)}sublist(e,r){let{bufs:n,length:i}=this._subList(e,r),s=new t;return s.length=i,s.bufs=n,s}_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=[],i=0;for(let s=0;s<this.bufs.length;s++){let o=this.bufs[s],a=i,c=a+o.byteLength;if(i=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(o);break}let l=e-a;n.push(o.subarray(l,l+(r-e)));break}if(u){if(e===0){n.push(o);continue}n.push(o.subarray(e-a));continue}if(f){if(r===c){n.push(o);break}n.push(o.subarray(0,r-a));break}n.push(o)}return{bufs:n,length:r-e}}indexOf(e,r=0){if(!qr(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(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 i=n.byteLength;if(i===0)throw new TypeError("search must be at least 1 byte long");let s=256,o=new Int32Array(s);for(let l=0;l<s;l++)o[l]=-1;for(let l=0;l<i;l++)o[n[l]]=l;let a=o,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=r;l<=c;l+=f){f=0;for(let h=u;h>=0;h--){let d=this.get(l+h);if(n[h]!==d){f=Math.max(1,h-a[d]);break}}if(f===0)return l}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=be(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 i=Me(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt16(0,r,n),this.write(i,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 i=Me(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt32(0,r,n),this.write(i,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 i=Me(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigInt64(0,r,n),this.write(i,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=be(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 i=Me(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint16(0,r,n),this.write(i,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 i=Me(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint32(0,r,n),this.write(i,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 i=Me(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigUint64(0,r,n),this.write(i,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 i=Me(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat32(0,r,n),this.write(i,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 i=Me(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat64(0,r,n),this.write(i,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(!ye(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((i,s)=>i+s.byteLength,0)),n.length=r,n}};var On={};me(On,{base10:()=>Fc});var Fc=Ge({prefix:"9",name:"base10",alphabet:"0123456789"});var Nn={};me(Nn,{base16:()=>Kc,base16upper:()=>Uc});var Kc=G({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),Uc=G({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var Fn={};me(Fn,{base2:()=>Mc});var Mc=G({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Kn={};me(Kn,{base256emoji:()=>$c});var Yi=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}"),qc=Yi.reduce((t,e,r)=>(t[r]=e,t),[]),Vc=Yi.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function Hc(t){return t.reduce((e,r)=>(e+=qc[r],e),"")}function zc(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let i=Vc[n];if(i==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(i)}return new Uint8Array(e)}var $c=Lt({prefix:"\u{1F680}",name:"base256emoji",encode:Hc,decode:zc});var Un={};me(Un,{base64:()=>jc,base64pad:()=>Zc,base64url:()=>Yc,base64urlpad:()=>Gc});var jc=G({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Zc=G({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Yc=G({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Gc=G({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Mn={};me(Mn,{base8:()=>Xc});var Xc=G({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var qn={};me(qn,{identity:()=>Wc});var Wc=Lt({prefix:"\0",name:"identity",encode:t=>ki(Ie(t)),decode:t=>Ie(Di(t))});var dh=new TextEncoder,ph=new TextDecoder;var zn={};me(zn,{sha256:()=>ht,sha512:()=>tu});var eu=20;function Hn({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:i}){return new Vn(t,e,r,n,i)}var Vn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,i,s){this.name=e,this.code=r,this.encode=n,this.minDigestLength=i??eu,this.maxDigestLength=s}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?Gi(n,this.code,r?.truncate):n.then(i=>Gi(i,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Gi(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 Oe(e,t)}function Wi(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var ht=Hn({name:"sha2-256",code:18,encode:Wi("SHA-256")}),tu=Hn({name:"sha2-512",code:19,encode:Wi("SHA-512")});var $n={...qn,...Fn,...Mn,...On,...Nn,...Dn,...kn,..._n,...Un,...Kn},Bh={...zn,...Pn};function Qi(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Ji=Qi("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),jn=Qi("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=be(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),ru={utf8:Ji,"utf-8":Ji,hex:$n.base16,latin1:jn,ascii:jn,binary:jn,...$n},Vr=ru;function z(t,e="utf8"){let r=Vr[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function H(t,e="utf8"){let r=Vr[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var nu=parseInt("11111",2),Zn=parseInt("10000000",2),su=parseInt("01111111",2),eo={0:er,1:er,2:iu,3:cu,4:uu,5:au,6:ou,16:er,22:er,48:er};function qe(t,e={offset:0}){let r=t[e.offset]&nu;if(e.offset++,eo[r]!=null)return eo[r](t,e);throw new Error("No decoder for tag "+r)}function tr(t,e){let r=0;if((t[e.offset]&Zn)===Zn){let n=t[e.offset]&su,i="0x";e.offset++;for(let s=0;s<n;s++,e.offset++)i+=t[e.offset].toString(16).padStart(2,"0");r=parseInt(i,16)}else r=t[e.offset],e.offset++;return r}function er(t,e){tr(t,e);let r=[];for(;!(e.offset>=t.byteLength);){let n=qe(t,e);if(n===null)break;r.push(n)}return r}function iu(t,e){let r=tr(t,e),n=e.offset,i=e.offset+r,s=[];for(let o=n;o<i;o++)o===n&&t[o]===0||s.push(t[o]);return e.offset+=r,Uint8Array.from(s)}function ou(t,e){let r=tr(t,e),n=e.offset+r,i=t[e.offset];e.offset++;let s=0,o=0;i<40?(s=0,o=i):i<80?(s=1,o=i-40):(s=2,o=i-80);let a=`${s}.${o}`,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 l=0;l<c.length;l++)f+=c[l]<<l*7;a+=`.${f}`,c=[]}}return a}function au(t,e){return e.offset++,null}function cu(t,e){let r=tr(t,e),n=t[e.offset];e.offset++;let i=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 i}function uu(t,e){let r=tr(t,e),n=t.subarray(e.offset,e.offset+r);return e.offset+=r,n}function fu(t){let e=t.toString(16);e.length%2===1&&(e="0"+e);let r=new ie;for(let n=0;n<e.length;n+=2)r.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return r}function Yn(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=fu(t.byteLength);return new ie(Uint8Array.from([e.byteLength|Zn]),e)}function ge(t){let e=new ie,r=128;return(t.subarray()[0]&r)===r&&e.append(Uint8Array.from([0])),e.append(t),new ie(Uint8Array.from([2]),Yn(e),e)}function Hr(t){let e=Uint8Array.from([0]),r=new ie(e,t);return new ie(Uint8Array.from([3]),Yn(r),r)}function Je(t,e=48){let r=new ie;for(let n of t)r.append(n);return new ie(Uint8Array.from([e]),Yn(r),r)}var lu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),hu=Uint8Array.from([6,5,43,129,4,0,34]),du=Uint8Array.from([6,5,43,129,4,0,35]),pu={ext:!0,kty:"EC",crv:"P-256"},mu={ext:!0,kty:"EC",crv:"P-384"},yu={ext:!0,kty:"EC",crv:"P-521"},Gn=32,Xn=48,Wn=66;function Jn(t){let e=qe(t);return to(e)}function to(t){let e=t[1][1][0],r=1,n,i;if(e.byteLength===Gn*2+1)return n=H(e.subarray(r,r+Gn),"base64url"),i=H(e.subarray(r+Gn),"base64url"),new Ct({...pu,key_ops:["verify"],x:n,y:i});if(e.byteLength===Xn*2+1)return n=H(e.subarray(r,r+Xn),"base64url"),i=H(e.subarray(r+Xn),"base64url"),new Ct({...mu,key_ops:["verify"],x:n,y:i});if(e.byteLength===Wn*2+1)return n=H(e.subarray(r,r+Wn),"base64url"),i=H(e.subarray(r+Wn),"base64url"),new Ct({...yu,key_ops:["verify"],x:n,y:i});throw new j(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function ro(t){return Je([ge(Uint8Array.from([1])),Je([bu(t.crv)],160),Je([Hr(new ie(Uint8Array.from([4]),z(t.x??"","base64url"),z(t.y??"","base64url")))],161)]).subarray()}function bu(t){if(t==="P-256")return lu;if(t==="P-384")return hu;if(t==="P-521")return du;throw new j(`Invalid curve ${t}`)}var Ct=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=ro(this.jwk)),this._raw}toMultihash(){return Le.digest(Ve(this))}toCID(){return ue.createV1(114,this.toMultihash())}toString(){return Z.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ye(this.raw,e.raw)}async verify(e,r,n){return zi(this.jwk,r,e,n)}};function Qn(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}function Qe(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 Se(t,e,r=""){let n=Qn(t),i=t?.length,s=e!==void 0;if(!n||s&&i!==e){let o=r&&`"${r}" `,a=s?` of length ${e}`:"",c=n?`length=${i}`:`type=${typeof t}`,u=o+"expected Uint8Array"+a+", got "+c;throw n?new RangeError(u):new TypeError(u)}return t}function zr(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(Qe(t.outputLen),Qe(t.blockLen),t.outputLen<1)throw new Error('"outputLen" must be >= 1');if(t.blockLen<1)throw new Error('"blockLen" must be >= 1')}function Pt(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 $r(t,e){Se(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 ze(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function jr(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function _e(t,e){return t<<32-e|t>>>e}var so=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",gu=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Zr(t){if(Se(t),so)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=gu[t[r]];return e}var He={_0:48,_9:57,A:65,F:70,a:97,f:102};function no(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 rr(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(so)try{return Uint8Array.fromHex(t)}catch(i){throw i instanceof SyntaxError?new RangeError(i.message):i}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 i=0,s=0;i<r;i++,s+=2){let o=no(t.charCodeAt(s)),a=no(t.charCodeAt(s+1));if(o===void 0||a===void 0){let c=t[s]+t[s+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+s)}n[i]=o*16+a}return n}function es(...t){let e=0;for(let n=0;n<t.length;n++){let i=t[n];Se(i),e+=i.length}let r=new Uint8Array(e);for(let n=0,i=0;n<t.length;n++){let s=t[n];r.set(s,i),i+=s.length}return r}function ts(t,e={}){let r=(i,s)=>t(s).update(i).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=i=>t(i),Object.assign(r,e),Object.freeze(r)}function io(t=32){Qe(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 rs=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function oo(t,e,r){return t&e^~t&r}function ao(t,e,r){return t&e^t&r^e&r}var nr=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,r,n,i){this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=i,this.buffer=new Uint8Array(e),this.view=jr(this.buffer)}update(e){Pt(this),Se(e);let{view:r,buffer:n,blockLen:i}=this,s=e.length;for(let o=0;o<s;){let a=Math.min(i-this.pos,s-o);if(a===i){let c=jr(e);for(;i<=s-o;o+=i)this.process(c,o);continue}n.set(e.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===i&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Pt(this),$r(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:i,isLE:s}=this,{pos:o}=this;r[o++]=128,ze(this.buffer.subarray(o)),this.padOffset>i-o&&(this.process(n,0),o=0);for(let l=o;l<i;l++)r[l]=0;n.setBigUint64(i-8,BigInt(this.length*8),s),this.process(n,0);let a=jr(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 l=0;l<u;l++)a.setUint32(4*l,f[l],s)}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:i,finished:s,destroyed:o,pos:a}=this;return e.destroyed=o,e.finished=s,e.length=i,e.pos=a,i%r&&e.buffer.set(n),e}clone(){return this._cloneInto()}},$e=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ae=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Yr=BigInt(4294967295),co=BigInt(32);function wu(t,e=!1){return e?{h:Number(t&Yr),l:Number(t>>co&Yr)}:{h:Number(t>>co&Yr)|0,l:Number(t&Yr)|0}}function uo(t,e=!1){let r=t.length,n=new Uint32Array(r),i=new Uint32Array(r);for(let s=0;s<r;s++){let{h:o,l:a}=wu(t[s],e);[n[s],i[s]]=[o,a]}return[n,i]}var ns=(t,e,r)=>t>>>r,ss=(t,e,r)=>t<<32-r|e>>>r,dt=(t,e,r)=>t>>>r|e<<32-r,pt=(t,e,r)=>t<<32-r|e>>>r,sr=(t,e,r)=>t<<64-r|e>>>r-32,ir=(t,e,r)=>t>>>r-32|e<<64-r;function Ne(t,e,r,n){let i=(e>>>0)+(n>>>0);return{h:t+r+(i/2**32|0)|0,l:i|0}}var fo=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),lo=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,ho=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),po=(t,e,r,n,i)=>e+r+n+i+(t/2**32|0)|0,mo=(t,e,r,n,i)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(i>>>0),yo=(t,e,r,n,i,s)=>e+r+n+i+s+(t/2**32|0)|0;var Eu=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]),et=new Uint32Array(64),is=class extends nr{constructor(e){super(64,e,8,!1)}get(){let{A:e,B:r,C:n,D:i,E:s,F:o,G:a,H:c}=this;return[e,r,n,i,s,o,a,c]}set(e,r,n,i,s,o,a,c){this.A=e|0,this.B=r|0,this.C=n|0,this.D=i|0,this.E=s|0,this.F=o|0,this.G=a|0,this.H=c|0}process(e,r){for(let l=0;l<16;l++,r+=4)et[l]=e.getUint32(r,!1);for(let l=16;l<64;l++){let h=et[l-15],d=et[l-2],g=_e(h,7)^_e(h,18)^h>>>3,E=_e(d,17)^_e(d,19)^d>>>10;et[l]=E+et[l-7]+g+et[l-16]|0}let{A:n,B:i,C:s,D:o,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let h=_e(a,6)^_e(a,11)^_e(a,25),d=f+h+oo(a,c,u)+Eu[l]+et[l]|0,E=(_e(n,2)^_e(n,13)^_e(n,22))+ao(n,i,s)|0;f=u,u=c,c=a,a=o+d|0,o=s,s=i,i=n,n=d+E|0}n=n+this.A|0,i=i+this.B|0,s=s+this.C|0,o=o+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,i,s,o,a,c,u,f)}roundClean(){ze(et)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),ze(this.buffer)}},os=class extends is{A=$e[0]|0;B=$e[1]|0;C=$e[2]|0;D=$e[3]|0;E=$e[4]|0;F=$e[5]|0;G=$e[6]|0;H=$e[7]|0;constructor(){super(32)}};var bo=uo(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(t=>BigInt(t))),vu=bo[0],Su=bo[1],tt=new Uint32Array(80),rt=new Uint32Array(80),as=class extends nr{constructor(e){super(128,e,16,!1)}get(){let{Ah:e,Al:r,Bh:n,Bl:i,Ch:s,Cl:o,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:h,Gh:d,Gl:g,Hh:E,Hl:y}=this;return[e,r,n,i,s,o,a,c,u,f,l,h,d,g,E,y]}set(e,r,n,i,s,o,a,c,u,f,l,h,d,g,E,y){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=i|0,this.Ch=s|0,this.Cl=o|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=h|0,this.Gh=d|0,this.Gl=g|0,this.Hh=E|0,this.Hl=y|0}process(e,r){for(let I=0;I<16;I++,r+=4)tt[I]=e.getUint32(r),rt[I]=e.getUint32(r+=4);for(let I=16;I<80;I++){let R=tt[I-15]|0,_=rt[I-15]|0,O=dt(R,_,1)^dt(R,_,8)^ns(R,_,7),k=pt(R,_,1)^pt(R,_,8)^ss(R,_,7),B=tt[I-2]|0,N=rt[I-2]|0,F=dt(B,N,19)^sr(B,N,61)^ns(B,N,6),P=pt(B,N,19)^ir(B,N,61)^ss(B,N,6),p=ho(k,P,rt[I-7],rt[I-16]),b=po(p,O,F,tt[I-7],tt[I-16]);tt[I]=b|0,rt[I]=p|0}let{Ah:n,Al:i,Bh:s,Bl:o,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:h,Fh:d,Fl:g,Gh:E,Gl:y,Hh:m,Hl:v}=this;for(let I=0;I<80;I++){let R=dt(l,h,14)^dt(l,h,18)^sr(l,h,41),_=pt(l,h,14)^pt(l,h,18)^ir(l,h,41),O=l&d^~l&E,k=h&g^~h&y,B=mo(v,_,k,Su[I],rt[I]),N=yo(B,m,R,O,vu[I],tt[I]),F=B|0,P=dt(n,i,28)^sr(n,i,34)^sr(n,i,39),p=pt(n,i,28)^ir(n,i,34)^ir(n,i,39),b=n&s^n&a^s&a,S=i&o^i&c^o&c;m=E|0,v=y|0,E=d|0,y=g|0,d=l|0,g=h|0,{h:l,l:h}=Ne(u|0,f|0,N|0,F|0),u=a|0,f=c|0,a=s|0,c=o|0,s=n|0,o=i|0;let x=fo(F,p,S);n=lo(x,N,P,b),i=x|0}({h:n,l:i}=Ne(this.Ah|0,this.Al|0,n|0,i|0)),{h:s,l:o}=Ne(this.Bh|0,this.Bl|0,s|0,o|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,l:h}=Ne(this.Eh|0,this.El|0,l|0,h|0),{h:d,l:g}=Ne(this.Fh|0,this.Fl|0,d|0,g|0),{h:E,l:y}=Ne(this.Gh|0,this.Gl|0,E|0,y|0),{h:m,l:v}=Ne(this.Hh|0,this.Hl|0,m|0,v|0),this.set(n,i,s,o,a,c,u,f,l,h,d,g,E,y,m,v)}roundClean(){ze(tt,rt)}destroy(){this.destroyed=!0,ze(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},cs=class extends as{Ah=ae[0]|0;Al=ae[1]|0;Bh=ae[2]|0;Bl=ae[3]|0;Ch=ae[4]|0;Cl=ae[5]|0;Dh=ae[6]|0;Dl=ae[7]|0;Eh=ae[8]|0;El=ae[9]|0;Fh=ae[10]|0;Fl=ae[11]|0;Gh=ae[12]|0;Gl=ae[13]|0;Hh=ae[14]|0;Hl=ae[15]|0;constructor(){super(64)}};var Ot=ts(()=>new os,rs(1));var Gr=ts(()=>new cs,rs(3));var M=(t,e,r)=>Se(t,e,r),fs=Qe,Nt=Zr,re=(...t)=>es(...t),Ft=t=>rr(t),mt=Qn,or=t=>io(t),Wr=BigInt(0),us=BigInt(1);function De(t,e=""){if(typeof t!="boolean"){let r=e&&`"${e}" `;throw new TypeError(r+"expected boolean, got type="+typeof t)}return t}function Jr(t){if(typeof t=="bigint"){if(!Xr(t))throw new RangeError("positive bigint expected, got "+t)}else fs(t);return t}function ke(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 ar(t){let e=Jr(t).toString(16);return e.length&1?"0"+e:e}function go(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?Wr:BigInt("0x"+t)}function yt(t){return go(Zr(t))}function Fe(t){return go(Zr(cr(Se(t)).reverse()))}function Qr(t,e){if(Qe(e),e===0)throw new RangeError("zero length");t=Jr(t);let r=t.toString(16);if(r.length>e*2)throw new RangeError("number too large");return rr(r.padStart(e*2,"0"))}function ls(t,e){return Qr(t,e).reverse()}function wo(t,e){if(t=M(t),e=M(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 cr(t){return Uint8Array.from(M(t))}function en(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 Xr=t=>typeof t=="bigint"&&Wr<=t;function Au(t,e,r){return Xr(t)&&Xr(e)&&Xr(r)&&e<=t&&t<r}function Kt(t,e,r,n){if(!Au(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function Ut(t){if(t<Wr)throw new Error("expected non-negative bigint, got "+t);let e;for(e=0;t>Wr;t>>=us,e+=1);return e}var ur=t=>(us<<BigInt(t))-us;function xo(t,e,r){if(Qe(t,"hashLen"),Qe(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=y=>new Uint8Array(y),i=Uint8Array.of(),s=Uint8Array.of(0),o=Uint8Array.of(1),a=1e3,c=n(t),u=n(t),f=0,l=()=>{c.fill(1),u.fill(0),f=0},h=(...y)=>r(u,re(c,...y)),d=(y=i)=>{u=h(s,y),c=h(),y.length!==0&&(u=h(o,y),c=h())},g=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let y=0,m=[];for(;y<e;){c=h();let v=c.slice();m.push(v),y+=c.length}return re(...m)};return(y,m)=>{l(),d(y);let v;for(;(v=m(g()))===void 0;)d();return l(),v}}function Re(t,e={},r={}){if(Object.prototype.toString.call(t)!=="[object Object]")throw new TypeError("expected valid options object");function n(s,o,a){if(!a&&o!=="function"&&!Object.hasOwn(t,s))throw new TypeError(`param "${s}" is invalid: expected own property`);let c=t[s];if(a&&c===void 0)return;let u=typeof c;if(u!==o||c===null)throw new TypeError(`param "${s}" is invalid: expected ${o}, got ${u}`)}let i=(s,o)=>Object.entries(s).forEach(([a,c])=>n(a,c,o));i(e,!1),i(r,!0)}var hs=()=>{throw new Error("not implemented")};var ce=BigInt(0),X=BigInt(1),bt=BigInt(2),Ao=BigInt(3),Io=BigInt(4),Bo=BigInt(5),Iu=BigInt(7),To=BigInt(8),Bu=BigInt(9),Lo=BigInt(16);function Q(t,e){if(e<=ce)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=ce?r:e+r}function $(t,e,r){if(e<ce)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >ce;)n*=n,n%=r;return n}function Eo(t,e){if(t===ce)throw new Error("invert: expected non-zero number");if(e<=ce)throw new Error("invert: expected positive modulus, got "+e);let r=Q(t,e),n=e,i=ce,s=X,o=X,a=ce;for(;r!==ce;){let u=n/r,f=n-r*u,l=i-o*u,h=s-a*u;n=r,r=f,i=o,s=a,o=l,a=h}if(n!==X)throw new Error("invert: does not exist");return Q(i,e)}function ds(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function _o(t,e){let r=t,n=(r.ORDER+X)/Io,i=r.pow(e,n);return ds(r,i,e),i}function Tu(t,e){let r=t,n=(r.ORDER-Bo)/To,i=r.mul(e,bt),s=r.pow(i,n),o=r.mul(e,s),a=r.mul(r.mul(o,bt),s),c=r.mul(o,r.sub(a,r.ONE));return ds(r,c,e),c}function Lu(t){let e=Mt(t),r=Do(t),n=r(e,e.neg(e.ONE)),i=r(e,n),s=r(e,e.neg(n)),o=(t+Iu)/Lo;return((a,c)=>{let u=a,f=u.pow(c,o),l=u.mul(f,n),h=u.mul(f,i),d=u.mul(f,s),g=u.eql(u.sqr(l),c),E=u.eql(u.sqr(h),c);f=u.cmov(f,l,g),l=u.cmov(d,h,E);let y=u.eql(u.sqr(l),c),m=u.cmov(f,l,y);return ds(u,m,c),m})}function Do(t){if(t<Ao)throw new Error("sqrt is not defined for small field");let e=t-X,r=0;for(;e%bt===ce;)e/=bt,r++;let n=bt,i=Mt(t);for(;vo(i,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return _o;let s=i.pow(n,e),o=(e+X)/bt;return function(c,u){let f=c;if(f.is0(u))return u;if(vo(f,u)!==1)throw new Error("Cannot find square root");let l=r,h=f.mul(f.ONE,s),d=f.pow(u,e),g=f.pow(u,o);for(;!f.eql(d,f.ONE);){if(f.is0(d))return f.ZERO;let E=1,y=f.sqr(d);for(;!f.eql(y,f.ONE);)if(E++,y=f.sqr(y),E===l)throw new Error("Cannot find square root");let m=X<<BigInt(l-E-1),v=f.pow(h,m);l=E,h=f.sqr(v),d=f.mul(d,h),g=f.mul(g,v)}return g}}function _u(t){return t%Io===Ao?_o:t%To===Bo?Tu:t%Lo===Bu?Lu(t):Do(t)}var je=(t,e)=>(Q(t,e)&X)===X,Du=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ps(t){let e={ORDER:"bigint",BYTES:"number",BITS:"number"},r=Du.reduce((n,i)=>(n[i]="function",n),e);if(Re(t,r),ke(t.BYTES,"BYTES"),ke(t.BITS,"BITS"),t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=X)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function ku(t,e,r){let n=t;if(r<ce)throw new Error("invalid exponent, negatives unsupported");if(r===ce)return n.ONE;if(r===X)return e;let i=n.ONE,s=e;for(;r>ce;)r&X&&(i=n.mul(i,s)),s=n.sqr(s),r>>=X;return i}function fr(t,e,r=!1){let n=t,i=new Array(e.length).fill(r?n.ZERO:void 0),s=e.reduce((a,c,u)=>n.is0(c)?a:(i[u]=a,n.mul(a,c)),n.ONE),o=n.inv(s);return e.reduceRight((a,c,u)=>n.is0(c)?a:(i[u]=n.mul(a,i[u]),n.mul(a,c)),o),i}function vo(t,e){let r=t,n=(r.ORDER-X)/bt,i=r.pow(e,n),s=r.eql(i,r.ONE),o=r.eql(i,r.ZERO),a=r.eql(i,r.neg(r.ONE));if(!s&&!o&&!a)throw new Error("invalid Legendre symbol result");return s?1:o?0:-1}function Ru(t,e){if(e!==void 0&&fs(e),t<=ce)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=Ut(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,i=Math.ceil(n/8);return{nBitLength:n,nByteLength:i}}var So=new WeakMap,tn=class{ORDER;BITS;BYTES;isLE;ZERO=ce;ONE=X;_lengths;_mod;constructor(e,r={}){if(e<=X)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:i,nByteLength:s}=Ru(e,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=i,this.BYTES=s,Object.freeze(this)}create(e){return Q(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return ce<=e&&e<this.ORDER}is0(e){return e===ce}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&X)===X}neg(e){return Q(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return Q(e*e,this.ORDER)}add(e,r){return Q(e+r,this.ORDER)}sub(e,r){return Q(e-r,this.ORDER)}mul(e,r){return Q(e*r,this.ORDER)}pow(e,r){return ku(this,e,r)}div(e,r){return Q(e*Eo(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 Eo(e,this.ORDER)}sqrt(e){let r=So.get(this);return r||So.set(this,r=_u(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?ls(e,this.BYTES):Qr(e,this.BYTES)}fromBytes(e,r=!1){M(e);let{_lengths:n,BYTES:i,isLE:s,ORDER:o,_mod:a}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>i)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let u=new Uint8Array(i);u.set(e,s?0:u.length-e.length),e=u}if(e.length!==i)throw new Error("Field.fromBytes: expected "+i+" bytes, got "+e.length);let c=s?Fe(e):yt(e);if(a&&(c=Q(c,o)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return fr(this,e)}cmov(e,r,n){return De(n,"condition"),n?r:e}};Object.freeze(tn.prototype);function Mt(t,e={}){return new tn(t,e)}function ko(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=X)throw new Error("field order must be greater than 1");let e=Ut(t-X);return Math.ceil(e/8)}function ms(t){let e=ko(t);return e+Math.ceil(e/2)}function ys(t,e,r=!1){M(t);let n=t.length,i=ko(e),s=Math.max(ms(e),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let o=r?Fe(t):yt(t),a=Q(o,e-X)+X;return r?ls(a,i):Qr(a,i)}var qt=BigInt(0),gt=BigInt(1);function lr(t,e){let r=e.negate();return t?r:e}function wt(t,e){let r=fr(t.Fp,e.map(n=>n.Z));return e.map((n,i)=>t.fromAffine(n.toAffine(r[i])))}function Oo(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function bs(t,e){Oo(t,e);let r=Math.ceil(e/t)+1,n=2**(t-1),i=2**t,s=ur(t),o=BigInt(t);return{windows:r,windowSize:n,mask:s,maxNumber:i,shiftBy:o}}function Ro(t,e,r){let{windowSize:n,mask:i,maxNumber:s,shiftBy:o}=r,a=Number(t&i),c=t>>o;a>n&&(a-=s,c+=gt);let u=e*n,f=u+Math.abs(a)-1,l=a===0,h=a<0,d=e%2!==0;return{nextN:c,offset:f,isZero:l,isNeg:h,isNegF:d,offsetF:u}}var gs=new WeakMap,No=new WeakMap;function ws(t){return No.get(t)||1}function Co(t){if(t!==qt)throw new Error("invalid wNAF")}var Vt=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 i=e;for(;r>qt;)r&gt&&(n=n.add(i)),i=i.double(),r>>=gt;return n}precomputeWindow(e,r){let{windows:n,windowSize:i}=bs(r,this.bits),s=[],o=e,a=o;for(let c=0;c<n;c++){a=o,s.push(a);for(let u=1;u<i;u++)a=a.add(o),s.push(a);o=a.double()}return s}wNAF(e,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let i=this.ZERO,s=this.BASE,o=bs(e,this.bits);for(let a=0;a<o.windows;a++){let{nextN:c,offset:u,isZero:f,isNeg:l,isNegF:h,offsetF:d}=Ro(n,a,o);n=c,f?s=s.add(lr(h,r[d])):i=i.add(lr(l,r[u]))}return Co(n),{p:i,f:s}}wNAFUnsafe(e,r,n,i=this.ZERO){let s=bs(e,this.bits);for(let o=0;o<s.windows&&n!==qt;o++){let{nextN:a,offset:c,isZero:u,isNeg:f}=Ro(n,o,s);if(n=a,!u){let l=r[c];i=i.add(f?l.negate():l)}}return Co(n),i}getPrecomputes(e,r,n){let i=gs.get(r);return i||(i=this.precomputeWindow(r,e),e!==1&&(typeof n=="function"&&(i=n(i)),gs.set(r,i))),i}cached(e,r,n){let i=ws(e);return this.wNAF(i,this.getPrecomputes(i,e,n),r)}unsafe(e,r,n,i){let s=ws(e);return s===1?this._unsafeLadder(e,r,i):this.wNAFUnsafe(s,this.getPrecomputes(s,e,n),r,i)}createCache(e,r){Oo(r,this.bits),No.set(e,r),gs.delete(e)}hasCache(e){return ws(e)!==1}};function Fo(t,e,r,n){let i=e,s=t.ZERO,o=t.ZERO;for(;r>qt||n>qt;)r&gt&&(s=s.add(i)),n&gt&&(o=o.add(i)),i=i.double(),r>>=gt,n>>=gt;return{p1:s,p2:o}}function Po(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return ps(e),e}else return Mt(t,{isLE:r})}function rn(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>qt))throw new Error(`CURVE.${c} must be positive bigint`)}let i=Po(e.p,r.Fp,n),s=Po(e.n,r.Fn,n),a=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let c of a)if(!i.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:i,Fn:s}}function nn(t,e){return function(n){let i=t(n);return{secretKey:i,publicKey:e(i)}}}var nt=BigInt(0),oe=BigInt(1),xs=BigInt(2),Cu=BigInt(8);function Pu(t,e,r,n){let i=t.sqr(r),s=t.sqr(n),o=t.add(t.mul(e.a,i),s),a=t.add(t.ONE,t.mul(e.d,t.mul(i,s)));return t.eql(o,a)}function Ko(t,e={}){let r=e,n=rn("edwards",t,r,r.FpFnLE),{Fp:i,Fn:s}=n,o=n.CURVE,{h:a}=o;Re(r,{},{uvRatio:"function"});let c=xs<<BigInt(s.BYTES*8)-oe,u=E=>i.create(E),f=r.uvRatio===void 0?(E,y)=>{try{return{isValid:!0,value:i.sqrt(i.div(E,y))}}catch{return{isValid:!1,value:nt}}}:r.uvRatio;if(!Pu(i,o,o.Gx,o.Gy))throw new Error("bad curve params: generator point");function l(E,y,m=!1){let v=m?oe:nt;return Kt("coordinate "+E,y,v,c),y}function h(E){if(!(E instanceof d))throw new Error("EdwardsPoint expected")}class d{static BASE=new d(o.Gx,o.Gy,oe,u(o.Gx*o.Gy));static ZERO=new d(nt,oe,oe,nt);static Fp=i;static Fn=s;X;Y;Z;T;constructor(y,m,v,I){this.X=l("x",y),this.Y=l("y",m),this.Z=l("z",v,!0),this.T=l("t",I),Object.freeze(this)}static CURVE(){return o}static fromAffine(y){if(y instanceof d)throw new Error("extended point not allowed");let{x:m,y:v}=y||{};return l("x",m),l("y",v),new d(m,v,oe,u(m*v))}static fromBytes(y,m=!1){let v=i.BYTES,{a:I,d:R}=o;y=cr(M(y,v,"point")),De(m,"zip215");let _=cr(y),O=y[v-1];_[v-1]=O&-129;let k=Fe(_),B=m?c:i.ORDER;Kt("point.y",k,nt,B);let N=u(k*k),F=u(N-oe),P=u(R*N-I),{isValid:p,value:b}=f(F,P);if(!p)throw new Error("bad point: invalid y coordinate");let S=(b&oe)===oe,x=(O&128)!==0;if(!m&&b===nt&&x)throw new Error("bad point: x=0 and x_0=1");return x!==S&&(b=u(-b)),d.fromAffine({x:b,y:k})}static fromHex(y,m=!1){return d.fromBytes(Ft(y),m)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=8,m=!0){return g.createCache(this,y),m||this.multiply(xs),this}assertValidity(){let y=this,{a:m,d:v}=o;if(y.is0())throw new Error("bad point: ZERO");let{X:I,Y:R,Z:_,T:O}=y,k=u(I*I),B=u(R*R),N=u(_*_),F=u(N*N),P=u(k*m),p=u(N*u(P+B)),b=u(F+u(v*u(k*B)));if(p!==b)throw new Error("bad point: equation left != right (1)");let S=u(I*R),x=u(_*O);if(S!==x)throw new Error("bad point: equation left != right (2)")}equals(y){h(y);let{X:m,Y:v,Z:I}=this,{X:R,Y:_,Z:O}=y,k=u(m*O),B=u(R*I),N=u(v*O),F=u(_*I);return k===B&&N===F}is0(){return this.equals(d.ZERO)}negate(){return new d(u(-this.X),this.Y,this.Z,u(-this.T))}double(){let{a:y}=o,{X:m,Y:v,Z:I}=this,R=u(m*m),_=u(v*v),O=u(xs*u(I*I)),k=u(y*R),B=m+v,N=u(u(B*B)-R-_),F=k+_,P=F-O,p=k-_,b=u(N*P),S=u(F*p),x=u(N*p),w=u(P*F);return new d(b,S,w,x)}add(y){h(y);let{a:m,d:v}=o,{X:I,Y:R,Z:_,T:O}=this,{X:k,Y:B,Z:N,T:F}=y,P=u(I*k),p=u(R*B),b=u(O*v*F),S=u(_*N),x=u((I+R)*(k+B)-P-p),w=S-b,A=S+b,L=u(p-m*P),T=u(x*w),D=u(A*L),C=u(x*L),U=u(w*A);return new d(T,D,U,C)}subtract(y){return h(y),this.add(y.negate())}multiply(y){if(!s.isValidNot0(y))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:m,f:v}=g.cached(this,y,I=>wt(d,I));return wt(d,[m,v])[0]}multiplyUnsafe(y){if(!s.isValid(y))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return y===nt?d.ZERO:this.is0()||y===oe?this:g.unsafe(this,y,m=>wt(d,m))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return g.unsafe(this,o.n).is0()}toAffine(y){let m=this,v=y,{X:I,Y:R,Z:_}=m,O=m.is0();v==null&&(v=O?Cu:i.inv(_));let k=u(I*v),B=u(R*v),N=i.mul(_,v);if(O)return{x:nt,y:oe};if(N!==oe)throw new Error("invZ was invalid");return{x:k,y:B}}clearCofactor(){return a===oe?this:this.multiplyUnsafe(a)}toBytes(){let{x:y,y:m}=this.toAffine(),v=i.toBytes(m);return v[v.length-1]|=y&oe?128:0,v}toHex(){return Nt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let g=new Vt(d,s.BITS);return s.BITS>=8&&d.BASE.precompute(8),Object.freeze(d.prototype),Object.freeze(d),d}var sn=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(e){this.ep=e}static fromBytes(e){hs()}static fromHex(e){hs()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(e){return this.ep.toAffine(e)}toHex(){return Nt(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(e){return this.assertSame(e),this.init(this.ep.add(e.ep))}subtract(e){return this.assertSame(e),this.init(this.ep.subtract(e.ep))}multiply(e){return this.init(this.ep.multiply(e))}multiplyUnsafe(e){return this.init(this.ep.multiplyUnsafe(e))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(e,r){return this.ep.precompute(e,r),this}};function Uo(t,e,r={}){if(typeof e!="function")throw new Error('"hash" function param is required');let n=e,i=r;Re(i,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function"});let{prehash:s}=i,{BASE:o,Fp:a,Fn:c}=t,u=n.outputLen,f=2*a.BYTES;if(u!==void 0&&(ke(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let l=i.randomBytes===void 0?or:i.randomBytes,h=i.adjustScalarBytes===void 0?p=>p:i.adjustScalarBytes,d=i.domain===void 0?(p,b,S)=>{if(De(S,"phflag"),b.length||S)throw new Error("Contexts/pre-hash are not supported");return p}:i.domain;function g(p){return c.create(Fe(p))}function E(p){let b=k.secretKey;M(p,k.secretKey,"secretKey");let S=M(n(p),2*b,"hashedSecretKey"),x=h(S.slice(0,b)),w=S.slice(b,2*b),A=g(x);return{head:x,prefix:w,scalar:A}}function y(p){let{head:b,prefix:S,scalar:x}=E(p),w=o.multiply(x),A=w.toBytes();return{head:b,prefix:S,scalar:x,point:w,pointBytes:A}}function m(p){return y(p).pointBytes}function v(p=Uint8Array.of(),...b){let S=re(...b);return g(n(d(S,M(p,void 0,"context"),!!s)))}function I(p,b,S={}){p=M(p,void 0,"message"),s&&(p=s(p));let{prefix:x,scalar:w,pointBytes:A}=y(b),L=v(S.context,x,p),T=o.multiply(L).toBytes(),D=v(S.context,T,A,p),C=c.create(L+D*w);if(!c.isValid(C))throw new Error("sign failed: invalid s");let U=re(T,c.toBytes(C));return M(U,k.signature,"result")}let R={zip215:i.zip215};function _(p,b,S,x=R){let{context:w}=x,A=x.zip215===void 0?!!R.zip215:x.zip215,L=k.signature;p=M(p,L,"signature"),b=M(b,void 0,"message"),S=M(S,k.publicKey,"publicKey"),A!==void 0&&De(A,"zip215"),s&&(b=s(b));let T=L/2,D=p.subarray(0,T),C=Fe(p.subarray(T,L)),U,q,K;try{U=t.fromBytes(S,A),q=t.fromBytes(D,A),K=o.multiplyUnsafe(C)}catch{return!1}if(!A&&U.isSmallOrder())return!1;let te=v(w,D,S,b);return q.add(U.multiplyUnsafe(te)).subtract(K).clearCofactor().is0()}let O=a.BYTES,k={secretKey:O,publicKey:O,signature:2*O,seed:O};function B(p){return p=p===void 0?l(k.seed):p,M(p,k.seed,"seed")}function N(p){return mt(p)&&p.length===k.secretKey}function F(p,b){try{return!!t.fromBytes(p,b===void 0?R.zip215:b)}catch{return!1}}let P={getExtendedPublicKey:y,randomSecretKey:B,isValidSecretKey:N,isValidPublicKey:F,toMontgomery(p){let{y:b}=t.fromBytes(p),S=k.publicKey,x=S===32;if(!x&&S!==57)throw new Error("only defined for 25519 and 448");let w=x?a.div(oe+b,oe-b):a.div(b-oe,b+oe);return a.toBytes(w)},toMontgomerySecret(p){let b=k.secretKey;M(p,b);let S=n(p.subarray(0,b));return h(S).subarray(0,b)}};return Object.freeze(k),Object.freeze(P),Object.freeze({keygen:nn(B,m),getPublicKey:m,sign:I,verify:_,utils:P,Point:t,lengths:k})}function hr(t,e){if(ke(t),ke(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 Ou(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 Nu(t){if(!mt(t)&&typeof t!="string")throw new Error("DST must be Uint8Array or ascii string");let e=typeof t=="string"?en(t):t;if(e.length===0)throw new Error("DST must be non-empty");return e}function Es(t,e,r,n){M(t),ke(r),e=Nu(e),e.length>255&&(e=n(re(en("H2C-OVERSIZE-DST-"),e)));let{outputLen:i,blockLen:s}=n,o=Math.ceil(r/i);if(r>65535||o>255)throw new Error("expand_message_xmd: invalid lenInBytes");let a=re(e,hr(e.length,1)),c=new Uint8Array(s),u=hr(r,2),f=new Array(o),l=n(re(c,t,u,hr(0,1),a));f[0]=n(re(l,hr(1,1),a));for(let d=1;d<o;d++){let g=[Ou(l,f[d-1]),hr(d+1,1),a];f[d]=n(re(...g))}return re(...f).slice(0,r)}var Mo="HashToScalar-";var Fu=BigInt(0),Ze=BigInt(1),qo=BigInt(2);var Ku=BigInt(5),Uu=BigInt(8),Ht=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Is={p:Ht,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Uu,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Mu(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),i=BigInt(80),s=Ht,a=t*t%s*t%s,c=$(a,qo,s)*a%s,u=$(c,Ze,s)*t%s,f=$(u,Ku,s)*u%s,l=$(f,e,s)*f%s,h=$(l,r,s)*l%s,d=$(h,n,s)*h%s,g=$(d,i,s)*d%s,E=$(g,i,s)*d%s,y=$(E,e,s)*f%s;return{pow_p_5_8:$(y,qo,s)*t%s,b2:a}}function qu(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var vs=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Bs(t,e){let r=Ht,n=Q(e*e*e,r),i=Q(n*n*e,r),s=Mu(t*i).pow_p_5_8,o=Q(t*n*s,r),a=Q(e*o*o,r),c=o,u=Q(o*vs,r),f=a===t,l=a===Q(-t,r),h=a===Q(-t*vs,r);return f&&(o=c),(l||h)&&(o=u),je(o,r)&&(o=Q(-o,r)),{isValid:f||l,value:o}}var it=Ko(Is,{uvRatio:Bs}),st=it.Fp,zo=it.Fn;function Vu(t){return Uo(it,Gr,Object.assign({adjustScalarBytes:qu,zip215:!0},t))}var $o=Vu({});var Ss=vs,Hu=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),zu=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),$u=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),ju=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Vo=t=>Bs(Ze,t),Zu=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),As=t=>st.create(Fe(t)&Zu);function Ho(t){let{d:e}=Is,r=Ht,n=m=>st.create(m),i=n(Ss*t*t),s=n((i+Ze)*$u),o=BigInt(-1),a=n((o-e*i)*n(i+e)),{isValid:c,value:u}=Bs(s,a),f=n(u*t);je(f,r)||(f=n(-f)),c||(u=f),c||(o=i);let l=n(o*(i-Ze)*ju-a),h=u*u,d=n((u+u)*a),g=n(l*Hu),E=n(Ze-h),y=n(Ze+h);return new it(n(d*y),n(E*g),n(g*y),n(d*E))}var ot=class t extends sn{static BASE=new t(it.BASE);static ZERO=new t(it.ZERO);static Fp=st;static Fn=zo;constructor(e){super(e)}static fromAffine(e){return new t(it.fromAffine(e))}assertSame(e){if(!(e instanceof t))throw new Error("RistrettoPoint expected")}init(e){return new t(e)}static fromBytes(e){Se(e,32);let{a:r,d:n}=Is,i=Ht,s=R=>st.create(R),o=As(e);if(!wo(st.toBytes(o),e)||je(o,i))throw new Error("invalid ristretto255 encoding 1");let a=s(o*o),c=s(Ze+r*a),u=s(Ze-r*a),f=s(c*c),l=s(u*u),h=s(r*n*f-l),{isValid:d,value:g}=Vo(s(h*l)),E=s(g*u),y=s(g*E*h),m=s((o+o)*E);je(m,i)&&(m=s(-m));let v=s(c*y),I=s(m*v);if(!d||je(I,i)||v===Fu)throw new Error("invalid ristretto255 encoding 2");return new t(new it(m,v,Ze,I))}static fromHex(e){return t.fromBytes(rr(e))}toBytes(){let{X:e,Y:r,Z:n,T:i}=this.ep,s=Ht,o=y=>st.create(y),a=o(o(n+r)*o(n-r)),c=o(e*r),u=o(c*c),{value:f}=Vo(o(a*u)),l=o(f*a),h=o(f*c),d=o(l*h*i),g;if(je(i*d,s)){let y=o(r*Ss),m=o(e*Ss);e=y,r=m,g=o(l*zu)}else g=h;je(e*d,s)&&(r=o(-r));let E=o((n-r)*g);return je(E,s)&&(E=o(-E)),st.toBytes(E)}equals(e){this.assertSame(e);let{X:r,Y:n}=this.ep,{X:i,Y:s}=e.ep,o=u=>st.create(u),a=o(r*s)===o(n*i),c=o(n*s)===o(r*i);return a||c}is0(){return this.equals(t.ZERO)}};Object.freeze(ot.BASE);Object.freeze(ot.ZERO);Object.freeze(ot.prototype);Object.freeze(ot);var Yu=Object.freeze({Point:ot,hashToCurve(t,e){let r=e?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":e.DST,n=Es(t,r,64,Gr);return Yu.deriveToCurve(n)},hashToScalar(t,e={DST:Mo}){let r=Es(t,e.DST,64,Gr);return zo.create(Fe(r))},deriveToCurve(t){Se(t,64);let e=As(t.subarray(0,32)),r=Ho(e),n=As(t.subarray(32,64)),i=Ho(n);return new ot(r.add(i))}});var dr=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},on=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var Te={get(t=globalThis){let e=t.crypto;if(e?.subtle==null)throw new on("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 Ts,Gu=(async()=>{try{return await Te.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Xu(t,e,r){if(t.buffer instanceof ArrayBuffer){let n=await Te.get().subtle.importKey("raw",t.buffer,{name:"Ed25519"},!1,["verify"]);return await Te.get().subtle.verify({name:"Ed25519"},n,Be(e),Be(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Wu(t,e,r){return $o.verify(e,r instanceof Uint8Array?r:r.subarray(),t)}async function jo(t,e,r){return Ts==null&&(Ts=await Gu),Ts?Xu(t,e,r):Wu(t,e,r)}function cn(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var un=class{type="Ed25519";raw;constructor(e){this.raw=Ls(e,an)}toMultihash(){return Le.digest(Ve(this))}toCID(){return ue.createV1(114,this.toMultihash())}toString(){return Z.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ye(this.raw,e.raw)}verify(e,r,n){n?.signal?.throwIfAborted();let i=jo(this.raw,r,e);return cn(i)?i.then(s=>(n?.signal?.throwIfAborted(),s)):i}};function _s(t){return t=Ls(t,an),new un(t)}function Ls(t,e){if(t=Uint8Array.from(t??[]),t.length!==e)throw new j(`Key must be a Uint8Array of length ${e}, got ${t.length}`);return t}var Qu=Math.pow(2,7),ef=Math.pow(2,14),tf=Math.pow(2,21),Ds=Math.pow(2,28),ks=Math.pow(2,35),Rs=Math.pow(2,42),Cs=Math.pow(2,49),V=128,fe=127;function Ye(t){if(t<Qu)return 1;if(t<ef)return 2;if(t<tf)return 3;if(t<Ds)return 4;if(t<ks)return 5;if(t<Rs)return 6;if(t<Cs)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ps(t,e,r=0){switch(Ye(t)){case 8:e[r++]=t&255|V,t/=128;case 7:e[r++]=t&255|V,t/=128;case 6:e[r++]=t&255|V,t/=128;case 5:e[r++]=t&255|V,t/=128;case 4:e[r++]=t&255|V,t>>>=7;case 3:e[r++]=t&255|V,t>>>=7;case 2:e[r++]=t&255|V,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function rf(t,e,r=0){switch(Ye(t)){case 8:e.set(r++,t&255|V),t/=128;case 7:e.set(r++,t&255|V),t/=128;case 6:e.set(r++,t&255|V),t/=128;case 5:e.set(r++,t&255|V),t/=128;case 4:e.set(r++,t&255|V),t>>>=7;case 3:e.set(r++,t&255|V),t>>>=7;case 2:e.set(r++,t&255|V),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&fe,r<V||(r=t[e+1],n+=(r&fe)<<7,r<V)||(r=t[e+2],n+=(r&fe)<<14,r<V)||(r=t[e+3],n+=(r&fe)<<21,r<V)||(r=t[e+4],n+=(r&fe)*Ds,r<V)||(r=t[e+5],n+=(r&fe)*ks,r<V)||(r=t[e+6],n+=(r&fe)*Rs,r<V)||(r=t[e+7],n+=(r&fe)*Cs,r<V))return n;throw new RangeError("Could not decode varint")}function nf(t,e){let r=t.get(e),n=0;if(n+=r&fe,r<V||(r=t.get(e+1),n+=(r&fe)<<7,r<V)||(r=t.get(e+2),n+=(r&fe)<<14,r<V)||(r=t.get(e+3),n+=(r&fe)<<21,r<V)||(r=t.get(e+4),n+=(r&fe)*Ds,r<V)||(r=t.get(e+5),n+=(r&fe)*ks,r<V)||(r=t.get(e+6),n+=(r&fe)*Rs,r<V)||(r=t.get(e+7),n+=(r&fe)*Cs,r<V))return n;throw new RangeError("Could not decode varint")}function Yo(t,e,r=0){return e==null&&(e=be(Ye(t))),e instanceof Uint8Array?Ps(t,e,r):rf(t,e,r)}function Go(t,e=0){return t instanceof Uint8Array?Os(t,e):nf(t,e)}var Ns=new Float32Array([-0]),at=new Uint8Array(Ns.buffer);function Xo(t,e,r){Ns[0]=t,e[r]=at[0],e[r+1]=at[1],e[r+2]=at[2],e[r+3]=at[3]}function Wo(t,e){return at[0]=t[e],at[1]=t[e+1],at[2]=t[e+2],at[3]=t[e+3],Ns[0]}var Fs=new Float64Array([-0]),le=new Uint8Array(Fs.buffer);function Jo(t,e,r){Fs[0]=t,e[r]=le[0],e[r+1]=le[1],e[r+2]=le[2],e[r+3]=le[3],e[r+4]=le[4],e[r+5]=le[5],e[r+6]=le[6],e[r+7]=le[7]}function Qo(t,e){return le[0]=t[e],le[1]=t[e+1],le[2]=t[e+2],le[3]=t[e+3],le[4]=t[e+4],le[5]=t[e+5],le[6]=t[e+6],le[7]=t[e+7],Fs[0]}var of=BigInt(Number.MAX_SAFE_INTEGER),af=BigInt(Number.MIN_SAFE_INTEGER),Ae=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 xt;if(e<of&&e>af)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,i=e-(n<<32n);return r&&(n=~n|0n,i=~i|0n,++i>ea&&(i=0n,++n>ea&&(n=0n))),new t(Number(i),Number(n))}static fromNumber(e){if(e===0)return xt;let r=e<0;r&&(e=-e);let n=e>>>0,i=(e-n)/4294967296>>>0;return r&&(i=~i>>>0,n=~n>>>0,++n>4294967295&&(n=0,++i>4294967295&&(i=0))),new t(n,i)}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):xt}},xt=new Ae(0,0);xt.toBigInt=function(){return 0n};xt.zzEncode=xt.zzDecode=function(){return this};xt.length=function(){return 1};var ea=4294967296n;function ta(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 ra(t,e,r){if(r-e<1)return"";let i,s=[],o=0,a;for(;e<r;)a=t[e++],a<128?s[o++]=a:a>191&&a<224?s[o++]=(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,s[o++]=55296+(a>>10),s[o++]=56320+(a&1023)):s[o++]=(a&15)<<12|(t[e++]&63)<<6|t[e++]&63,o>8191&&((i??(i=[])).push(String.fromCharCode.apply(String,s)),o=0);return i!=null?(o>0&&i.push(String.fromCharCode.apply(String,s.slice(0,o))),i.join("")):String.fromCharCode.apply(String,s.slice(0,o))}function Ks(t,e,r){let n=r,i,s;for(let o=0;o<t.length;++o)i=t.charCodeAt(o),i<128?e[r++]=i:i<2048?(e[r++]=i>>6|192,e[r++]=i&63|128):(i&64512)===55296&&((s=t.charCodeAt(o+1))&64512)===56320?(i=65536+((i&1023)<<10)+(s&1023),++o,e[r++]=i>>18|240,e[r++]=i>>12&63|128,e[r++]=i>>6&63|128,e[r++]=i&63|128):(e[r++]=i>>12|224,e[r++]=i>>6&63|128,e[r++]=i&63|128);return r-n}function Ce(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function fn(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var Us=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=Be(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,Ce(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 Ce(this,4);return fn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ce(this,4);return fn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ce(this,4);let e=Wo(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Ce(this,4);let e=Qo(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 Ce(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return ra(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Ce(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Ce(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 Ae(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 Ce(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 Ce(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 Ce(this,8);let e=fn(this.buf,this.pos+=4),r=fn(this.buf,this.pos+=4);return new Ae(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+=Ye(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 pr(t){return new Us(t instanceof Uint8Array?t:t.subarray())}function we(t,e,r){let n=pr(t);return e.decode(n,void 0,r)}function Ms(t){let e=t??8192,r=e>>>1,n,i=e;return function(o){if(o<1||o>r)return be(o);i+o>e&&(n=be(e),i=0);let a=n.subarray(i,i+=o);return(i&7)!==0&&(i=(i|7)+1),a}}var Et=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function qs(){}var Hs=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},cf=Ms();function uf(t){return globalThis.Buffer!=null?be(t):cf(t)}var yr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Et(qs,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new Et(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new zs((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(ln,10,Ae.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=Ae.fromBigInt(e);return this._push(ln,r.length(),r)}uint64Number(e){return this._push(Ps,Ye(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=Ae.fromBigInt(e).zzEncode();return this._push(ln,r.length(),r)}sint64Number(e){let r=Ae.fromNumber(e).zzEncode();return this._push(ln,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Vs,1,e?1:0)}fixed32(e){return this._push(mr,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=Ae.fromBigInt(e);return this._push(mr,4,r.lo)._push(mr,4,r.hi)}fixed64Number(e){let r=Ae.fromNumber(e);return this._push(mr,4,r.lo)._push(mr,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(Xo,4,e)}double(e){return this._push(Jo,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(Vs,1,0):this.uint32(r)._push(lf,r,e)}string(e){let r=ta(e);return r!==0?this.uint32(r)._push(Ks,r,e):this._push(Vs,1,0)}fork(){return this.states=new Hs(this),this.head=this.tail=new Et(qs,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 Et(qs,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=uf(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function Vs(t,e,r){e[r]=t&255}function ff(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var zs=class extends Et{next;constructor(e,r){super(ff,e,r),this.next=void 0}};function ln(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 mr(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 lf(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(yr.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(hf,e,t),this},yr.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(df,e,t),this});function hf(t,e,r){e.set(t,r)}function df(t,e,r){t.length<40?Ks(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(z(t),r)}function $s(){return new yr}function xe(t,e){let r=$s();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*Ee(t,e,r){let n=pr(t);yield*e.stream(n,void 0,"$",r)}var hn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function dn(t,e,r,n,i){return{name:t,type:e,encode:r,decode:n,stream:i}}function js(t){function e(s){if(t[s.toString()]==null)throw new Error("Invalid enum value");return t[s]}let r=function(o,a){let c=e(o);a.int32(c)},n=function(o){let a=o.int32();return e(a)},i=function*(o){let a=o.int32();yield e(a)};return dn("enum",hn.VARINT,r,n,i)}function ve(t,e,r){return dn("message",hn.LENGTH_DELIMITED,t,e,r)}var ee=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var Y;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.ECDSA="ECDSA"})(Y||(Y={}));var Zs;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(Zs||(Zs={}));(function(t){t.codec=()=>js(Zs)})(Y||(Y={}));var Ke;(function(t){let e;t.codec=()=>(e==null&&(e=ve((s,o,a={})=>{a.lengthDelimited!==!1&&o.fork(),s.Type!=null&&(o.uint32(8),Y.codec().encode(s.Type,o)),s.Data!=null&&(o.uint32(18),o.bytes(s.Data)),a.lengthDelimited!==!1&&o.ldelim()},(s,o,a={})=>{let c={},u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=Y.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,o,a,c={}){let u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:Y.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return xe(s,t.codec())}t.encode=r;function n(s,o){return we(s,t.codec(),o)}t.decode=n;function i(s,o){return Ee(s,t.codec(),o)}t.stream=i})(Ke||(Ke={}));var Ys;(function(t){let e;t.codec=()=>(e==null&&(e=ve((s,o,a={})=>{a.lengthDelimited!==!1&&o.fork(),s.Type!=null&&(o.uint32(8),Y.codec().encode(s.Type,o)),s.Data!=null&&(o.uint32(18),o.bytes(s.Data)),a.lengthDelimited!==!1&&o.ldelim()},(s,o,a={})=>{let c={},u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=Y.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,o,a,c={}){let u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:Y.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return xe(s,t.codec())}t.encode=r;function n(s,o){return we(s,t.codec(),o)}t.decode=n;function i(s,o){return Ee(s,t.codec(),o)}t.stream=i})(Ys||(Ys={}));var gr={};me(gr,{MAX_RSA_KEY_SIZE:()=>Gs,generateRSAKeyPair:()=>ca,jwkToJWKKeyPair:()=>ua,jwkToPkcs1:()=>bf,jwkToPkix:()=>Qs,jwkToRSAPrivateKey:()=>ni,pkcs1MessageToJwk:()=>Ws,pkcs1MessageToRSAPrivateKey:()=>ei,pkcs1ToJwk:()=>yf,pkcs1ToRSAPrivateKey:()=>aa,pkixMessageToJwk:()=>Js,pkixMessageToRSAPublicKey:()=>ri,pkixToJwk:()=>gf,pkixToRSAPublicKey:()=>ti});var zt=class{type="RSA";jwk;_raw;_multihash;constructor(e,r){this.jwk=e,this._multihash=r}get raw(){return this._raw==null&&(this._raw=gr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return ue.createV1(114,this._multihash)}toString(){return Z.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ye(this.raw,e.raw)}verify(e,r,n){return oa(this.jwk,r,e,n)}},br=class{type="RSA";jwk;_raw;publicKey;constructor(e,r){this.jwk=e,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=gr.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ye(this.raw,e.raw)}sign(e,r){return ia(this.jwk,e,r)}};var Gs=8192,Xs=18,pf=1062,mf=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function yf(t){let e=qe(t);return Ws(e)}function Ws(t){return{n:H(t[1],"base64url"),e:H(t[2],"base64url"),d:H(t[3],"base64url"),p:H(t[4],"base64url"),q:H(t[5],"base64url"),dp:H(t[6],"base64url"),dq:H(t[7],"base64url"),qi:H(t[8],"base64url"),kty:"RSA"}}function bf(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 j("JWK was missing components");return Je([ge(Uint8Array.from([0])),ge(z(t.n,"base64url")),ge(z(t.e,"base64url")),ge(z(t.d,"base64url")),ge(z(t.p,"base64url")),ge(z(t.q,"base64url")),ge(z(t.dp,"base64url")),ge(z(t.dq,"base64url")),ge(z(t.qi,"base64url"))]).subarray()}function gf(t){let e=qe(t,{offset:0});return Js(e)}function Js(t){let e=qe(t[1],{offset:0});return{kty:"RSA",n:H(e[0],"base64url"),e:H(e[1],"base64url")}}function Qs(t){if(t.n==null||t.e==null)throw new j("JWK was missing components");return Je([mf,Hr(Je([ge(z(t.n,"base64url")),ge(z(t.e,"base64url"))]))]).subarray()}function aa(t){let e=qe(t);return ei(e)}function ei(t){let e=Ws(t);return ni(e)}function ti(t,e){if(t.byteLength>=pf)throw new Bt("Key size is too large");let r=qe(t,{offset:0});return ri(r,t,e)}function ri(t,e,r){let n=Js(t);if(r==null){let i=Ot(Ke.encode({Type:Y.RSA,Data:e}));r=Oe(Xs,i)}return new zt(n,r)}function ni(t){if(la(t)>Gs)throw new j("Key size is too large");let e=ua(t),r=Ot(Ke.encode({Type:Y.RSA,Data:Qs(e.publicKey)})),n=Oe(Xs,r);return new br(e.privateKey,new zt(e.publicKey,n))}async function ca(t){if(t>Gs)throw new j("Key size is too large");let e=await fa(t),r=Ot(Ke.encode({Type:Y.RSA,Data:Qs(e.publicKey)})),n=Oe(Xs,r);return new br(e.privateKey,new zt(e.publicKey,n))}function ua(t){if(t==null)throw new j("Missing key parameter");return{privateKey:t,publicKey:{kty:t.kty,n:t.n,e:t.e}}}async function fa(t,e){let r=await Te.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 wf(r,e);return{privateKey:n[0],publicKey:n[1]}}async function ia(t,e,r){let n=await Te.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let i=await Te.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,Be(e instanceof Uint8Array?e:e.subarray()));return r?.signal?.throwIfAborted(),new Uint8Array(i,0,i.byteLength)}async function oa(t,e,r,n){let i=await Te.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await Te.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},i,Be(e),Be(r instanceof Uint8Array?r:r.subarray()));return n?.signal?.throwIfAborted(),s}async function wf(t,e){if(t.privateKey==null||t.publicKey==null)throw new j("Private and public key are required");let r=await Promise.all([Te.get().subtle.exportKey("jwk",t.privateKey),Te.get().subtle.exportKey("jwk",t.publicKey)]);return e?.signal?.throwIfAborted(),r}function la(t){if(t.kty!=="RSA")throw new j("invalid key type");if(t.n==null)throw new j("invalid key modulus");return z(t.n,"base64url").length*8}var pn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,r){if(zr(e),Se(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,i=new Uint8Array(n);i.set(r.length>n?e.create().update(r).digest():r);for(let s=0;s<i.length;s++)i[s]^=54;this.iHash.update(i),this.oHash=e.create();for(let s=0;s<i.length;s++)i[s]^=106;this.oHash.update(i),ze(i)}update(e){return Pt(this),this.iHash.update(e),this}digestInto(e){Pt(this),$r(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:i,destroyed:s,blockLen:o,outputLen:a}=this;return e=e,e.finished=i,e.destroyed=s,e.blockLen=o,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()}},ha=(()=>{let t=((e,r,n)=>new pn(e,r).update(n).digest());return t.create=(e,r)=>new pn(e,r),t})();var da=(t,e)=>(t+(t>=0?e:-e)/pa)/e;function xf(t,e,r){Kt("scalar",t,Ue,r);let[[n,i],[s,o]]=e,a=da(o*t,r),c=da(-i*t,r),u=t-a*n-c*s,f=-a*i-c*o,l=u<Ue,h=f<Ue;l&&(u=-u),h&&(f=-f);let d=ur(Math.ceil(Ut(r)/2))+ct;if(u<Ue||u>=d||f<Ue||f>=d)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:u,k2neg:h,k2:f}}function ii(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function si(t,e){Re(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return De(r.lowS,"lowS"),De(r.prehash,"prehash"),r.format!==void 0&&ii(r.format),r}var oi=class extends Error{constructor(e=""){super(e)}},Pe={Err:oi,_tlv:{encode:(t,e)=>{let{Err:r}=Pe;if(ke(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,i=ar(n);if(i.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?ar(i.length/2|128):"";return ar(t)+s+i+e},decode(t,e){let{Err:r}=Pe;e=M(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 i=e[n++],s=!!(i&128),o=0;if(!s)o=i;else{let c=i&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)o=o<<8|f;if(n+=c,o<128)throw new r("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+o);if(a.length!==o)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+o)}}},_int:{encode(t){let{Err:e}=Pe;if(Jr(t),t<Ue)throw new e("integer: negative integers are not allowed");let r=ar(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}=Pe;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}=Pe,i=M(t,void 0,"signature"),{v:s,l:o}=n.decode(48,i);if(o.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{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}=Pe,n=e.encode(2,r.encode(t.r)),i=e.encode(2,r.encode(t.s)),s=n+i;return e.encode(48,s)}};Object.freeze(Pe._tlv);Object.freeze(Pe._int);Object.freeze(Pe);var Ue=BigInt(0),ct=BigInt(1),pa=BigInt(2),mn=BigInt(3),Ef=BigInt(4);function ma(t,e={}){let r=rn("weierstrass",t,e),n=r.Fp,i=r.Fn,s=r.CURVE,{h:o,n:a}=s;Re(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c,allowInfinityPoint:u}=e;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let f=ba(n,i);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function h(P,p,b){if(u&&p.is0())return Uint8Array.of(0);let{x:S,y:x}=p.toAffine(),w=n.toBytes(S);if(De(b,"isCompressed"),b){l();let A=!n.isOdd(x);return re(ya(A),w)}else return re(Uint8Array.of(4),w,n.toBytes(x))}function d(P){M(P,void 0,"Point");let{publicKey:p,publicKeyUncompressed:b}=f,S=P.length,x=P[0],w=P.subarray(1);if(u&&S===1&&x===0)return{x:n.ZERO,y:n.ZERO};if(S===p&&(x===2||x===3)){let A=n.fromBytes(w);if(!n.isValid(A))throw new Error("bad point: is not on curve, wrong x");let L=y(A),T;try{T=n.sqrt(L)}catch(U){let q=U instanceof Error?": "+U.message:"";throw new Error("bad point: is not on curve, sqrt error"+q)}l();let D=n.isOdd(T);return(x&1)===1!==D&&(T=n.neg(T)),{x:A,y:T}}else if(S===b&&x===4){let A=n.BYTES,L=n.fromBytes(w.subarray(0,A)),T=n.fromBytes(w.subarray(A,A*2));if(!m(L,T))throw new Error("bad point: is not on curve");return{x:L,y:T}}else throw new Error(`bad point: got length ${S}, expected compressed=${p} or uncompressed=${b}`)}let g=e.toBytes===void 0?h:e.toBytes,E=e.fromBytes===void 0?d:e.fromBytes;function y(P){let p=n.sqr(P),b=n.mul(p,P);return n.add(n.add(b,n.mul(P,s.a)),s.b)}function m(P,p){let b=n.sqr(p),S=y(P);return n.eql(b,S)}if(!m(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let v=n.mul(n.pow(s.a,mn),Ef),I=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(v,I)))throw new Error("bad curve params: a or b");function R(P,p,b=!1){if(!n.isValid(p)||b&&n.is0(p))throw new Error(`bad point coordinate ${P}`);return p}function _(P){if(!(P instanceof B))throw new Error("Weierstrass Point expected")}function O(P){if(!c||!c.basises)throw new Error("no endo");return xf(P,c.basises,i.ORDER)}function k(P,p,b,S,x){return b=new B(n.mul(b.X,P),b.Y,b.Z),p=lr(S,p),b=lr(x,b),p.add(b)}class B{static BASE=new B(s.Gx,s.Gy,n.ONE);static ZERO=new B(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=i;X;Y;Z;constructor(p,b,S){this.X=R("x",p),this.Y=R("y",b,!0),this.Z=R("z",S),Object.freeze(this)}static CURVE(){return s}static fromAffine(p){let{x:b,y:S}=p||{};if(!p||!n.isValid(b)||!n.isValid(S))throw new Error("invalid affine point");if(p instanceof B)throw new Error("projective point not allowed");return n.is0(b)&&n.is0(S)?B.ZERO:new B(b,S,n.ONE)}static fromBytes(p){let b=B.fromAffine(E(M(p,void 0,"point")));return b.assertValidity(),b}static fromHex(p){return B.fromBytes(Ft(p))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=8,b=!0){return F.createCache(this,p),b||this.multiply(mn),this}assertValidity(){let p=this;if(p.is0()){if(e.allowInfinityPoint&&n.is0(p.X)&&n.eql(p.Y,n.ONE)&&n.is0(p.Z))return;throw new Error("bad point: ZERO")}let{x:b,y:S}=p.toAffine();if(!n.isValid(b)||!n.isValid(S))throw new Error("bad point: x or y not field elements");if(!m(b,S))throw new Error("bad point: equation left != right");if(!p.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:p}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(p)}equals(p){_(p);let{X:b,Y:S,Z:x}=this,{X:w,Y:A,Z:L}=p,T=n.eql(n.mul(b,L),n.mul(w,x)),D=n.eql(n.mul(S,L),n.mul(A,x));return T&&D}negate(){return new B(this.X,n.neg(this.Y),this.Z)}double(){let{a:p,b}=s,S=n.mul(b,mn),{X:x,Y:w,Z:A}=this,L=n.ZERO,T=n.ZERO,D=n.ZERO,C=n.mul(x,x),U=n.mul(w,w),q=n.mul(A,A),K=n.mul(x,w);return K=n.add(K,K),D=n.mul(x,A),D=n.add(D,D),L=n.mul(p,D),T=n.mul(S,q),T=n.add(L,T),L=n.sub(U,T),T=n.add(U,T),T=n.mul(L,T),L=n.mul(K,L),D=n.mul(S,D),q=n.mul(p,q),K=n.sub(C,q),K=n.mul(p,K),K=n.add(K,D),D=n.add(C,C),C=n.add(D,C),C=n.add(C,q),C=n.mul(C,K),T=n.add(T,C),q=n.mul(w,A),q=n.add(q,q),C=n.mul(q,K),L=n.sub(L,C),D=n.mul(q,U),D=n.add(D,D),D=n.add(D,D),new B(L,T,D)}add(p){_(p);let{X:b,Y:S,Z:x}=this,{X:w,Y:A,Z:L}=p,T=n.ZERO,D=n.ZERO,C=n.ZERO,U=s.a,q=n.mul(s.b,mn),K=n.mul(b,w),te=n.mul(S,A),ne=n.mul(x,L),se=n.add(b,S),W=n.add(w,A);se=n.mul(se,W),W=n.add(K,te),se=n.sub(se,W),W=n.add(b,x);let pe=n.add(w,L);return W=n.mul(W,pe),pe=n.add(K,ne),W=n.sub(W,pe),pe=n.add(S,x),T=n.add(A,L),pe=n.mul(pe,T),T=n.add(te,ne),pe=n.sub(pe,T),C=n.mul(U,W),T=n.mul(q,ne),C=n.add(T,C),T=n.sub(te,C),C=n.add(te,C),D=n.mul(T,C),te=n.add(K,K),te=n.add(te,K),ne=n.mul(U,ne),W=n.mul(q,W),te=n.add(te,ne),ne=n.sub(K,ne),ne=n.mul(U,ne),W=n.add(W,ne),K=n.mul(te,W),D=n.add(D,K),K=n.mul(pe,W),T=n.mul(se,T),T=n.sub(T,K),K=n.mul(se,te),C=n.mul(pe,C),C=n.add(C,K),new B(T,D,C)}subtract(p){return _(p),this.add(p.negate())}is0(){return this.equals(B.ZERO)}multiply(p){let{endo:b}=e;if(!i.isValidNot0(p))throw new RangeError("invalid scalar: out of range");let S,x,w=A=>F.cached(this,A,L=>wt(B,L));if(b){let{k1neg:A,k1:L,k2neg:T,k2:D}=O(p),{p:C,f:U}=w(L),{p:q,f:K}=w(D);x=U.add(K),S=k(b.beta,C,q,A,T)}else{let{p:A,f:L}=w(p);S=A,x=L}return wt(B,[S,x])[0]}multiplyUnsafe(p){let{endo:b}=e,S=this,x=p;if(!i.isValid(x))throw new RangeError("invalid scalar: out of range");if(x===Ue||S.is0())return B.ZERO;if(x===ct)return S;if(F.hasCache(this))return this.multiply(x);if(b){let{k1neg:w,k1:A,k2neg:L,k2:T}=O(x),{p1:D,p2:C}=Fo(B,S,A,T);return k(b.beta,D,C,w,L)}else return F.unsafe(S,x)}toAffine(p){let b=this,S=p,{X:x,Y:w,Z:A}=b;if(n.eql(A,n.ONE))return{x,y:w};let L=b.is0();S==null&&(S=L?n.ONE:n.inv(A));let T=n.mul(x,S),D=n.mul(w,S),C=n.mul(A,S);if(L)return{x:n.ZERO,y:n.ZERO};if(!n.eql(C,n.ONE))throw new Error("invZ was invalid");return{x:T,y:D}}isTorsionFree(){let{isTorsionFree:p}=e;return o===ct?!0:p?p(B,this):F.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:p}=e;return o===ct?this:p?p(B,this):this.multiplyUnsafe(o)}isSmallOrder(){return o===ct?this.is0():this.clearCofactor().is0()}toBytes(p=!0){return De(p,"isCompressed"),this.assertValidity(),g(B,this,p)}toHex(p=!0){return Nt(this.toBytes(p))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let N=i.BITS,F=new Vt(B,e.endo?Math.ceil(N/2):N);return N>=8&&B.BASE.precompute(8),Object.freeze(B.prototype),Object.freeze(B),B}function ya(t){return Uint8Array.of(t?2:3)}function ba(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function vf(t,e={}){let{Fn:r}=t,n=e.randomBytes===void 0?or:e.randomBytes,i=Object.assign(ba(t.Fp,r),{seed:Math.max(ms(r.ORDER),16)});function s(d){try{let g=r.fromBytes(d);return r.isValidNot0(g)}catch{return!1}}function o(d,g){let{publicKey:E,publicKeyUncompressed:y}=i;try{let m=d.length;return g===!0&&m!==E||g===!1&&m!==y?!1:!!t.fromBytes(d)}catch{return!1}}function a(d){return d=d===void 0?n(i.seed):d,ys(M(d,i.seed,"seed"),r.ORDER)}function c(d,g=!0){return t.BASE.multiply(r.fromBytes(d)).toBytes(g)}function u(d){let{secretKey:g,publicKey:E,publicKeyUncompressed:y}=i,m=r._lengths;if(!mt(d))return;let v=M(d,void 0,"key").length,I=v===E||v===y,R=v===g||!!m?.includes(v);if(!(I&&R))return I}function f(d,g,E=!0){if(u(d)===!0)throw new Error("first arg must be private key");if(u(g)===!1)throw new Error("second arg must be public key");let y=r.fromBytes(d);return t.fromBytes(g).multiply(y).toBytes(E)}let l={isValidSecretKey:s,isValidPublicKey:o,randomSecretKey:a},h=nn(a,c);return Object.freeze(l),Object.freeze(i),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:h,Point:t,utils:l,lengths:i})}function ga(t,e,r={}){let n=e;zr(n),Re(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let i=r.randomBytes===void 0?or:r.randomBytes,s=r.hmac===void 0?(x,w)=>ha(n,x,w):r.hmac,{Fp:o,Fn:a}=t,{ORDER:c,BITS:u}=a,{keygen:f,getPublicKey:l,getSharedSecret:h,utils:d,lengths:g}=vf(t,r),E={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},y=c*pa+ct<o.ORDER;function m(x){let w=c>>ct;return x>w}function v(x,w){if(!a.isValidNot0(w))throw new Error(`invalid signature ${x}: out of range 1..Point.Fn.ORDER`);return w}function I(){if(y)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function R(x,w){ii(w);let A=g.signature,L=w==="compact"?A:w==="recovered"?A+1:void 0;return M(x,L)}class _{r;s;recovery;constructor(w,A,L){if(this.r=v("r",w),this.s=v("s",A),L!=null){if(I(),![0,1,2,3].includes(L))throw new Error("invalid recovery id");this.recovery=L}Object.freeze(this)}static fromBytes(w,A=E.format){R(w,A);let L;if(A==="der"){let{r:U,s:q}=Pe.toSig(M(w));return new _(U,q)}A==="recovered"&&(L=w[0],A="compact",w=w.subarray(1));let T=g.signature/2,D=w.subarray(0,T),C=w.subarray(T,T*2);return new _(a.fromBytes(D),a.fromBytes(C),L)}static fromHex(w,A){return this.fromBytes(Ft(w),A)}assertRecovery(){let{recovery:w}=this;if(w==null)throw new Error("invalid recovery id: must be present");return w}addRecoveryBit(w){return new _(this.r,this.s,w)}recoverPublicKey(w){let{r:A,s:L}=this,T=this.assertRecovery(),D=T===2||T===3?A+c:A;if(!o.isValid(D))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let C=o.toBytes(D),U=t.fromBytes(re(ya((T&1)===0),C)),q=a.inv(D),K=k(M(w,void 0,"msgHash")),te=a.create(-K*q),ne=a.create(L*q),se=t.BASE.multiplyUnsafe(te).add(U.multiplyUnsafe(ne));if(se.is0())throw new Error("invalid recovery: point at infinify");return se.assertValidity(),se}hasHighS(){return m(this.s)}toBytes(w=E.format){if(ii(w),w==="der")return Ft(Pe.hexFromSig(this));let{r:A,s:L}=this,T=a.toBytes(A),D=a.toBytes(L);return w==="recovered"?(I(),re(Uint8Array.of(this.assertRecovery()),T,D)):re(T,D)}toHex(w){return Nt(this.toBytes(w))}}Object.freeze(_.prototype),Object.freeze(_);let O=r.bits2int===void 0?function(w){if(w.length>8192)throw new Error("input is too large");let A=yt(w),L=w.length*8-u;return L>0?A>>BigInt(L):A}:r.bits2int,k=r.bits2int_modN===void 0?function(w){return a.create(O(w))}:r.bits2int_modN,B=ur(u);function N(x){return Kt("num < 2^"+u,x,Ue,B),a.toBytes(x)}function F(x,w){return M(x,void 0,"message"),w?M(n(x),void 0,"prehashed message"):x}function P(x,w,A){let{lowS:L,prehash:T,extraEntropy:D}=si(A,E);x=F(x,T);let C=k(x),U=a.fromBytes(w);if(!a.isValidNot0(U))throw new Error("invalid private key");let q=[N(U),N(C)];if(D!=null&&D!==!1){let se=D===!0?i(g.secretKey):D;q.push(M(se,void 0,"extraEntropy"))}let K=re(...q),te=C;function ne(se){let W=O(se);if(!a.isValidNot0(W))return;let pe=a.inv(W),It=t.BASE.multiply(W).toAffine(),Yt=a.create(It.x);if(Yt===Ue)return;let Nr=a.create(pe*a.create(te+Yt*U));if(Nr===Ue)return;let Si=(It.x===Yt?0:2)|Number(It.y&ct),Ai=Nr;return L&&m(Nr)&&(Ai=a.neg(Nr),Si^=1),new _(Yt,Ai,y?void 0:Si)}return{seed:K,k2sig:ne}}function p(x,w,A={}){let{seed:L,k2sig:T}=P(x,w,A);return xo(n.outputLen,a.BYTES,s)(L,T).toBytes(A.format)}function b(x,w,A,L={}){let{lowS:T,prehash:D,format:C}=si(L,E);if(A=M(A,void 0,"publicKey"),w=F(w,D),!mt(x)){let U=x instanceof _?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+U)}R(x,C);try{let U=_.fromBytes(x,C),q=t.fromBytes(A);if(T&&U.hasHighS())return!1;let{r:K,s:te}=U,ne=k(w),se=a.inv(te),W=a.create(ne*se),pe=a.create(K*se),It=t.BASE.multiplyUnsafe(W).add(q.multiplyUnsafe(pe));return It.is0()?!1:a.create(It.x)===K}catch{return!1}}function S(x,w,A={}){let{prehash:L}=si(A,E);return w=F(w,L),_.fromBytes(x,"recovered").recoverPublicKey(w).toBytes()}return Object.freeze({keygen:f,getPublicKey:l,getSharedSecret:h,utils:d,lengths:g,Point:t,sign:p,verify:b,recoverPublicKey:S,Signature:_,hash:n})}var ci={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Sf={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var wa=BigInt(2);function Af(t){let e=ci.p,r=BigInt(3),n=BigInt(6),i=BigInt(11),s=BigInt(22),o=BigInt(23),a=BigInt(44),c=BigInt(88),u=t*t*t%e,f=u*u*t%e,l=$(f,r,e)*f%e,h=$(l,r,e)*f%e,d=$(h,wa,e)*u%e,g=$(d,i,e)*d%e,E=$(g,s,e)*g%e,y=$(E,a,e)*E%e,m=$(y,c,e)*y%e,v=$(m,a,e)*E%e,I=$(v,r,e)*f%e,R=$(I,o,e)*g%e,_=$(R,n,e)*u%e,O=$(_,wa,e);if(!ai.eql(ai.sqr(O),t))throw new Error("Cannot find square root");return O}var ai=Mt(ci.p,{sqrt:Af}),If=ma(ci,{Fp:ai,endo:Sf}),$t=ga(If,Ot);function xa(t,e,r,n){let i=ht.digest(r instanceof Uint8Array?r:r.subarray());if(cn(i))return i.then(({digest:s})=>(n?.signal?.throwIfAborted(),$t.verify(e,s,t,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new dr(String(s))});try{return n?.signal?.throwIfAborted(),$t.verify(e,i.digest,t,{prehash:!1,format:"der"})}catch(s){throw new dr(String(s))}}var yn=class{type="secp256k1";raw;_key;constructor(e){this._key=va(e),this.raw=Ea(this._key)}toMultihash(){return Le.digest(Ve(this))}toCID(){return ue.createV1(114,this.toMultihash())}toString(){return Z.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ye(this.raw,e.raw)}verify(e,r,n){return xa(this._key,r,e,n)}};function ui(t){return new yn(t)}function Ea(t){return $t.Point.fromBytes(t).toBytes()}function va(t){try{return $t.Point.fromBytes(t),t}catch(e){throw new Bt(String(e))}}function fi(t,e){let{Type:r,Data:n}=Ke.decode(t),i=n??new Uint8Array;switch(r){case Y.RSA:return ti(i,e);case Y.Ed25519:return _s(i);case Y.secp256k1:return ui(i);case Y.ECDSA:return Jn(i);default:throw new ut}}function Sa(t){let{Type:e,Data:r}=Ke.decode(t.digest),n=r??new Uint8Array;switch(e){case Y.Ed25519:return _s(n);case Y.secp256k1:return ui(n);case Y.ECDSA:return Jn(n);default:throw new ut}}function Ve(t){return Ke.encode({Type:Y[t.type],Data:t.raw})}var Aa=Symbol.for("nodejs.util.inspect.custom"),Bf=114,wr=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()})`}[An]=!0;toString(){return this.string==null&&(this.string=Z.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ue.createV1(Bf,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return ye(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return ye(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[Aa](){return`PeerId(${this.toString()})`}},xr=class extends wr{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Er=class extends wr{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},vr=class extends wr{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},Tf=2336,bn=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=Le.digest(z(this.url))}[Aa](){return`PeerId(${this.url})`}[An]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ue.createV1(Tf,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=H(e)),e.toString()===this.toString())}};function li(t){if(t.type==="Ed25519")return new Er({multihash:t.toCID().multihash,publicKey:t});if(t.type==="secp256k1")return new vr({multihash:t.toCID().multihash,publicKey:t});if(t.type==="RSA")return new xr({multihash:t.toCID().multihash,publicKey:t});throw new ut}function Ia(t){return li(t.publicKey)}function Sr(t){if(_f(t))return new xr({multihash:t});if(Lf(t))try{let e=Sa(t);if(e.type==="Ed25519")return new Er({multihash:t,publicKey:e});if(e.type==="secp256k1")return new vr({multihash:t,publicKey:e})}catch{let r=H(t.digest);return new bn(new URL(r))}throw new Kr("Supplied PeerID Multihash is invalid")}function Lf(t){return t.code===Le.code}function _f(t){return t.code===ht.code}function vt(t,e){let r={[Symbol.iterator]:()=>r,next:()=>{let n=t.next(),i=n.value;return n.done===!0||i==null?{done:!0,value:void 0}:{done:!1,value:e(i)}}};return r}function gn(t){let e=Xe(Z.decode(`z${t}`));return Sr(e)}var Ar=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 vt(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 vt(this.map.values(),e=>e.key)}values(){return vt(this.map.values(),e=>e.value)}get size(){return this.map.size}};var Ir=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 vt(this.set.entries(),e=>{let r=gn(e[0]);return[r,r]})}forEach(e){this.set.forEach(r=>{let n=gn(r);e(n,n,this)})}has(e){return this.set.has(e.toString())}values(){return vt(this.set.values(),e=>gn(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 hi=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},Ba=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function Br(t,e){let{milliseconds:r,fallback:n,message:i,customTimers:s={setTimeout,clearTimeout},signal:o}=e,a,c,f=new Promise((l,h)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(o?.aborted){h(Ba(o));return}if(o&&(c=()=>{h(Ba(o))},o.addEventListener("abort",c,{once:!0})),t.then(l,h),r===Number.POSITIVE_INFINITY)return;let d=new hi;a=s.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(g){h(g)}return}typeof t.cancel=="function"&&t.cancel(),i===!1?l():i instanceof Error?h(i):(d.message=i??`Promise timed out after ${r} milliseconds`,h(d))},r)}).finally(()=>{f.clear(),c&&o&&o.removeEventListener("abort",c)});return f.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},f}var Df=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 kf(t,e,r){let n,i=new Promise((s,o)=>{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}=Df(t),l=async(...d)=>{let g=r.multiArgs?d:d[0];if(r.filter)try{if(!await r.filter(g))return}catch(E){n(),o(E);return}c.push(g),r.count===c.length&&(n(),s(c))},h=(...d)=>{n(),o(r.rejectionMultiArgs?d:d[0])};n=()=>{for(let d of a)f(d,l);for(let d of r.rejectionEvents)a.includes(d)||f(d,h)};for(let d of a)u(d,l);for(let d of r.rejectionEvents)a.includes(d)||u(d,h);r.signal&&r.signal.addEventListener("abort",()=>{h(r.signal.reason)},{once:!0}),r.resolveImmediately&&s(c)});if(i.cancel=n,typeof r.timeout=="number"){let s=Br(i,{milliseconds:r.timeout});return s.cancel=()=>{n(),s.clear()},s}return i}function Ta(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=kf(t,e,r),i=n.then(s=>s[0]);return i.cancel=n.cancel,i}var St=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function Rf(t){return t.reason}async function di(t,e,r){if(e==null)return t;let n=r?.translateError??Rf;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let i;try{return await Promise.race([t,new Promise((s,o)=>{i=()=>{o(n(e))},e.addEventListener("abort",i)})])}finally{i!=null&&e.removeEventListener("abort",i)}}var Pf=4194304,wn=class extends Error{static name="UnwrappedError";name="UnwrappedError"},mi=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},yi=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},bi=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Of(t){return typeof t?.closeRead=="function"}function Nf(t){return typeof t?.close=="function"}function pi(t){return Of(t)?t.remoteWriteStatus!=="writable"&&t.readBufferLength===0:Nf(t)?t.status!=="open":!1}function Ff(t){return t?.addEventListener!=null&&t?.removeEventListener!=null&&t?.send!=null&&t?.push!=null&&t?.log!=null}function Kf(t,e){let r=e?.maxBufferSize??Pf,n=new ie,i,s=!1;if(!Ff(t))throw new j("Argument should be a Stream or a Multiaddr");let o=f=>{if(n.append(f.data),n.byteLength>r){let l=n.byteLength;n.consume(n.byteLength),i?.reject(new Error(`Read buffer overflow - ${l} > ${r}`))}i?.resolve()};t.addEventListener("message",o);let a=f=>{f.error!=null?i?.reject(f.error):i?.resolve()};t.addEventListener("close",a);let c=()=>{i?.resolve()};t.addEventListener("remoteCloseWrite",c);let u={readBuffer:n,async read(f){if(s===!0)throw new wn("Stream was unwrapped");if(pi(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 St(`Unexpected EOF - stream closed after reading ${n.byteLength}/${f.bytes} bytes`)}let l=f?.bytes??1;for(i=Promise.withResolvers();;){if(n.byteLength>=l){i.resolve();break}if(await di(i.promise,f?.signal),pi(t)){if(n.byteLength===0&&f?.bytes==null)return null;break}i=Promise.withResolvers()}let h=f?.bytes??n.byteLength;if(n.byteLength<h){if(pi(t))throw t.log.error("closed while reading %d/%d bytes",n.byteLength,h),new St(`Unexpected EOF - stream closed while reading ${n.byteLength}/${h} bytes`);return u.read(f)}let d=n.sublist(0,h);return n.consume(h),d},async write(f,l){if(s===!0)throw new wn("Stream was unwrapped");t.send(f)||await Ta(t,"drain",{signal:l?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,t.removeEventListener("message",o),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 Uf(t,e={}){let r=Kf(t,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=Ye(e.maxDataLength));let n=e?.lengthDecoder??Go,i=e?.lengthEncoder??Yo;return{async read(o){let a=-1,c=new ie;for(;;){let f=await r.read({...o,bytes:1});if(f==null)break;c.append(f);try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new mi("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new bi(`Message length length too long - ${c.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new yi(`Message length too long - ${a} > ${e.maxDataLength}`);let u=await r.read({...o,bytes:a});if(u==null)throw t.log.error("tried to read %d bytes but the stream closed",a),new St(`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 St(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(o,a){await r.write(new ie(i(o.byteLength),o),a)},async writeV(o,a){let c=new ie(...o.flatMap(u=>[i(u.byteLength),u]));await r.write(c,a)},unwrap(){return r.unwrap()}}}function gi(t,e){let r=Uf(t,e),n={read:async(i,s)=>{let o=await r.read(s);return i.decode(o)},write:async(i,s,o)=>{await r.write(s.encode(i),o)},writeV:async(i,s,o)=>{await r.writeV(i.map(a=>s.encode(a)),o)},pb:i=>({read:async s=>n.read(i,s),write:async(s,o)=>n.write(s,i,o),writeV:async(s,o)=>n.writeV(s,i,o),unwrap:()=>n}),unwrap:()=>r.unwrap()};return n}var xi=Ha(_a(),1);function Ei(t,e,r){let n=0,i=t.length;for(;i>0;){let s=Math.trunc(i/2),o=n+s;r(t[o],e)<=0?(n=++o,i-=s+1):i=s}return n}var Vf=100,jt=class{#e=[];#t=0;enqueue(e,r){let{priority:n=0,id:i}=r??{},{size:s}=this,o={priority:n,id:i,run:e};if(s===0){this.#e.length=0,this.#t=0,this.#e.push(o);return}if(this.#e.at(-1).priority>=n){this.#e.push(o);return}this.#i();let a=Ei(this.#e,o,(c,u)=>u.priority-c.priority);this.#e.splice(a,0,o)}setPriority(e,r){let n=this.#e.findIndex((s,o)=>o>=this.#t&&s.id===e);if(n===-1)throw new ReferenceError(`No promise function with the id "${e}" exists in the queue.`);let[i]=this.#e.splice(n,1);this.enqueue(i.run,{priority:r,id:e})}remove(e){let r=this.#e.findIndex((n,i)=>i<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>Vf&&this.#t>this.#e.length/2&&this.#i(),e?.run}filter(e){let r=[];for(let n=this.#t;n<this.#e.length;n++){let i=this.#e[n];i.priority===e.priority&&r.push(i.run)}return r}get size(){return this.#e.length-this.#t}#i(){this.#t!==0&&(this.#e.splice(0,this.#t),this.#t=0)}};var Lr=class extends xi.default{#e;#t;#i=0;#d;#m=!1;#w=!1;#c;#T=0;#x=0;#u;#f;#a;#o=[];#s=0;#r;#L;#n=0;#y;#l;#C=1n;#b=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:jt,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.#s<this.#o.length;){let n=this.#o[this.#s];if(n!==void 0&&e-n>=this.#c)this.#s++;else break}(this.#s>100&&this.#s>this.#o.length/2||this.#s===this.#o.length)&&(this.#o=this.#o.slice(this.#s),this.#s=0)}#P(e){this.#a?this.#o.push(e):this.#i++}#O(){this.#a?this.#o.length>this.#s&&this.#o.pop():this.#i>0&&this.#i--}#S(){return this.#o.length-this.#s}get#N(){return this.#t?!0:this.#a?this.#S()<this.#d:this.#i<this.#d}get#F(){return this.#n<this.#y}#K(){this.#n--,this.#n===0&&this.emit("pendingZero"),this.#g(),this.emit("next")}#U(){this.#f=void 0,this.#k(),this.#D()}#M(e){if(this.#a){if(this.#v(e),this.#S()>=this.#d){let n=this.#o[this.#s],i=this.#c-(e-n);return this.#A(i),!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.#i=this.#e?this.#n:0}else return this.#A(r),!0}return!1}#A(e){this.#f===void 0&&(this.#f=setTimeout(()=>{this.#U()},e))}#I(){this.#u&&(clearInterval(this.#u),this.#u=void 0)}#_(){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.#_(),this.#a&&this.#s>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.#N&&this.#F){let i=this.#r.dequeue();this.#t||(this.#P(r),this.#p()),this.emit("active"),i(),n&&this.#D(),e=!0}}return e}#D(){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.#i===0&&this.#n===0&&this.#u&&this.#I(),this.#i=this.#e?this.#n:0),this.#B(),this.#p()}#B(){for(;this.#g(););}get concurrency(){return this.#y}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.#y=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.#C++).toString()},new Promise((n,i)=>{let s=Symbol(`task-${r.id}`),o=()=>{},a=async()=>{o(),this.#n++,this.#b.set(s,{id:r.id,priority:r.priority??0,startTime:Date.now(),timeout:r.timeout});let u;try{try{r.signal?.throwIfAborted()}catch(h){throw this.#V(),this.#b.delete(s),h}this.#x=Date.now();let f=e({signal:r.signal});if(r.timeout&&(f=Br(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:h}=r;f=Promise.race([f,new Promise((d,g)=>{u=()=>{g(h.reason)},h.addEventListener("abort",u,{once:!0})})])}let l=await f;n(l),this.emit("completed",l)}catch(f){i(f),this.emit("error",f)}finally{u&&r.signal?.removeEventListener("abort",u),this.#b.delete(s),queueMicrotask(()=>{this.#K()})}};this.#r.enqueue(a,r);let c=()=>{if(this.#r instanceof jt){this.#r.remove(a);return}this.#r.remove?.(r.id)};if(r.signal){let{signal:u}=r,f=()=>{o(),c(),i(u.reason),this.#g(),this.emit("next")};if(o=()=>{u.removeEventListener("abort",f),this.#E.delete(o)},u.aborted){f();return}u.addEventListener("abort",f,{once:!0}),this.#E.add(o)}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.#R(),this.emit("empty"),this.#n===0&&(this.#_(),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","active"],()=>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=i=>{this.off("error",n),r(i)};this.on("error",n)})}async#h(e,r){let n=Array.isArray(e)?e:[e];return new Promise(i=>{let s=()=>{if(!(r&&!r())){for(let o of n)this.off(o,s);i()}};for(let o of n)this.on(o,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.#R()}))}#V(){this.#t||(this.#O(),this.#p())}#R(){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 i=Date.now();this.#v(i),r=this.#S()}else r=this.#i;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.#y&&this.#r.size>0||this.isRateLimited&&this.#r.size>0}get runningTasks(){return[...this.#b.values()].map(e=>({...e,timeoutRemaining:e.timeout?Math.max(0,e.startTime+e.timeout-Date.now()):void 0}))}};var En=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 At;(function(t){let e;(function(a){let c;a.codec=()=>(c==null&&(c=ve((h,d,g={})=>{g.lengthDelimited!==!1&&d.fork(),h.subscribe!=null&&(d.uint32(8),d.bool(h.subscribe)),h.topic!=null&&(d.uint32(18),d.string(h.topic)),g.lengthDelimited!==!1&&d.ldelim()},(h,d,g={})=>{let E={},y=d==null?h.len:h.pos+d;for(;h.pos<y;){let m=h.uint32();switch(m>>>3){case 1:{E.subscribe=h.bool();break}case 2:{E.topic=h.string();break}default:{h.skipType(m&7);break}}}return E},function*(h,d,g,E={}){let y=d==null?h.len:h.pos+d;for(;h.pos<y;){let m=h.uint32();switch(m>>>3){case 1:{yield{field:`${g}.subscribe`,value:h.bool()};break}case 2:{yield{field:`${g}.topic`,value:h.string()};break}default:{h.skipType(m&7);break}}}})),c);function u(h){return xe(h,a.codec())}a.encode=u;function f(h,d){return we(h,a.codec(),d)}a.decode=f;function l(h,d){return Ee(h,a.codec(),d)}a.stream=l})(e=t.SubOpts||(t.SubOpts={}));let r;(function(a){let c;a.codec=()=>(c==null&&(c=ve((h,d,g={})=>{g.lengthDelimited!==!1&&d.fork(),h.from!=null&&(d.uint32(10),d.bytes(h.from)),h.data!=null&&(d.uint32(18),d.bytes(h.data)),h.sequenceNumber!=null&&(d.uint32(26),d.bytes(h.sequenceNumber)),h.topic!=null&&(d.uint32(34),d.string(h.topic)),h.signature!=null&&(d.uint32(42),d.bytes(h.signature)),h.key!=null&&(d.uint32(50),d.bytes(h.key)),g.lengthDelimited!==!1&&d.ldelim()},(h,d,g={})=>{let E={},y=d==null?h.len:h.pos+d;for(;h.pos<y;){let m=h.uint32();switch(m>>>3){case 1:{E.from=h.bytes();break}case 2:{E.data=h.bytes();break}case 3:{E.sequenceNumber=h.bytes();break}case 4:{E.topic=h.string();break}case 5:{E.signature=h.bytes();break}case 6:{E.key=h.bytes();break}default:{h.skipType(m&7);break}}}return E},function*(h,d,g,E={}){let y=d==null?h.len:h.pos+d;for(;h.pos<y;){let m=h.uint32();switch(m>>>3){case 1:{yield{field:`${g}.from`,value:h.bytes()};break}case 2:{yield{field:`${g}.data`,value:h.bytes()};break}case 3:{yield{field:`${g}.sequenceNumber`,value:h.bytes()};break}case 4:{yield{field:`${g}.topic`,value:h.string()};break}case 5:{yield{field:`${g}.signature`,value:h.bytes()};break}case 6:{yield{field:`${g}.key`,value:h.bytes()};break}default:{h.skipType(m&7);break}}}})),c);function u(h){return xe(h,a.codec())}a.encode=u;function f(h,d){return we(h,a.codec(),d)}a.decode=f;function l(h,d){return Ee(h,a.codec(),d)}a.stream=l})(r=t.Message||(t.Message={}));let n;t.codec=()=>(n==null&&(n=ve((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),_r.codec().encode(a.control,c)),u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={subscriptions:[],messages:[]},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let h=a.uint32();switch(h>>>3){case 1:{if(u.limits?.subscriptions!=null&&f.subscriptions.length===u.limits.subscriptions)throw new ee('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 ee('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=_r.codec().decode(a,a.uint32(),{limits:u.limits?.control});break}default:{a.skipType(h&7);break}}}return f},function*(a,c,u,f={}){let l={subscriptions:0,messages:0},h=c==null?a.len:a.pos+c;for(;a.pos<h;){let d=a.uint32();switch(d>>>3){case 1:{if(f.limits?.subscriptions!=null&&l.subscriptions===f.limits.subscriptions)throw new ee('Streaming decode error - repeated field "subscriptions" had too many elements');for(let g of t.SubOpts.codec().stream(a,a.uint32(),`${u}.subscriptions[]`,{limits:f.limits?.subscriptions$}))yield{...g,index:l.subscriptions};l.subscriptions++;break}case 2:{if(f.limits?.messages!=null&&l.messages===f.limits.messages)throw new ee('Streaming decode error - repeated field "messages" had too many elements');for(let g of t.Message.codec().stream(a,a.uint32(),`${u}.messages[]`,{limits:f.limits?.messages$}))yield{...g,index:l.messages};l.messages++;break}case 3:{yield*_r.codec().stream(a,a.uint32(),`${u}.control`,{limits:f.limits?.control});break}default:{a.skipType(d&7);break}}}})),n);function i(a){return xe(a,t.codec())}t.encode=i;function s(a,c){return we(a,t.codec(),c)}t.decode=s;function o(a,c){return Ee(a,t.codec(),c)}t.stream=o})(At||(At={}));var _r;(function(t){let e;t.codec=()=>(e==null&&(e=ve((s,o,a={})=>{if(a.lengthDelimited!==!1&&o.fork(),s.ihave!=null&&s.ihave.length>0)for(let c of s.ihave)o.uint32(10),Dr.codec().encode(c,o);if(s.iwant!=null&&s.iwant.length>0)for(let c of s.iwant)o.uint32(18),kr.codec().encode(c,o);if(s.graft!=null&&s.graft.length>0)for(let c of s.graft)o.uint32(26),Rr.codec().encode(c,o);if(s.prune!=null&&s.prune.length>0)for(let c of s.prune)o.uint32(34),Cr.codec().encode(c,o);a.lengthDelimited!==!1&&o.ldelim()},(s,o,a={})=>{let c={ihave:[],iwant:[],graft:[],prune:[]},u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{if(a.limits?.ihave!=null&&c.ihave.length===a.limits.ihave)throw new ee('Decode error - repeated field "ihave" had too many elements');c.ihave.push(Dr.codec().decode(s,s.uint32(),{limits:a.limits?.ihave$}));break}case 2:{if(a.limits?.iwant!=null&&c.iwant.length===a.limits.iwant)throw new ee('Decode error - repeated field "iwant" had too many elements');c.iwant.push(kr.codec().decode(s,s.uint32(),{limits:a.limits?.iwant$}));break}case 3:{if(a.limits?.graft!=null&&c.graft.length===a.limits.graft)throw new ee('Decode error - repeated field "graft" had too many elements');c.graft.push(Rr.codec().decode(s,s.uint32(),{limits:a.limits?.graft$}));break}case 4:{if(a.limits?.prune!=null&&c.prune.length===a.limits.prune)throw new ee('Decode error - repeated field "prune" had too many elements');c.prune.push(Cr.codec().decode(s,s.uint32(),{limits:a.limits?.prune$}));break}default:{s.skipType(f&7);break}}}return c},function*(s,o,a,c={}){let u={ihave:0,iwant:0,graft:0,prune:0},f=o==null?s.len:s.pos+o;for(;s.pos<f;){let l=s.uint32();switch(l>>>3){case 1:{if(c.limits?.ihave!=null&&u.ihave===c.limits.ihave)throw new ee('Streaming decode error - repeated field "ihave" had too many elements');for(let h of Dr.codec().stream(s,s.uint32(),`${a}.ihave[]`,{limits:c.limits?.ihave$}))yield{...h,index:u.ihave};u.ihave++;break}case 2:{if(c.limits?.iwant!=null&&u.iwant===c.limits.iwant)throw new ee('Streaming decode error - repeated field "iwant" had too many elements');for(let h of kr.codec().stream(s,s.uint32(),`${a}.iwant[]`,{limits:c.limits?.iwant$}))yield{...h,index:u.iwant};u.iwant++;break}case 3:{if(c.limits?.graft!=null&&u.graft===c.limits.graft)throw new ee('Streaming decode error - repeated field "graft" had too many elements');for(let h of Rr.codec().stream(s,s.uint32(),`${a}.graft[]`,{limits:c.limits?.graft$}))yield{...h,index:u.graft};u.graft++;break}case 4:{if(c.limits?.prune!=null&&u.prune===c.limits.prune)throw new ee('Streaming decode error - repeated field "prune" had too many elements');for(let h of Cr.codec().stream(s,s.uint32(),`${a}.prune[]`,{limits:c.limits?.prune$}))yield{...h,index:u.prune};u.prune++;break}default:{s.skipType(l&7);break}}}})),e);function r(s){return xe(s,t.codec())}t.encode=r;function n(s,o){return we(s,t.codec(),o)}t.decode=n;function i(s,o){return Ee(s,t.codec(),o)}t.stream=i})(_r||(_r={}));var Dr;(function(t){let e;t.codec=()=>(e==null&&(e=ve((s,o,a={})=>{if(a.lengthDelimited!==!1&&o.fork(),s.topic!=null&&(o.uint32(10),o.string(s.topic)),s.messageIDs!=null&&s.messageIDs.length>0)for(let c of s.messageIDs)o.uint32(18),o.bytes(c);a.lengthDelimited!==!1&&o.ldelim()},(s,o,a={})=>{let c={messageIDs:[]},u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.topic=s.string();break}case 2:{if(a.limits?.messageIDs!=null&&c.messageIDs.length===a.limits.messageIDs)throw new ee('Decode error - repeated field "messageIDs" had too many elements');c.messageIDs.push(s.bytes());break}default:{s.skipType(f&7);break}}}return c},function*(s,o,a,c={}){let u={messageIDs:0},f=o==null?s.len:s.pos+o;for(;s.pos<f;){let l=s.uint32();switch(l>>>3){case 1:{yield{field:`${a}.topic`,value:s.string()};break}case 2:{if(c.limits?.messageIDs!=null&&u.messageIDs===c.limits.messageIDs)throw new ee('Streaming decode error - repeated field "messageIDs" had too many elements');yield{field:`${a}.messageIDs[]`,index:u.messageIDs,value:s.bytes()},u.messageIDs++;break}default:{s.skipType(l&7);break}}}})),e);function r(s){return xe(s,t.codec())}t.encode=r;function n(s,o){return we(s,t.codec(),o)}t.decode=n;function i(s,o){return Ee(s,t.codec(),o)}t.stream=i})(Dr||(Dr={}));var kr;(function(t){let e;t.codec=()=>(e==null&&(e=ve((s,o,a={})=>{if(a.lengthDelimited!==!1&&o.fork(),s.messageIDs!=null&&s.messageIDs.length>0)for(let c of s.messageIDs)o.uint32(10),o.bytes(c);a.lengthDelimited!==!1&&o.ldelim()},(s,o,a={})=>{let c={messageIDs:[]},u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{if(a.limits?.messageIDs!=null&&c.messageIDs.length===a.limits.messageIDs)throw new ee('Decode error - repeated field "messageIDs" had too many elements');c.messageIDs.push(s.bytes());break}default:{s.skipType(f&7);break}}}return c},function*(s,o,a,c={}){let u={messageIDs:0},f=o==null?s.len:s.pos+o;for(;s.pos<f;){let l=s.uint32();switch(l>>>3){case 1:{if(c.limits?.messageIDs!=null&&u.messageIDs===c.limits.messageIDs)throw new ee('Streaming decode error - repeated field "messageIDs" had too many elements');yield{field:`${a}.messageIDs[]`,index:u.messageIDs,value:s.bytes()},u.messageIDs++;break}default:{s.skipType(l&7);break}}}})),e);function r(s){return xe(s,t.codec())}t.encode=r;function n(s,o){return we(s,t.codec(),o)}t.decode=n;function i(s,o){return Ee(s,t.codec(),o)}t.stream=i})(kr||(kr={}));var Rr;(function(t){let e;t.codec=()=>(e==null&&(e=ve((s,o,a={})=>{a.lengthDelimited!==!1&&o.fork(),s.topic!=null&&(o.uint32(10),o.string(s.topic)),a.lengthDelimited!==!1&&o.ldelim()},(s,o,a={})=>{let c={},u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();f>>>3===1?c.topic=s.string():s.skipType(f&7)}return c},function*(s,o,a,c={}){let u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();f>>>3===1?yield{field:`${a}.topic`,value:s.string()}:s.skipType(f&7)}})),e);function r(s){return xe(s,t.codec())}t.encode=r;function n(s,o){return we(s,t.codec(),o)}t.decode=n;function i(s,o){return Ee(s,t.codec(),o)}t.stream=i})(Rr||(Rr={}));var Cr;(function(t){let e;t.codec=()=>(e==null&&(e=ve((s,o,a={})=>{if(a.lengthDelimited!==!1&&o.fork(),s.topic!=null&&(o.uint32(10),o.string(s.topic)),s.peers!=null&&s.peers.length>0)for(let c of s.peers)o.uint32(18),Pr.codec().encode(c,o);s.backoff!=null&&(o.uint32(24),o.uint64(s.backoff)),a.lengthDelimited!==!1&&o.ldelim()},(s,o,a={})=>{let c={peers:[]},u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.topic=s.string();break}case 2:{if(a.limits?.peers!=null&&c.peers.length===a.limits.peers)throw new ee('Decode error - repeated field "peers" had too many elements');c.peers.push(Pr.codec().decode(s,s.uint32(),{limits:a.limits?.peers$}));break}case 3:{c.backoff=s.uint64();break}default:{s.skipType(f&7);break}}}return c},function*(s,o,a,c={}){let u={peers:0},f=o==null?s.len:s.pos+o;for(;s.pos<f;){let l=s.uint32();switch(l>>>3){case 1:{yield{field:`${a}.topic`,value:s.string()};break}case 2:{if(c.limits?.peers!=null&&u.peers===c.limits.peers)throw new ee('Streaming decode error - repeated field "peers" had too many elements');for(let h of Pr.codec().stream(s,s.uint32(),`${a}.peers[]`,{limits:c.limits?.peers$}))yield{...h,index:u.peers};u.peers++;break}case 3:{yield{field:`${a}.backoff`,value:s.uint64()};break}default:{s.skipType(l&7);break}}}})),e);function r(s){return xe(s,t.codec())}t.encode=r;function n(s,o){return we(s,t.codec(),o)}t.decode=n;function i(s,o){return Ee(s,t.codec(),o)}t.stream=i})(Cr||(Cr={}));var Pr;(function(t){let e;t.codec=()=>(e==null&&(e=ve((s,o,a={})=>{a.lengthDelimited!==!1&&o.fork(),s.peerID!=null&&(o.uint32(10),o.bytes(s.peerID)),s.signedPeerRecord!=null&&(o.uint32(18),o.bytes(s.signedPeerRecord)),a.lengthDelimited!==!1&&o.ldelim()},(s,o,a={})=>{let c={},u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.peerID=s.bytes();break}case 2:{c.signedPeerRecord=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,o,a,c={}){let u=o==null?s.len:s.pos+o;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.peerID`,value:s.bytes()};break}case 2:{yield{field:`${a}.signedPeerRecord`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return xe(s,t.codec())}t.encode=r;function n(s,o){return we(s,t.codec(),o)}t.decode=n;function i(s,o){return Ee(s,t.codec(),o)}t.stream=i})(Pr||(Pr={}));var vn=class extends Tt{peerId;shutDownController;inboundPb;outboundPb;constructor(e){super(),this.peerId=e,this.shutDownController=new AbortController}attachInboundStream(e,r){this.inboundPb=gi(e,r).pb(At),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=gi(e,r).pb(At)}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 Da(){return BigInt(`0x${H(crypto.getRandomValues(new Uint8Array(8)),"base16")}`)}var ka=(t,e)=>{let r=z(e.toString(16).padStart(16,"0"),"base16"),n=Ve(t),i=new Uint8Array(n.byteLength+r.length);return i.set(n,0),i.set(r,n.byteLength),i},Ra=t=>ht.encode(t);var Hf=async t=>{if(t.sequenceNumber==null||t.from==null||t.signature==null)return!1;let e=Sr(Xe(t.from));if(e.publicKey!=null)return!0;if(t.key!=null){let r=t.key;return li(fi(r)).equals(e)}return!1},Ca=async t=>{if(t.from==null)throw new J("RPC message was missing from");if(!await Hf(t))return{type:"unsigned",topic:t.topic??"",data:t.data??new Uint8Array(0)};let e=Sr(Xe(t.from)),r=t.key??e.publicKey;if(r==null)throw new J("RPC message was missing public key");return{type:"signed",from:e,topic:t.topic??"",sequenceNumber:$f(t.sequenceNumber??new Uint8Array(0)),data:t.data??new Uint8Array(0),signature:t.signature??new Uint8Array(0),key:r instanceof Uint8Array?fi(r):r}},Or=t=>t.type==="signed"?{from:t.from.toMultihash().bytes,data:t.data,sequenceNumber:zf(t.sequenceNumber),topic:t.topic,signature:t.signature,key:t.key?Ve(t.key):void 0}:{data:t.data,topic:t.topic},zf=t=>{let e=t.toString(16);return e.length%2!==0&&(e=`0${e}`),z(e,"base16")},$f=t=>BigInt(`0x${H(t,"base16")}`);var Pa=z("libp2p-pubsub:");async function Oa(t,e,r){let n={type:"signed",topic:e.topic,data:e.data,sequenceNumber:e.sequenceNumber,from:Ia(t)},i=lt([Pa,r(Or(n)).subarray()]);return n.signature=await t.sign(i),n.key=t.publicKey,n}async function Na(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=lt([Pa,e({...Or(t),signature:void 0,key:void 0}).subarray()]);return jf(t).verify(r,t.signature)}function jf(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 Sn=class extends Tt{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??vi,this.started=!1,this.topics=new Map,this.subscriptions=new Set,this.peers=new Ar,this.globalSignaturePolicy=r.globalSignaturePolicy==="StrictNoSign"?"StrictNoSign":"StrictSign",this.canRelayMessage=r.canRelayMessage??!0,this.emitSelf=r.emitSelf??!1,this.topicValidators=new Map,this.queue=new Lr({concurrency:r.messageProcessingConcurrency??10}),this.maxInboundStreams=r.maxInboundStreams??1,this.maxOutboundStreams=r.maxOutboundStreams??1,this.seenCache=new En({validityMs:r?.seenTTL??3e4}),this._onIncomingStream=this._onIncomingStream.bind(this),this._onPeerConnected=this._onPeerConnected.bind(this),this._onPeerDisconnected=this._onPeerDisconnected.bind(this)}[Gt]=!0;[Symbol.toStringTag]="@libp2p/floodsub";[Bi]=["@libp2p/pubsub"];[Ti]=["@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(s=>s.direction==="outbound"&&s.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(s=>s.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 i=new vn(e);return this.peers.set(e,i),i.addEventListener("message",s=>{let o=s.detail,a=[];for(let c of o.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(i,{subscriptions:(o.subscriptions??[]).map(c=>({subscribe:!!c.subscribe,topic:c.topic??""})),messages:a}).catch(c=>{this.log(c)})}),i.addEventListener("close",()=>this._removePeer(e),{once:!0}),i}_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:i}=r;return n!=null&&n.length>0&&(this.log("subscription update from %p",e.peerId),n.forEach(s=>{this.processRpcSubOpt(e.peerId,s)}),super.dispatchEvent(new CustomEvent("subscription-change",{detail:{peerId:e.peerId,subscriptions:n.map(({topic:s,subscribe:o})=>({topic:`${s??""}`,subscribe:!!o}))}}))),i!=null&&i.length>0&&(this.log("messages from %p",e.peerId),this.queue.addAll(i.map(s=>async()=>{if(s.topic==null||!this.subscriptions.has(s.topic)&&!this.canRelayMessage)return this.log("received message we didn't subscribe to. Dropping."),!1;try{let o=await Ca(s);await this.processMessage(e.peerId,o)}catch(o){this.log.error("failed to queue messages from %p - %e",e.peerId,o)}})).catch(s=>{this.log(s)})),!0}processRpcSubOpt(e,r){let n=r.topic;if(n==null)return;let i=this.topics.get(n);i==null&&(i=new Ir,this.topics.set(n,i)),r.subscribe===!0?i.add(e):i.delete(e)}async processMessage(e,r){if(this.components.peerId.equals(e)&&!this.emitSelf)return;let n=await this.getMsgId(r),i=H(n,"base64");if(!this.seenCache.has(i)){this.seenCache.put(i,!0);try{await this.validate(e,r)}catch(s){this.log("Message is invalid, dropping it. %O",s);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 J('Message type should be "signed" when signature policy is StrictSign but it was not');if(e.sequenceNumber==null)throw new J("Need sequence number when signature policy is StrictSign but it was missing");if(e.key==null)throw new J("Need key when signature policy is StrictSign but it was missing");return ka(e.key,e.sequenceNumber);case"StrictNoSign":return Ra(e.data);default:throw new J("Cannot get message id: unhandled signature policy")}}encodeMessage(e){return At.Message.encode(e)}send(e,r){let{messages:n,subscriptions:i,subscribe:s}=r;this.sendRpc(e,{subscriptions:(i??[]).map(o=>({topic:o,subscribe:!!s})),messages:(n??[]).map(Or)})}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 J('Message type should be "unsigned" when signature policy is StrictNoSign but it was not');if(r.signature!=null)throw new J("StrictNoSigning: signature should not be present");if(r.key!=null)throw new J("StrictNoSigning: key should not be present");if(r.sequenceNumber!=null)throw new J("StrictNoSigning: seqno should not be present");break;case"StrictSign":if(r.type!=="signed")throw new J('Message type should be "signed" when signature policy is StrictSign but it was not');if(r.signature==null)throw new J("StrictSigning: Signing required and no signature was present");if(r.sequenceNumber==null)throw new J("StrictSigning: Signing required and no sequenceNumber was present");if(!await Na(r,this.encodeMessage.bind(this)))throw new J("StrictSigning: Invalid message signature");break;default:throw new J("Cannot validate message: unhandled signature policy")}let i=this.topicValidators.get(r.topic);if(i!=null){let s=await i(e,r);if(s===Zt.Reject||s===Zt.Ignore)throw new J("Message validation failed")}}async buildMessage(e){switch(this.globalSignaturePolicy){case"StrictSign":return Oa(this.components.privateKey,e,this.encodeMessage.bind(this));case"StrictNoSign":return Promise.resolve({type:"unsigned",...e});default:throw new J("Cannot build message: unhandled signature policy")}}getSubscribers(e){if(!this.started)throw new Ur("not started yet");if(e==null)throw new j("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:Da()};this.log("publish topic: %s from: %p data: %m",e,n.from,n.data);let i=await this.buildMessage(n),s=!1;this.emitSelf&&this.subscriptions.has(e)&&(s=!0,super.dispatchEvent(new CustomEvent("message",{detail:i})));let o=await this.publishMessage(this.components.peerId,i);return s&&(o.recipients=[...o.recipients,this.components.peerId]),o}async publishMessage(e,r){let n=this.getSubscribers(r.topic),i=[];return n==null||n.length===0?(this.log("no peers are subscribed to topic %s",r.topic),{recipients:i}):(n.forEach(s=>{if(this.components.peerId.equals(s)){this.log("not sending message on topic %s to myself",r.topic);return}if(s.equals(e)){this.log("not sending message on topic %s to sender %p",r.topic,s);return}this.log("publish msgs on topics %s %p",r.topic,s),i.push(s),this.send(s,{messages:[r]})}),{recipients:i})}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 vi="/floodsub/1.0.0",Zf="StrictSign",Yf="StrictNoSign",Zt;(function(t){t.Accept="accept",t.Ignore="ignore",t.Reject="reject"})(Zt||(Zt={}));function Gf(t){return!!t?.[Gt]}function Xf(t={}){return e=>new Sn(e,t)}return za(Wf);})();
3
3
  /*! Bundled license information:
4
4
 
5
5
  @noble/curves/utils.js: