@libp2p/floodsub 10.1.45-58abe8702 → 10.1.45-cb1c14e62
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +3 -3
- package/package.json +8 -8
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 Aa=Object.create;var Sr=Object.defineProperty;var Ia=Object.getOwnPropertyDescriptor;var Ba=Object.getOwnPropertyNames;var _a=Object.getPrototypeOf,La=Object.prototype.hasOwnProperty;var Ta=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),ht=(r,t)=>{for(var e in t)Sr(r,e,{get:t[e],enumerable:!0})},is=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ba(t))!La.call(r,o)&&o!==e&&Sr(r,o,{get:()=>t[o],enumerable:!(n=Ia(t,o))||n.enumerable});return r};var Da=(r,t,e)=>(e=r!=null?Aa(_a(r)):{},is(t||!r||!r.__esModule?Sr(e,"default",{value:r,enumerable:!0}):e,r)),Pa=r=>is(Sr({},"__esModule",{value:!0}),r);var ua=Ta((Im,Jo)=>{"use strict";var Ef=Object.prototype.hasOwnProperty,lt="~";function mr(){}Object.create&&(mr.prototype=Object.create(null),new mr().__proto__||(lt=!1));function Sf(r,t,e){this.fn=r,this.context=t,this.once=e||!1}function ca(r,t,e,n,o){if(typeof e!="function")throw new TypeError("The listener must be a function");var s=new Sf(e,n||r,o),i=lt?lt+t:t;return r._events[i]?r._events[i].fn?r._events[i]=[r._events[i],s]:r._events[i].push(s):(r._events[i]=s,r._eventsCount++),r}function nn(r,t){--r._eventsCount===0?r._events=new mr:delete r._events[t]}function at(){this._events=new mr,this._eventsCount=0}at.prototype.eventNames=function(){var t=[],e,n;if(this._eventsCount===0)return t;for(n in e=this._events)Ef.call(e,n)&&t.push(lt?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(e)):t};at.prototype.listeners=function(t){var e=lt?lt+t:t,n=this._events[e];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,s=n.length,i=new Array(s);o<s;o++)i[o]=n[o].fn;return i};at.prototype.listenerCount=function(t){var e=lt?lt+t:t,n=this._events[e];return n?n.fn?1:n.length:0};at.prototype.emit=function(t,e,n,o,s,i){var a=lt?lt+t:t;if(!this._events[a])return!1;var c=this._events[a],l=arguments.length,u,f;if(c.fn){switch(c.once&&this.removeListener(t,c.fn,void 0,!0),l){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,e),!0;case 3:return c.fn.call(c.context,e,n),!0;case 4:return c.fn.call(c.context,e,n,o),!0;case 5:return c.fn.call(c.context,e,n,o,s),!0;case 6:return c.fn.call(c.context,e,n,o,s,i),!0}for(f=1,u=new Array(l-1);f<l;f++)u[f-1]=arguments[f];c.fn.apply(c.context,u)}else{var b=c.length,p;for(f=0;f<b;f++)switch(c[f].once&&this.removeListener(t,c[f].fn,void 0,!0),l){case 1:c[f].fn.call(c[f].context);break;case 2:c[f].fn.call(c[f].context,e);break;case 3:c[f].fn.call(c[f].context,e,n);break;case 4:c[f].fn.call(c[f].context,e,n,o);break;default:if(!u)for(p=1,u=new Array(l-1);p<l;p++)u[p-1]=arguments[p];c[f].fn.apply(c[f].context,u)}}return!0};at.prototype.on=function(t,e,n){return ca(this,t,e,n,!1)};at.prototype.once=function(t,e,n){return ca(this,t,e,n,!0)};at.prototype.removeListener=function(t,e,n,o){var s=lt?lt+t:t;if(!this._events[s])return this;if(!e)return nn(this,s),this;var i=this._events[s];if(i.fn)i.fn===e&&(!o||i.once)&&(!n||i.context===n)&&nn(this,s);else{for(var a=0,c=[],l=i.length;a<l;a++)(i[a].fn!==e||o&&!i[a].once||n&&i[a].context!==n)&&c.push(i[a]);c.length?this._events[s]=c.length===1?c[0]:c:nn(this,s)}return this};at.prototype.removeAllListeners=function(t){var e;return t?(e=lt?lt+t:t,this._events[e]&&nn(this,e)):(this._events=new mr,this._eventsCount=0),this};at.prototype.off=at.prototype.removeListener;at.prototype.addListener=at.prototype.on;at.prefixed=lt;at.EventEmitter=at;typeof Jo<"u"&&(Jo.exports=at)});var Df={};ht(Df,{floodsub:()=>Tf,multicodec:()=>os});var En=Symbol.for("@libp2p/peer-id");var qe;(function(r){r.Accept="accept",r.Ignore="ignore",r.Reject="reject"})(qe||(qe={}));var as=Symbol.for("@libp2p/pubsub");var V=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},be=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var vr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var j=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var Ar=class extends Error{static name="NotStartedError";constructor(t="Not started"){super(t),this.name="NotStartedError"}};var Qt=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var ge=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let e=this.#t.get(t);return e==null?0:e.length}addEventListener(t,e,n){super.addEventListener(t,e,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:e,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,e,n){super.removeEventListener(t.toString(),e??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==e),this.#t.set(t,o))}dispatchEvent(t){let e=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),e}safeDispatchEvent(t,e={}){return this.dispatchEvent(new CustomEvent(t,e))}};var cs=Symbol.for("@libp2p/service-capabilities"),us=Symbol.for("@libp2p/service-dependencies");var Bn={};ht(Bn,{base58btc:()=>F,base58flickr:()=>Ma});var nl=new Uint8Array(0);function fs(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Ct(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function ls(r){return new TextEncoder().encode(r)}function hs(r){return new TextDecoder().decode(r)}function Ca(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var a=r.length,c=r.charAt(0),l=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function f(v){if(v instanceof Uint8Array||(ArrayBuffer.isView(v)?v=new Uint8Array(v.buffer,v.byteOffset,v.byteLength):Array.isArray(v)&&(v=Uint8Array.from(v))),!(v instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(v.length===0)return"";for(var w=0,d=0,S=0,L=v.length;S!==L&&v[S]===0;)S++,w++;for(var A=(L-S)*u+1>>>0,C=new Uint8Array(A);S!==L;){for(var y=v[S],P=0,D=A-1;(y!==0||P<d)&&D!==-1;D--,P++)y+=256*C[D]>>>0,C[D]=y%a>>>0,y=y/a>>>0;if(y!==0)throw new Error("Non-zero carry");d=P,S++}for(var B=A-d;B!==A&&C[B]===0;)B++;for(var h=c.repeat(w);B<A;++B)h+=r.charAt(C[B]);return h}function b(v){if(typeof v!="string")throw new TypeError("Expected String");if(v.length===0)return new Uint8Array;var w=0;if(v[w]!==" "){for(var d=0,S=0;v[w]===c;)d++,w++;for(var L=(v.length-w)*l+1>>>0,A=new Uint8Array(L);v[w];){var C=e[v.charCodeAt(w)];if(C===255)return;for(var y=0,P=L-1;(C!==0||y<S)&&P!==-1;P--,y++)C+=a*A[P]>>>0,A[P]=C%256>>>0,C=C/256>>>0;if(C!==0)throw new Error("Non-zero carry");S=y,w++}if(v[w]!==" "){for(var D=L-S;D!==L&&A[D]===0;)D++;for(var B=new Uint8Array(d+(L-D)),h=d;D!==L;)B[h++]=A[D++];return B}}}function p(v){var w=b(v);if(w)return w;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:b,decode:p}}var Na=Ca,ka=Na,ps=ka;var Sn=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},vn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return ms(this,t)}},An=class{decoders;constructor(t){this.decoders=t}or(t){return ms(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function ms(r,t){return new An({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var In=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new Sn(t,e,n),this.decoder=new vn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function xe({name:r,prefix:t,encode:e,decode:n}){return new In(r,t,e,n)}function zt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=ps(e,r);return xe({prefix:t,name:r,encode:n,decode:s=>Ct(o(s))})}function Ka(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,a=0,c=0;for(let l=0;l<o;++l){let u=t[r[l]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|u,i+=e,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Ra(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function Ua(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function Z({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=Ua(n);return xe({prefix:t,name:r,encode(s){return Ra(s,n,e)},decode(s){return Ka(s,o,e,r)}})}var F=zt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ma=zt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var _n={};ht(_n,{base32:()=>we,base32hex:()=>za,base32hexpad:()=>Fa,base32hexpadupper:()=>Ga,base32hexupper:()=>Va,base32pad:()=>qa,base32padupper:()=>Ha,base32upper:()=>Oa,base32z:()=>Za});var we=Z({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Oa=Z({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),qa=Z({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ha=Z({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),za=Z({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Va=Z({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Fa=Z({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Ga=Z({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Za=Z({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ln={};ht(Ln,{base36:()=>He,base36upper:()=>$a});var He=zt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),$a=zt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ja=gs,ys=128,Ya=127,Wa=~Ya,Xa=Math.pow(2,31);function gs(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Xa;)t[e++]=r&255|ys,r/=128;for(;r&Wa;)t[e++]=r&255|ys,r>>>=7;return t[e]=r|0,gs.bytes=e-n+1,t}var Ja=Tn,Qa=128,bs=127;function Tn(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Tn.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&bs)<<o:(i&bs)*Math.pow(2,o),o+=7}while(i>=Qa);return Tn.bytes=s-n,e}var tc=Math.pow(2,7),ec=Math.pow(2,14),rc=Math.pow(2,21),nc=Math.pow(2,28),oc=Math.pow(2,35),sc=Math.pow(2,42),ic=Math.pow(2,49),ac=Math.pow(2,56),cc=Math.pow(2,63),uc=function(r){return r<tc?1:r<ec?2:r<rc?3:r<nc?4:r<oc?5:r<sc?6:r<ic?7:r<ac?8:r<cc?9:10},fc={encode:ja,decode:Ja,encodingLength:uc},lc=fc,ze=lc;function Ve(r,t=0){return[ze.decode(r,t),ze.decode.bytes]}function Ee(r,t,e=0){return ze.encode(r,t,e),t}function Se(r){return ze.encodingLength(r)}function St(r,t){let e=t.byteLength,n=Se(r),o=n+Se(e),s=new Uint8Array(o+e);return Ee(r,s,0),Ee(e,s,n),s.set(t,o),new ve(r,e,t,s)}function Vt(r){let t=Ct(r),[e,n]=Ve(t),[o,s]=Ve(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new ve(e,o,i,t)}function xs(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&fs(r.bytes,e.bytes)}}var ve=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function ws(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return dc(e,Dn(r),t??F.encoder);default:return pc(e,Dn(r),t??we.encoder)}}var Es=new WeakMap;function Dn(r){let t=Es.get(r);if(t==null){let e=new Map;return Es.set(r,e),e}return t}var rt=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==Fe)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==mc)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=St(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&xs(t.multihash,n.multihash)}toString(t){return ws(this,t)}toJSON(){return{"/":ws(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:s,bytes:i}=e;return new r(n,o,s,i??Ss(n,o,s.bytes))}else if(e[yc]===!0){let{version:n,multihash:o,code:s}=e,i=Vt(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==Fe)throw new Error(`Version 0 CID must use dag-pb (code: ${Fe}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Ss(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Fe,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=Ct(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new ve(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[f,b]=Ve(t.subarray(e));return e+=b,f},o=n(),s=Fe;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),c=n(),l=e+c,u=l-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:u,size:l}}static parse(t,e){let[n,o]=hc(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Dn(s).set(n,t),s}};function hc(r,t){switch(r[0]){case"Q":{let e=t??F;return[F.prefix,e.decode(`${F.prefix}${r}`)]}case F.prefix:{let e=t??F;return[F.prefix,e.decode(r)]}case we.prefix:{let e=t??we;return[we.prefix,e.decode(r)]}case He.prefix:{let e=t??He;return[He.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function dc(r,t,e){let{prefix:n}=e;if(n!==F.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function pc(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var Fe=112,mc=18;function Ss(r,t,e){let n=Se(r),o=n+Se(t),s=new Uint8Array(o+e.byteLength);return Ee(r,s,0),Ee(t,s,n),s.set(e,o),s}var yc=Symbol.for("@ipld/js-cid/CID");var Pn={};ht(Pn,{identity:()=>vt});var vs=0,bc="identity",As=Ct;function gc(r){return St(vs,As(r))}var vt={code:vs,name:bc,encode:As,digest:gc};function dt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Nt(r=0){return new Uint8Array(r)}function nt(r=0){return new Uint8Array(r)}function te(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=nt(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var Bs=Symbol.for("@achingbrain/uint8arraylist");function Is(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function Br(r){return!!r?.[Bs]}var X=class r{bufs;length;[Bs]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(Br(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(Br(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=Is(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Is(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(Br(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:o}=this._subList(t,e);return te(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:te(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=[...n],s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let l=t>=a&&t<c,u=e>a&&e<=c;if(l&&u){if(t===a&&e===c){n.push(i);break}let f=t-a;n.push(i.subarray(f,f+(e-t)));break}if(l){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(u){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Br(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let f=0;f<s;f++)i[f]=-1;for(let f=0;f<o;f++)i[n[f]]=f;let a=i,c=this.byteLength-n.byteLength,l=n.byteLength-1,u;for(let f=e;f<=c;f+=u){u=0;for(let b=l;b>=0;b--){let p=this.get(f+b);if(n[b]!==p){u=Math.max(1,b-a[p]);break}}if(u===0)return f}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=nt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=Nt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=Nt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=Nt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=nt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=Nt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=Nt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=Nt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=Nt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=Nt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!dt(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};var Cn={};ht(Cn,{base10:()=>xc});var xc=zt({prefix:"9",name:"base10",alphabet:"0123456789"});var Nn={};ht(Nn,{base16:()=>wc,base16upper:()=>Ec});var wc=Z({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ec=Z({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var kn={};ht(kn,{base2:()=>Sc});var Sc=Z({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Kn={};ht(Kn,{base256emoji:()=>_c});var _s=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}"),vc=_s.reduce((r,t,e)=>(r[e]=t,r),[]),Ac=_s.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Ic(r){return r.reduce((t,e)=>(t+=vc[e],t),"")}function Bc(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=Ac[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var _c=xe({prefix:"\u{1F680}",name:"base256emoji",encode:Ic,decode:Bc});var Rn={};ht(Rn,{base64:()=>Lc,base64pad:()=>Tc,base64url:()=>Dc,base64urlpad:()=>Pc});var Lc=Z({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Tc=Z({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Dc=Z({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Pc=Z({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Un={};ht(Un,{base8:()=>Cc});var Cc=Z({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Mn={};ht(Mn,{identity:()=>Nc});var Nc=xe({prefix:"\0",name:"identity",encode:r=>hs(r),decode:r=>ls(r)});var ql=new TextEncoder,Hl=new TextDecoder;var Hn={};ht(Hn,{sha256:()=>ee,sha512:()=>Rc});function qn({name:r,code:t,encode:e}){return new On(r,t,e)}var On=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?St(this.code,e):e.then(n=>St(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Ts(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var ee=qn({name:"sha2-256",code:18,encode:Ts("SHA-256")}),Rc=qn({name:"sha2-512",code:19,encode:Ts("SHA-512")});var zn={...Mn,...kn,...Un,...Cn,...Nn,..._n,...Ln,...Bn,...Rn,...Kn},Ql={...Hn,...Pn};function Ps(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Ds=Ps("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Vn=Ps("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=nt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Uc={utf8:Ds,"utf-8":Ds,hex:zn.base16,latin1:Vn,ascii:Vn,binary:Vn,...zn},_r=Uc;function O(r,t="utf8"){let e=_r[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function M(r,t="utf8"){let e=_r[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Mc=parseInt("11111",2),Fn=parseInt("10000000",2),Oc=parseInt("01111111",2),Cs={0:Ge,1:Ge,2:qc,3:Vc,4:Fc,5:zc,6:Hc,16:Ge,22:Ge,48:Ge};function kt(r,t={offset:0}){let e=r[t.offset]&Mc;if(t.offset++,Cs[e]!=null)return Cs[e](r,t);throw new Error("No decoder for tag "+e)}function Ze(r,t){let e=0;if((r[t.offset]&Fn)===Fn){let n=r[t.offset]&Oc,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=r[t.offset].toString(16).padStart(2,"0");e=parseInt(o,16)}else e=r[t.offset],t.offset++;return e}function Ge(r,t){Ze(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=kt(r,t);if(n===null)break;e.push(n)}return e}function qc(r,t){let e=Ze(r,t),n=t.offset,o=t.offset+e,s=[];for(let i=n;i<o;i++)i===n&&r[i]===0||s.push(r[i]);return t.offset+=e,Uint8Array.from(s)}function Hc(r,t){let e=Ze(r,t),n=t.offset+e,o=r[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let l=r[t.offset];if(t.offset++,c.push(l&127),l<128){c.reverse();let u=0;for(let f=0;f<c.length;f++)u+=c[f]<<f*7;a+=`.${u}`,c=[]}}return a}function zc(r,t){return t.offset++,null}function Vc(r,t){let e=Ze(r,t),n=r[t.offset];t.offset++;let o=r.subarray(t.offset,t.offset+e-1);if(t.offset+=e,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Fc(r,t){let e=Ze(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function Gc(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new X;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function Gn(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=Gc(r.byteLength);return new X(Uint8Array.from([t.byteLength|Fn]),t)}function pt(r){let t=new X,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new X(Uint8Array.from([2]),Gn(t),t)}function Lr(r){let t=Uint8Array.from([0]),e=new X(t,r);return new X(Uint8Array.from([3]),Gn(e),e)}function Gt(r,t=48){let e=new X;for(let n of r)e.append(n);return new X(Uint8Array.from([t]),Gn(e),e)}async function Ns(r,t,e,n){let o=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,e.subarray());return n?.signal?.throwIfAborted(),s}var Zc=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),$c=Uint8Array.from([6,5,43,129,4,0,34]),jc=Uint8Array.from([6,5,43,129,4,0,35]),Yc={ext:!0,kty:"EC",crv:"P-256"},Wc={ext:!0,kty:"EC",crv:"P-384"},Xc={ext:!0,kty:"EC",crv:"P-521"},Zn=32,$n=48,jn=66;function Yn(r){let t=kt(r);return ks(t)}function ks(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===Zn*2+1)return n=M(t.subarray(e,e+Zn),"base64url"),o=M(t.subarray(e+Zn),"base64url"),new Ae({...Yc,key_ops:["verify"],x:n,y:o});if(t.byteLength===$n*2+1)return n=M(t.subarray(e,e+$n),"base64url"),o=M(t.subarray(e+$n),"base64url"),new Ae({...Wc,key_ops:["verify"],x:n,y:o});if(t.byteLength===jn*2+1)return n=M(t.subarray(e,e+jn),"base64url"),o=M(t.subarray(e+jn),"base64url"),new Ae({...Xc,key_ops:["verify"],x:n,y:o});throw new V(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Ks(r){return Gt([pt(Uint8Array.from([1])),Gt([Jc(r.crv)],160),Gt([Lr(new X(Uint8Array.from([4]),O(r.x??"","base64url"),O(r.y??"","base64url")))],161)]).subarray()}function Jc(r){if(r==="P-256")return Zc;if(r==="P-384")return $c;if(r==="P-521")return jc;throw new V(`Invalid curve ${r}`)}var Ae=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Ks(this.jwk)),this._raw}toMultihash(){return vt.digest(Kt(this))}toCID(){return rt.createV1(114,this.toMultihash())}toString(){return F.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:dt(this.raw,t.raw)}async verify(t,e,n){return Ns(this.jwk,e,t,n)}};var re=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Be(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function $e(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function ot(r,...t){if(!Be(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error("Uint8Array expected of length "+t+", got length="+r.length)}function Us(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");$e(r.outputLen),$e(r.blockLen)}function _e(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function Ms(r,t){ot(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}function Ut(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function Tr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function At(r,t){return r<<32-t|r>>>t}var Os=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Qc=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function Lt(r){if(ot(r),Os)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=Qc[r[e]];return t}var Rt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Rs(r){if(r>=Rt._0&&r<=Rt._9)return r-Rt._0;if(r>=Rt.A&&r<=Rt.F)return r-(Rt.A-10);if(r>=Rt.a&&r<=Rt.f)return r-(Rt.a-10)}function Le(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(Os)return Uint8Array.fromHex(r);let t=r.length,e=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,s=0;o<e;o++,s+=2){let i=Rs(r.charCodeAt(s)),a=Rs(r.charCodeAt(s+1));if(i===void 0||a===void 0){let c=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function qs(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function je(r){return typeof r=="string"&&(r=qs(r)),ot(r),r}function gt(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];ot(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}var Ie=class{};function Wn(r){let t=n=>r().update(je(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function ne(r=32){if(re&&typeof re.getRandomValues=="function")return re.getRandomValues(new Uint8Array(r));if(re&&typeof re.randomBytes=="function")return Uint8Array.from(re.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function tu(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(e>>o&s),a=Number(e&s),c=n?4:0,l=n?0:4;r.setUint32(t+c,i,n),r.setUint32(t+l,a,n)}function Hs(r,t,e){return r&t^~r&e}function zs(r,t,e){return r&t^r&e^t&e}var Ye=class extends Ie{constructor(t,e,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=Tr(this.buffer)}update(t){_e(this),t=je(t),ot(t);let{view:e,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=Tr(t);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){_e(this),Ms(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,Ut(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let f=i;f<o;f++)e[f]=0;tu(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=Tr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let l=c/4,u=this.get();if(l>u.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<l;f++)a.setUint32(4*f,u[f],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Mt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var tt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Dr=BigInt(4294967295),Vs=BigInt(32);function eu(r,t=!1){return t?{h:Number(r&Dr),l:Number(r>>Vs&Dr)}:{h:Number(r>>Vs&Dr)|0,l:Number(r&Dr)|0}}function Fs(r,t=!1){let e=r.length,n=new Uint32Array(e),o=new Uint32Array(e);for(let s=0;s<e;s++){let{h:i,l:a}=eu(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var Xn=(r,t,e)=>r>>>e,Jn=(r,t,e)=>r<<32-e|t>>>e,oe=(r,t,e)=>r>>>e|t<<32-e,se=(r,t,e)=>r<<32-e|t>>>e,We=(r,t,e)=>r<<64-e|t>>>e-32,Xe=(r,t,e)=>r>>>e-32|t<<64-e;function Tt(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var Gs=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Zs=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,$s=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),js=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Ys=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Ws=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var nu=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]),Zt=new Uint32Array(64),Pr=class extends Ye{constructor(t=32){super(64,t,8,!1),this.A=Mt[0]|0,this.B=Mt[1]|0,this.C=Mt[2]|0,this.D=Mt[3]|0,this.E=Mt[4]|0,this.F=Mt[5]|0,this.G=Mt[6]|0,this.H=Mt[7]|0}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,e,n,o,s,i,a,c]}set(t,e,n,o,s,i,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,e){for(let f=0;f<16;f++,e+=4)Zt[f]=t.getUint32(e,!1);for(let f=16;f<64;f++){let b=Zt[f-15],p=Zt[f-2],v=At(b,7)^At(b,18)^b>>>3,w=At(p,17)^At(p,19)^p>>>10;Zt[f]=w+Zt[f-7]+v+Zt[f-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:l,H:u}=this;for(let f=0;f<64;f++){let b=At(a,6)^At(a,11)^At(a,25),p=u+b+Hs(a,c,l)+nu[f]+Zt[f]|0,w=(At(n,2)^At(n,13)^At(n,22))+zs(n,o,s)|0;u=l,l=c,c=a,a=i+p|0,i=s,s=o,o=n,n=p+w|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,l=l+this.G|0,u=u+this.H|0,this.set(n,o,s,i,a,c,l,u)}roundClean(){Ut(Zt)}destroy(){this.set(0,0,0,0,0,0,0,0),Ut(this.buffer)}};var Xs=Fs(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),ou=Xs[0],su=Xs[1],$t=new Uint32Array(80),jt=new Uint32Array(80),Qn=class extends Ye{constructor(t=64){super(128,t,16,!1),this.Ah=tt[0]|0,this.Al=tt[1]|0,this.Bh=tt[2]|0,this.Bl=tt[3]|0,this.Ch=tt[4]|0,this.Cl=tt[5]|0,this.Dh=tt[6]|0,this.Dl=tt[7]|0,this.Eh=tt[8]|0,this.El=tt[9]|0,this.Fh=tt[10]|0,this.Fl=tt[11]|0,this.Gh=tt[12]|0,this.Gl=tt[13]|0,this.Hh=tt[14]|0,this.Hl=tt[15]|0}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:l,El:u,Fh:f,Fl:b,Gh:p,Gl:v,Hh:w,Hl:d}=this;return[t,e,n,o,s,i,a,c,l,u,f,b,p,v,w,d]}set(t,e,n,o,s,i,a,c,l,u,f,b,p,v,w,d){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=l|0,this.El=u|0,this.Fh=f|0,this.Fl=b|0,this.Gh=p|0,this.Gl=v|0,this.Hh=w|0,this.Hl=d|0}process(t,e){for(let A=0;A<16;A++,e+=4)$t[A]=t.getUint32(e),jt[A]=t.getUint32(e+=4);for(let A=16;A<80;A++){let C=$t[A-15]|0,y=jt[A-15]|0,P=oe(C,y,1)^oe(C,y,8)^Xn(C,y,7),D=se(C,y,1)^se(C,y,8)^Jn(C,y,7),B=$t[A-2]|0,h=jt[A-2]|0,x=oe(B,h,19)^We(B,h,61)^Xn(B,h,6),m=se(B,h,19)^Xe(B,h,61)^Jn(B,h,6),g=$s(D,m,jt[A-7],jt[A-16]),E=js(g,P,x,$t[A-7],$t[A-16]);$t[A]=E|0,jt[A]=g|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:l,Dl:u,Eh:f,El:b,Fh:p,Fl:v,Gh:w,Gl:d,Hh:S,Hl:L}=this;for(let A=0;A<80;A++){let C=oe(f,b,14)^oe(f,b,18)^We(f,b,41),y=se(f,b,14)^se(f,b,18)^Xe(f,b,41),P=f&p^~f&w,D=b&v^~b&d,B=Ys(L,y,D,su[A],jt[A]),h=Ws(B,S,C,P,ou[A],$t[A]),x=B|0,m=oe(n,o,28)^We(n,o,34)^We(n,o,39),g=se(n,o,28)^Xe(n,o,34)^Xe(n,o,39),E=n&s^n&a^s&a,_=o&i^o&c^i&c;S=w|0,L=d|0,w=p|0,d=v|0,p=f|0,v=b|0,{h:f,l:b}=Tt(l|0,u|0,h|0,x|0),l=a|0,u=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let I=Gs(x,g,_);n=Zs(I,h,m,E),o=I|0}({h:n,l:o}=Tt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Tt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Tt(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:u}=Tt(this.Dh|0,this.Dl|0,l|0,u|0),{h:f,l:b}=Tt(this.Eh|0,this.El|0,f|0,b|0),{h:p,l:v}=Tt(this.Fh|0,this.Fl|0,p|0,v|0),{h:w,l:d}=Tt(this.Gh|0,this.Gl|0,w|0,d|0),{h:S,l:L}=Tt(this.Hh|0,this.Hl|0,S|0,L|0),this.set(n,o,s,i,a,c,l,u,f,b,p,v,w,d,S,L)}roundClean(){Ut($t,jt)}destroy(){Ut(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Cr=Wn(()=>new Pr);var Js=Wn(()=>new Qn);var ro=BigInt(0),eo=BigInt(1);function Ot(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}function Je(r){let t=r.toString(16);return t.length&1?"0"+t:t}function Qs(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?ro:BigInt("0x"+r)}function Te(r){return Qs(Lt(r))}function ie(r){return ot(r),Qs(Lt(Uint8Array.from(r).reverse()))}function Nr(r,t){return Le(r.toString(16).padStart(t*2,"0"))}function De(r,t){return Nr(r,t).reverse()}function H(r,t,e){let n;if(typeof t=="string")try{n=Le(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(Be(t))n=Uint8Array.from(t);else throw new Error(r+" must be hex string or Uint8Array");let o=n.length;if(typeof e=="number"&&o!==e)throw new Error(r+" of length "+e+" expected, got "+o);return n}var to=r=>typeof r=="bigint"&&ro<=r;function ti(r,t,e){return to(r)&&to(t)&&to(e)&&t<=r&&r<e}function Yt(r,t,e,n){if(!ti(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function ei(r){let t;for(t=0;r>ro;r>>=eo,t+=1);return t}var ae=r=>(eo<<BigInt(r))-eo;function ri(r,t,e){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof e!="function")throw new Error("hmacFn must be a function");let n=p=>new Uint8Array(p),o=p=>Uint8Array.of(p),s=n(r),i=n(r),a=0,c=()=>{s.fill(1),i.fill(0),a=0},l=(...p)=>e(i,s,...p),u=(p=n(0))=>{i=l(o(0),p),s=l(),p.length!==0&&(i=l(o(1),p),s=l())},f=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let p=0,v=[];for(;p<t;){s=l();let w=s.slice();v.push(w),p+=s.length}return gt(...v)};return(p,v)=>{c(),u(p);let w;for(;!(w=v(f()));)u();return c(),w}}function Wt(r,t,e={}){if(!r||typeof r!="object")throw new Error("expected valid options object");function n(o,s,i){let a=r[o];if(i&&a===void 0)return;let c=typeof a;if(c!==s||a===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${c}`)}Object.entries(t).forEach(([o,s])=>n(o,s,!1)),Object.entries(e).forEach(([o,s])=>n(o,s,!0))}function Pe(r){let t=new WeakMap;return(e,...n)=>{let o=t.get(e);if(o!==void 0)return o;let s=r(e,...n);return t.set(e,s),s}}var ut=BigInt(0),Q=BigInt(1),ce=BigInt(2),iu=BigInt(3),si=BigInt(4),ii=BigInt(5),ai=BigInt(8);function G(r,t){let e=r%t;return e>=ut?e:t+e}function z(r,t,e){let n=r;for(;t-- >ut;)n*=n,n%=e;return n}function ni(r,t){if(r===ut)throw new Error("invert: expected non-zero number");if(t<=ut)throw new Error("invert: expected positive modulus, got "+t);let e=G(r,t),n=t,o=ut,s=Q,i=Q,a=ut;for(;e!==ut;){let l=n/e,u=n%e,f=o-i*l,b=s-a*l;n=e,e=u,o=i,s=a,i=f,a=b}if(n!==Q)throw new Error("invert: does not exist");return G(o,t)}function ci(r,t){let e=(r.ORDER+Q)/si,n=r.pow(t,e);if(!r.eql(r.sqr(n),t))throw new Error("Cannot find square root");return n}function au(r,t){let e=(r.ORDER-ii)/ai,n=r.mul(t,ce),o=r.pow(n,e),s=r.mul(t,o),i=r.mul(r.mul(s,ce),o),a=r.mul(s,r.sub(i,r.ONE));if(!r.eql(r.sqr(a),t))throw new Error("Cannot find square root");return a}function cu(r){if(r<BigInt(3))throw new Error("sqrt is not defined for small field");let t=r-Q,e=0;for(;t%ce===ut;)t/=ce,e++;let n=ce,o=It(r);for(;oi(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return ci;let s=o.pow(n,t),i=(t+Q)/ce;return function(c,l){if(c.is0(l))return l;if(oi(c,l)!==1)throw new Error("Cannot find square root");let u=e,f=c.mul(c.ONE,s),b=c.pow(l,t),p=c.pow(l,i);for(;!c.eql(b,c.ONE);){if(c.is0(b))return c.ZERO;let v=1,w=c.sqr(b);for(;!c.eql(w,c.ONE);)if(v++,w=c.sqr(w),v===u)throw new Error("Cannot find square root");let d=Q<<BigInt(u-v-1),S=c.pow(f,d);u=v,f=c.sqr(S),b=c.mul(b,f),p=c.mul(p,S)}return p}}function uu(r){return r%si===iu?ci:r%ai===ii?au:cu(r)}var ui=(r,t)=>(G(r,t)&Q)===Q,fu=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function no(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},e=fu.reduce((n,o)=>(n[o]="function",n),t);return Wt(r,e),r}function lu(r,t,e){if(e<ut)throw new Error("invalid exponent, negatives unsupported");if(e===ut)return r.ONE;if(e===Q)return t;let n=r.ONE,o=t;for(;e>ut;)e&Q&&(n=r.mul(n,o)),o=r.sqr(o),e>>=Q;return n}function Qe(r,t,e=!1){let n=new Array(t.length).fill(e?r.ZERO:void 0),o=t.reduce((i,a,c)=>r.is0(a)?i:(n[c]=i,r.mul(i,a)),r.ONE),s=r.inv(o);return t.reduceRight((i,a,c)=>r.is0(a)?i:(n[c]=r.mul(i,n[c]),r.mul(i,a)),s),n}function oi(r,t){let e=(r.ORDER-Q)/ce,n=r.pow(t,e),o=r.eql(n,r.ONE),s=r.eql(n,r.ZERO),i=r.eql(n,r.neg(r.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function fi(r,t){t!==void 0&&$e(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function It(r,t,e=!1,n={}){if(r<=ut)throw new Error("invalid field: expected ORDER > 0, got "+r);let o,s;if(typeof t=="object"&&t!=null){if(n.sqrt||e)throw new Error("cannot specify opts in two arguments");let u=t;u.BITS&&(o=u.BITS),u.sqrt&&(s=u.sqrt),typeof u.isLE=="boolean"&&(e=u.isLE)}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:i,nByteLength:a}=fi(r,o);if(a>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let c,l=Object.freeze({ORDER:r,isLE:e,BITS:i,BYTES:a,MASK:ae(i),ZERO:ut,ONE:Q,create:u=>G(u,r),isValid:u=>{if(typeof u!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof u);return ut<=u&&u<r},is0:u=>u===ut,isValidNot0:u=>!l.is0(u)&&l.isValid(u),isOdd:u=>(u&Q)===Q,neg:u=>G(-u,r),eql:(u,f)=>u===f,sqr:u=>G(u*u,r),add:(u,f)=>G(u+f,r),sub:(u,f)=>G(u-f,r),mul:(u,f)=>G(u*f,r),pow:(u,f)=>lu(l,u,f),div:(u,f)=>G(u*ni(f,r),r),sqrN:u=>u*u,addN:(u,f)=>u+f,subN:(u,f)=>u-f,mulN:(u,f)=>u*f,inv:u=>ni(u,r),sqrt:s||(u=>(c||(c=uu(r)),c(l,u))),toBytes:u=>e?De(u,a):Nr(u,a),fromBytes:u=>{if(u.length!==a)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+u.length);return e?ie(u):Te(u)},invertBatch:u=>Qe(l,u),cmov:(u,f,b)=>b?f:u});return Object.freeze(l)}function li(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let t=r.toString(2).length;return Math.ceil(t/8)}function oo(r){let t=li(r);return t+Math.ceil(t/2)}function hi(r,t,e=!1){let n=r.length,o=li(t),s=oo(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?ie(r):Te(r),a=G(i,t-Q)+Q;return e?De(a,o):Nr(a,o)}var Ne=BigInt(0),ue=BigInt(1);function Ce(r,t){let e=t.negate();return r?e:t}function kr(r,t,e){let n=t==="pz"?i=>i.pz:i=>i.ez,o=Qe(r.Fp,e.map(n));return e.map((i,a)=>i.toAffine(o[a])).map(r.fromAffine)}function yi(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function so(r,t){yi(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=ae(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function di(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,a=Number(r&o),c=r>>i;a>n&&(a-=s,c+=ue);let l=t*n,u=l+Math.abs(a)-1,f=a===0,b=a<0,p=t%2!==0;return{nextN:c,offset:u,isZero:f,isNeg:b,isNegF:p,offsetF:l}}function hu(r,t){if(!Array.isArray(r))throw new Error("array expected");r.forEach((e,n)=>{if(!(e instanceof t))throw new Error("invalid point at index "+n)})}function du(r,t){if(!Array.isArray(r))throw new Error("array of scalars expected");r.forEach((e,n)=>{if(!t.isValid(e))throw new Error("invalid scalar at index "+n)})}var io=new WeakMap,bi=new WeakMap;function ao(r){return bi.get(r)||1}function pi(r){if(r!==Ne)throw new Error("invalid wNAF")}function Kr(r,t){return{constTimeNegate:Ce,hasPrecomputes(e){return ao(e)!==1},unsafeLadder(e,n,o=r.ZERO){let s=e;for(;n>Ne;)n&ue&&(o=o.add(s)),s=s.double(),n>>=ue;return o},precomputeWindow(e,n){let{windows:o,windowSize:s}=so(n,t),i=[],a=e,c=a;for(let l=0;l<o;l++){c=a,i.push(c);for(let u=1;u<s;u++)c=c.add(a),i.push(c);a=c.double()}return i},wNAF(e,n,o){let s=r.ZERO,i=r.BASE,a=so(e,t);for(let c=0;c<a.windows;c++){let{nextN:l,offset:u,isZero:f,isNeg:b,isNegF:p,offsetF:v}=di(o,c,a);o=l,f?i=i.add(Ce(p,n[v])):s=s.add(Ce(b,n[u]))}return pi(o),{p:s,f:i}},wNAFUnsafe(e,n,o,s=r.ZERO){let i=so(e,t);for(let a=0;a<i.windows&&o!==Ne;a++){let{nextN:c,offset:l,isZero:u,isNeg:f}=di(o,a,i);if(o=c,!u){let b=n[l];s=s.add(f?b.negate():b)}}return pi(o),s},getPrecomputes(e,n,o){let s=io.get(n);return s||(s=this.precomputeWindow(n,e),e!==1&&(typeof o=="function"&&(s=o(s)),io.set(n,s))),s},wNAFCached(e,n,o){let s=ao(e);return this.wNAF(s,this.getPrecomputes(s,e,o),n)},wNAFCachedUnsafe(e,n,o,s){let i=ao(e);return i===1?this.unsafeLadder(e,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,e,o),n,s)},setWindowSize(e,n){yi(n,t),bi.set(e,n),io.delete(e)}}}function gi(r,t,e,n){let o=t,s=r.ZERO,i=r.ZERO;for(;e>Ne||n>Ne;)e&ue&&(s=s.add(o)),n&ue&&(i=i.add(o)),o=o.double(),e>>=ue,n>>=ue;return{p1:s,p2:i}}function Rr(r,t,e,n){hu(e,r),du(n,t);let o=e.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=r.ZERO,a=ei(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let l=ae(c),u=new Array(Number(l)+1).fill(i),f=Math.floor((t.BITS-1)/c)*c,b=i;for(let p=f;p>=0;p-=c){u.fill(i);for(let w=0;w<s;w++){let d=n[w],S=Number(d>>BigInt(p)&l);u[S]=u[S].add(e[w])}let v=i;for(let w=u.length-1,d=i;w>0;w--)d=d.add(u[w]),v=v.add(d);if(b=b.add(v),p!==0)for(let w=0;w<c;w++)b=b.double()}return b}function mi(r,t){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return no(t),t}else return It(r)}function Ur(r,t,e={}){if(!t||typeof t!="object")throw new Error(`expected valid ${r} CURVE object`);for(let a of["p","n","h"]){let c=t[a];if(!(typeof c=="bigint"&&c>Ne))throw new Error(`CURVE.${a} must be positive bigint`)}let n=mi(t.p,e.Fp),o=mi(t.n,e.Fn),i=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let a of i)if(!n.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return{Fp:n,Fn:o}}var Dt=BigInt(0),ft=BigInt(1),co=BigInt(2),pu=BigInt(8),mu={zip215:!0};function yu(r,t,e,n){let o=r.sqr(e),s=r.sqr(n),i=r.add(r.mul(t.a,o),s),a=r.add(r.ONE,r.mul(t.d,r.mul(o,s)));return r.eql(i,a)}function bu(r,t={}){let{Fp:e,Fn:n}=Ur("edwards",r,t),{h:o,n:s}=r;Wt(t,{},{uvRatio:"function"});let i=co<<BigInt(n.BYTES*8)-ft,a=w=>e.create(w),c=t.uvRatio||((w,d)=>{try{return{isValid:!0,value:e.sqrt(e.div(w,d))}}catch{return{isValid:!1,value:Dt}}});if(!yu(e,r,r.Gx,r.Gy))throw new Error("bad curve params: generator point");function l(w,d,S=!1){let L=S?ft:Dt;return Yt("coordinate "+w,d,L,i),d}function u(w){if(!(w instanceof p))throw new Error("ExtendedPoint expected")}let f=Pe((w,d)=>{let{ex:S,ey:L,ez:A}=w,C=w.is0();d==null&&(d=C?pu:e.inv(A));let y=a(S*d),P=a(L*d),D=a(A*d);if(C)return{x:Dt,y:ft};if(D!==ft)throw new Error("invZ was invalid");return{x:y,y:P}}),b=Pe(w=>{let{a:d,d:S}=r;if(w.is0())throw new Error("bad point: ZERO");let{ex:L,ey:A,ez:C,et:y}=w,P=a(L*L),D=a(A*A),B=a(C*C),h=a(B*B),x=a(P*d),m=a(B*a(x+D)),g=a(h+a(S*a(P*D)));if(m!==g)throw new Error("bad point: equation left != right (1)");let E=a(L*A),_=a(C*y);if(E!==_)throw new Error("bad point: equation left != right (2)");return!0});class p{constructor(d,S,L,A){this.ex=l("x",d),this.ey=l("y",S),this.ez=l("z",L,!0),this.et=l("t",A),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(d){if(d instanceof p)throw new Error("extended point not allowed");let{x:S,y:L}=d||{};return l("x",S),l("y",L),new p(S,L,ft,a(S*L))}static normalizeZ(d){return kr(p,"ez",d)}static msm(d,S){return Rr(p,n,d,S)}_setWindowSize(d){this.precompute(d)}precompute(d=8,S=!0){return v.setWindowSize(this,d),S||this.multiply(co),this}assertValidity(){b(this)}equals(d){u(d);let{ex:S,ey:L,ez:A}=this,{ex:C,ey:y,ez:P}=d,D=a(S*P),B=a(C*A),h=a(L*P),x=a(y*A);return D===B&&h===x}is0(){return this.equals(p.ZERO)}negate(){return new p(a(-this.ex),this.ey,this.ez,a(-this.et))}double(){let{a:d}=r,{ex:S,ey:L,ez:A}=this,C=a(S*S),y=a(L*L),P=a(co*a(A*A)),D=a(d*C),B=S+L,h=a(a(B*B)-C-y),x=D+y,m=x-P,g=D-y,E=a(h*m),_=a(x*g),I=a(h*g),T=a(m*x);return new p(E,_,T,I)}add(d){u(d);let{a:S,d:L}=r,{ex:A,ey:C,ez:y,et:P}=this,{ex:D,ey:B,ez:h,et:x}=d,m=a(A*D),g=a(C*B),E=a(P*L*x),_=a(y*h),I=a((A+C)*(D+B)-m-g),T=_-E,k=_+E,N=a(g-S*m),$=a(I*T),U=a(k*N),K=a(I*N),W=a(T*k);return new p($,U,W,K)}subtract(d){return this.add(d.negate())}multiply(d){let S=d;Yt("scalar",S,ft,s);let{p:L,f:A}=v.wNAFCached(this,S,p.normalizeZ);return p.normalizeZ([L,A])[0]}multiplyUnsafe(d,S=p.ZERO){let L=d;return Yt("scalar",L,Dt,s),L===Dt?p.ZERO:this.is0()||L===ft?this:v.wNAFCachedUnsafe(this,L,p.normalizeZ,S)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}isTorsionFree(){return v.wNAFCachedUnsafe(this,s).is0()}toAffine(d){return f(this,d)}clearCofactor(){return o===ft?this:this.multiplyUnsafe(o)}static fromBytes(d,S=!1){return ot(d),this.fromHex(d,S)}static fromHex(d,S=!1){let{d:L,a:A}=r,C=e.BYTES;d=H("pointHex",d,C),Ot("zip215",S);let y=d.slice(),P=d[C-1];y[C-1]=P&-129;let D=ie(y),B=S?i:e.ORDER;Yt("pointHex.y",D,Dt,B);let h=a(D*D),x=a(h-ft),m=a(L*h-A),{isValid:g,value:E}=c(x,m);if(!g)throw new Error("Point.fromHex: invalid y coordinate");let _=(E&ft)===ft,I=(P&128)!==0;if(!S&&E===Dt&&I)throw new Error("Point.fromHex: x=0 and x_0=1");return I!==_&&(E=a(-E)),p.fromAffine({x:E,y:D})}static fromPrivateScalar(d){return p.BASE.multiply(d)}toBytes(){let{x:d,y:S}=this.toAffine(),L=De(S,e.BYTES);return L[L.length-1]|=d&ft?128:0,L}toRawBytes(){return this.toBytes()}toHex(){return Lt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}p.BASE=new p(r.Gx,r.Gy,ft,a(r.Gx*r.Gy)),p.ZERO=new p(Dt,ft,ft,Dt),p.Fp=e,p.Fn=n;let v=Kr(p,n.BYTES*8);return p}function gu(r,t){Wt(t,{hash:"function"},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:e,hash:n}=t,{BASE:o,Fp:s,Fn:i}=r,a=i.ORDER,c=t.randomBytes||ne,l=t.adjustScalarBytes||(y=>y),u=t.domain||((y,P,D)=>{if(Ot("phflag",D),P.length||D)throw new Error("Contexts/pre-hash are not supported");return y});function f(y){return i.create(y)}function b(y){return f(ie(y))}function p(y){let P=s.BYTES;y=H("private key",y,P);let D=H("hashed private key",n(y),2*P),B=l(D.slice(0,P)),h=D.slice(P,2*P),x=b(B);return{head:B,prefix:h,scalar:x}}function v(y){let{head:P,prefix:D,scalar:B}=p(y),h=o.multiply(B),x=h.toBytes();return{head:P,prefix:D,scalar:B,point:h,pointBytes:x}}function w(y){return v(y).pointBytes}function d(y=Uint8Array.of(),...P){let D=gt(...P);return b(n(u(D,H("context",y),!!e)))}function S(y,P,D={}){y=H("message",y),e&&(y=e(y));let{prefix:B,scalar:h,pointBytes:x}=v(P),m=d(D.context,B,y),g=o.multiply(m).toBytes(),E=d(D.context,g,x,y),_=f(m+E*h);Yt("signature.s",_,Dt,a);let I=s.BYTES,T=gt(g,De(_,I));return H("result",T,I*2)}let L=mu;function A(y,P,D,B=L){let{context:h,zip215:x}=B,m=s.BYTES;y=H("signature",y,2*m),P=H("message",P),D=H("publicKey",D,m),x!==void 0&&Ot("zip215",x),e&&(P=e(P));let g=ie(y.slice(m,2*m)),E,_,I;try{E=r.fromHex(D,x),_=r.fromHex(y.slice(0,m),x),I=o.multiplyUnsafe(g)}catch{return!1}if(!x&&E.isSmallOrder())return!1;let T=d(h,_.toBytes(),E.toBytes(),P);return _.add(E.multiplyUnsafe(T)).subtract(I).clearCofactor().is0()}return o.precompute(8),{getPublicKey:w,sign:S,verify:A,utils:{getExtendedPublicKey:v,randomPrivateKey:()=>c(s.BYTES),precompute(y=8,P=r.BASE){return P.precompute(y,!1)}},Point:r}}function xu(r){let t={a:r.a,d:r.d,p:r.Fp.ORDER,n:r.n,h:r.h,Gx:r.Gx,Gy:r.Gy},e=r.Fp,n=It(t.n,r.nBitLength,!0),o={Fp:e,Fn:n,uvRatio:r.uvRatio},s={hash:r.hash,randomBytes:r.randomBytes,adjustScalarBytes:r.adjustScalarBytes,domain:r.domain,prehash:r.prehash,mapToCurve:r.mapToCurve};return{CURVE:t,curveOpts:o,eddsaOpts:s}}function wu(r,t){return Object.assign({},t,{ExtendedPoint:t.Point,CURVE:r})}function xi(r){let{CURVE:t,curveOpts:e,eddsaOpts:n}=xu(r),o=bu(t,e),s=gu(o,n);return wu(r,s)}var od=BigInt(0),Eu=BigInt(1),wi=BigInt(2),sd=BigInt(3),Su=BigInt(5),vu=BigInt(8),Mr={p:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:vu,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Au(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=Mr.p,a=r*r%s*r%s,c=z(a,wi,s)*a%s,l=z(c,Eu,s)*r%s,u=z(l,Su,s)*l%s,f=z(u,t,s)*u%s,b=z(f,e,s)*f%s,p=z(b,n,s)*b%s,v=z(p,o,s)*p%s,w=z(v,o,s)*p%s,d=z(w,t,s)*u%s;return{pow_p_5_8:z(d,wi,s)*r%s,b2:a}}function Iu(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var Ei=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Bu(r,t){let e=Mr.p,n=G(t*t*t,e),o=G(n*n*t,e),s=Au(r*o).pow_p_5_8,i=G(r*n*s,e),a=G(t*i*i,e),c=i,l=G(i*Ei,e),u=a===r,f=a===G(-r,e),b=a===G(-r*Ei,e);return u&&(i=c),(f||b)&&(i=l),ui(i,e)&&(i=G(-i,e)),{isValid:u||f,value:i}}var _u=It(Mr.p,void 0,!0),Lu={...Mr,Fp:_u,hash:Js,adjustScalarBytes:Iu,uvRatio:Bu},Si=xi(Lu);var tr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Or=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var vi={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new Or("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var wt=vi;var qr=32;var uo,Tu=(async()=>{try{return await wt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Du(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await wt.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await wt.get().subtle.verify({name:"Ed25519"},n,t,e instanceof Uint8Array?e:e.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Pu(r,t,e){return Si.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function Ai(r,t,e){return uo==null&&(uo=await Tu),uo?Du(r,t,e):Pu(r,t,e)}function Hr(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var zr=class{type="Ed25519";raw;constructor(t){this.raw=fo(t,qr)}toMultihash(){return vt.digest(Kt(this))}toCID(){return rt.createV1(114,this.toMultihash())}toString(){return F.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:dt(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let o=Ai(this.raw,e,t);return Hr(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function lo(r){return r=fo(r,qr),new zr(r)}function fo(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new V(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var Nu=Math.pow(2,7),ku=Math.pow(2,14),Ku=Math.pow(2,21),ho=Math.pow(2,28),po=Math.pow(2,35),mo=Math.pow(2,42),yo=Math.pow(2,49),R=128,st=127;function Bt(r){if(r<Nu)return 1;if(r<ku)return 2;if(r<Ku)return 3;if(r<ho)return 4;if(r<po)return 5;if(r<mo)return 6;if(r<yo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function bo(r,t,e=0){switch(Bt(r)){case 8:t[e++]=r&255|R,r/=128;case 7:t[e++]=r&255|R,r/=128;case 6:t[e++]=r&255|R,r/=128;case 5:t[e++]=r&255|R,r/=128;case 4:t[e++]=r&255|R,r>>>=7;case 3:t[e++]=r&255|R,r>>>=7;case 2:t[e++]=r&255|R,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Ru(r,t,e=0){switch(Bt(r)){case 8:t.set(e++,r&255|R),r/=128;case 7:t.set(e++,r&255|R),r/=128;case 6:t.set(e++,r&255|R),r/=128;case 5:t.set(e++,r&255|R),r/=128;case 4:t.set(e++,r&255|R),r>>>=7;case 3:t.set(e++,r&255|R),r>>>=7;case 2:t.set(e++,r&255|R),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function go(r,t){let e=r[t],n=0;if(n+=e&st,e<R||(e=r[t+1],n+=(e&st)<<7,e<R)||(e=r[t+2],n+=(e&st)<<14,e<R)||(e=r[t+3],n+=(e&st)<<21,e<R)||(e=r[t+4],n+=(e&st)*ho,e<R)||(e=r[t+5],n+=(e&st)*po,e<R)||(e=r[t+6],n+=(e&st)*mo,e<R)||(e=r[t+7],n+=(e&st)*yo,e<R))return n;throw new RangeError("Could not decode varint")}function Uu(r,t){let e=r.get(t),n=0;if(n+=e&st,e<R||(e=r.get(t+1),n+=(e&st)<<7,e<R)||(e=r.get(t+2),n+=(e&st)<<14,e<R)||(e=r.get(t+3),n+=(e&st)<<21,e<R)||(e=r.get(t+4),n+=(e&st)*ho,e<R)||(e=r.get(t+5),n+=(e&st)*po,e<R)||(e=r.get(t+6),n+=(e&st)*mo,e<R)||(e=r.get(t+7),n+=(e&st)*yo,e<R))return n;throw new RangeError("Could not decode varint")}function Bi(r,t,e=0){return t==null&&(t=nt(Bt(r))),t instanceof Uint8Array?bo(r,t,e):Ru(r,t,e)}function _i(r,t=0){return r instanceof Uint8Array?go(r,t):Uu(r,t)}var xo=new Float32Array([-0]),Xt=new Uint8Array(xo.buffer);function Ti(r,t,e){xo[0]=r,t[e]=Xt[0],t[e+1]=Xt[1],t[e+2]=Xt[2],t[e+3]=Xt[3]}function Di(r,t){return Xt[0]=r[t],Xt[1]=r[t+1],Xt[2]=r[t+2],Xt[3]=r[t+3],xo[0]}var wo=new Float64Array([-0]),it=new Uint8Array(wo.buffer);function Pi(r,t,e){wo[0]=r,t[e]=it[0],t[e+1]=it[1],t[e+2]=it[2],t[e+3]=it[3],t[e+4]=it[4],t[e+5]=it[5],t[e+6]=it[6],t[e+7]=it[7]}function Ci(r,t){return it[0]=r[t],it[1]=r[t+1],it[2]=r[t+2],it[3]=r[t+3],it[4]=r[t+4],it[5]=r[t+5],it[6]=r[t+6],it[7]=r[t+7],wo[0]}var Mu=BigInt(Number.MAX_SAFE_INTEGER),Ou=BigInt(Number.MIN_SAFE_INTEGER),xt=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return fe;if(t<Mu&&t>Ou)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>Ni&&(o=0n,++n>Ni&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return fe;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):fe}},fe=new xt(0,0);fe.toBigInt=function(){return 0n};fe.zzEncode=fe.zzDecode=function(){return this};fe.length=function(){return 1};var Ni=4294967296n;function ki(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Ki(r,t,e){if(e-t<1)return"";let o,s=[],i=0,a;for(;t<e;)a=r[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function Eo(r,t,e){let n=e,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function _t(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Vr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var So=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,_t(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw _t(this,4);return Vr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw _t(this,4);return Vr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw _t(this,4);let t=Di(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw _t(this,4);let t=Ci(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw _t(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Ki(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw _t(this,t);this.pos+=t}else do if(this.pos>=this.len)throw _t(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new xt(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw _t(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw _t(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw _t(this,8);let t=Vr(this.buf,this.pos+=4),e=Vr(this.buf,this.pos+=4);return new xt(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=go(this.buf,this.pos);return this.pos+=Bt(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function vo(r){return new So(r instanceof Uint8Array?r:r.subarray())}function mt(r,t,e){let n=vo(r);return t.decode(n,void 0,e)}function Ao(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return nt(i);o+i>t&&(n=nt(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var le=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Io(){}var _o=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},qu=Ao();function Hu(r){return globalThis.Buffer!=null?nt(r):qu(r)}var rr=class{len;head;tail;states;constructor(){this.len=0,this.head=new le(Io,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new le(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Lo((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(Fr,10,xt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=xt.fromBigInt(t);return this._push(Fr,e.length(),e)}uint64Number(t){return this._push(bo,Bt(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=xt.fromBigInt(t).zzEncode();return this._push(Fr,e.length(),e)}sint64Number(t){let e=xt.fromNumber(t).zzEncode();return this._push(Fr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Bo,1,t?1:0)}fixed32(t){return this._push(er,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=xt.fromBigInt(t);return this._push(er,4,e.lo)._push(er,4,e.hi)}fixed64Number(t){let e=xt.fromNumber(t);return this._push(er,4,e.lo)._push(er,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Ti,4,t)}double(t){return this._push(Pi,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Bo,1,0):this.uint32(e)._push(Vu,e,t)}string(t){let e=ki(t);return e!==0?this.uint32(e)._push(Eo,e,t):this._push(Bo,1,0)}fork(){return this.states=new _o(this),this.head=this.tail=new le(Io,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 le(Io,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=Hu(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Bo(r,t,e){t[e]=r&255}function zu(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Lo=class extends le{next;constructor(t,e){super(zu,t,e),this.next=void 0}};function Fr(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function er(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function Vu(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(rr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Fu,t,r),this},rr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Gu,t,r),this});function Fu(r,t,e){t.set(r,e)}function Gu(r,t,e){r.length<40?Eo(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(O(r),e)}function To(){return new rr}function yt(r,t){let e=To();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var ke;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(ke||(ke={}));function Gr(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Do(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(s,i){let a=t(s);i.int32(a)},n=function(s){let i=s.int32();return t(i)};return Gr("enum",ke.VARINT,e,n)}function bt(r,t){return Gr("message",ke.LENGTH_DELIMITED,r,t)}var Et=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var Y;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(Y||(Y={}));var Po;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(Po||(Po={}));(function(r){r.codec=()=>Do(Po)})(Y||(Y={}));var Pt;(function(r){let t;r.codec=()=>(t==null&&(t=bt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),Y.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=Y.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>yt(e,r.codec()),r.decode=(e,n)=>mt(e,r.codec(),n)})(Pt||(Pt={}));var Co;(function(r){let t;r.codec=()=>(t==null&&(t=bt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),Y.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=Y.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>yt(e,r.codec()),r.decode=(e,n)=>mt(e,r.codec(),n)})(Co||(Co={}));function Zr(r){if(isNaN(r)||r<=0)throw new V("random bytes length must be a Number bigger than 0");return ne(r)}var or={};ht(or,{MAX_RSA_KEY_SIZE:()=>No,generateRSAKeyPair:()=>Hi,jwkToJWKKeyPair:()=>zi,jwkToPkcs1:()=>Yu,jwkToPkix:()=>Uo,jwkToRSAPrivateKey:()=>Ho,pkcs1MessageToJwk:()=>Ko,pkcs1MessageToRSAPrivateKey:()=>Mo,pkcs1ToJwk:()=>ju,pkcs1ToRSAPrivateKey:()=>qi,pkixMessageToJwk:()=>Ro,pkixMessageToRSAPublicKey:()=>qo,pkixToJwk:()=>Wu,pkixToRSAPublicKey:()=>Oo});var $r=Cr;var Ke=class{type="RSA";jwk;_raw;_multihash;constructor(t,e){this.jwk=t,this._multihash=e}get raw(){return this._raw==null&&(this._raw=or.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return rt.createV1(114,this._multihash)}toString(){return F.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:dt(this.raw,t.raw)}verify(t,e,n){return Oi(this.jwk,e,t,n)}},nr=class{type="RSA";jwk;_raw;publicKey;constructor(t,e){this.jwk=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=or.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:dt(this.raw,t.raw)}sign(t,e){return Mi(this.jwk,t,e)}};var No=8192,ko=18,Zu=1062,$u=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function ju(r){let t=kt(r);return Ko(t)}function Ko(r){return{n:M(r[1],"base64url"),e:M(r[2],"base64url"),d:M(r[3],"base64url"),p:M(r[4],"base64url"),q:M(r[5],"base64url"),dp:M(r[6],"base64url"),dq:M(r[7],"base64url"),qi:M(r[8],"base64url"),kty:"RSA"}}function Yu(r){if(r.n==null||r.e==null||r.d==null||r.p==null||r.q==null||r.dp==null||r.dq==null||r.qi==null)throw new V("JWK was missing components");return Gt([pt(Uint8Array.from([0])),pt(O(r.n,"base64url")),pt(O(r.e,"base64url")),pt(O(r.d,"base64url")),pt(O(r.p,"base64url")),pt(O(r.q,"base64url")),pt(O(r.dp,"base64url")),pt(O(r.dq,"base64url")),pt(O(r.qi,"base64url"))]).subarray()}function Wu(r){let t=kt(r,{offset:0});return Ro(t)}function Ro(r){let t=kt(r[1],{offset:0});return{kty:"RSA",n:M(t[0],"base64url"),e:M(t[1],"base64url")}}function Uo(r){if(r.n==null||r.e==null)throw new V("JWK was missing components");return Gt([$u,Lr(Gt([pt(O(r.n,"base64url")),pt(O(r.e,"base64url"))]))]).subarray()}function qi(r){let t=kt(r);return Mo(t)}function Mo(r){let t=Ko(r);return Ho(t)}function Oo(r,t){if(r.byteLength>=Zu)throw new be("Key size is too large");let e=kt(r,{offset:0});return qo(e,r,t)}function qo(r,t,e){let n=Ro(r);if(e==null){let o=$r(Pt.encode({Type:Y.RSA,Data:t}));e=St(ko,o)}return new Ke(n,e)}function Ho(r){if(Fi(r)>No)throw new V("Key size is too large");let t=zi(r),e=$r(Pt.encode({Type:Y.RSA,Data:Uo(t.publicKey)})),n=St(ko,e);return new nr(t.privateKey,new Ke(t.publicKey,n))}async function Hi(r){if(r>No)throw new V("Key size is too large");let t=await Vi(r),e=$r(Pt.encode({Type:Y.RSA,Data:Uo(t.publicKey)})),n=St(ko,e);return new nr(t.privateKey,new Ke(t.publicKey,n))}function zi(r){if(r==null)throw new V("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function Vi(r,t){let e=await wt.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await Xu(e,t);return{privateKey:n[0],publicKey:n[1]}}async function Mi(r,t,e){let n=await wt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);e?.signal?.throwIfAborted();let o=await wt.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return e?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Oi(r,t,e,n){let o=await wt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await wt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,e instanceof Uint8Array?e:e.subarray());return n?.signal?.throwIfAborted(),s}async function Xu(r,t){if(r.privateKey==null||r.publicKey==null)throw new V("Private and public key are required");let e=await Promise.all([wt.get().subtle.exportKey("jwk",r.privateKey),wt.get().subtle.exportKey("jwk",r.publicKey)]);return t?.signal?.throwIfAborted(),e}function Fi(r){if(r.kty!=="RSA")throw new V("invalid key type");if(r.n==null)throw new V("invalid key modulus");return O(r.n,"base64url").length*8}var jr=class extends Ie{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,Us(t);let n=je(e);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),Ut(s)}update(t){return _e(this),this.iHash.update(t),this}digestInto(t){_e(this),ot(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:e,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},zo=(r,t,e)=>new jr(r,t).update(e).digest();zo.create=(r,t)=>new jr(r,t);function Gi(r){r.lowS!==void 0&&Ot("lowS",r.lowS),r.prehash!==void 0&&Ot("prehash",r.prehash)}var Vo=class extends Error{constructor(t=""){super(t)}},qt={Err:Vo,_tlv:{encode:(r,t)=>{let{Err:e}=qt;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,o=Je(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?Je(o.length/2|128):"";return Je(r)+s+o+t},decode(r,t){let{Err:e}=qt,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new e("tlv.decode(long): indefinite length not supported");if(c>4)throw new e("tlv.decode(long): byte length is too big");let l=t.subarray(n,n+c);if(l.length!==c)throw new e("tlv.decode: length bytes not complete");if(l[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let u of l)i=i<<8|u;if(n+=c,i<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=qt;if(r<sr)throw new t("integer: negative integers are not allowed");let e=Je(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return e},decode(r){let{Err:t}=qt;if(r[0]&128)throw new t("invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Te(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=qt,o=H("signature",r),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:l,l:u}=n.decode(2,c);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(l)}},hexFromSig(r){let{_tlv:t,_int:e}=qt,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}},sr=BigInt(0),ir=BigInt(1),Ju=BigInt(2),Yr=BigInt(3),Qu=BigInt(4);function tf(r,t,e){function n(o){let s=r.sqr(o),i=r.mul(s,o);return r.add(r.add(i,r.mul(o,t)),e)}return n}function Zi(r,t,e){let{BYTES:n}=r;function o(s){let i;if(typeof s=="bigint")i=s;else{let a=H("private key",s);if(t){if(!t.includes(a.length*2))throw new Error("invalid private key");let c=new Uint8Array(n);c.set(a,c.length-a.length),a=c}try{i=r.fromBytes(a)}catch{throw new Error(`invalid private key: expected ui8a of size ${n}, got ${typeof s}`)}}if(e&&(i=r.create(i)),!r.isValidNot0(i))throw new Error("invalid private key: out of range [1..N-1]");return i}return o}function ef(r,t={}){let{Fp:e,Fn:n}=Ur("weierstrass",r,t),{h:o,n:s}=r;Wt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:i}=t;if(i&&(!e.is0(r.a)||typeof i.beta!="bigint"||typeof i.splitScalar!="function"))throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function');function a(){if(!e.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function c(B,h,x){let{x:m,y:g}=h.toAffine(),E=e.toBytes(m);if(Ot("isCompressed",x),x){a();let _=!e.isOdd(g);return gt($i(_),E)}else return gt(Uint8Array.of(4),E,e.toBytes(g))}function l(B){ot(B);let h=e.BYTES,x=h+1,m=2*h+1,g=B.length,E=B[0],_=B.subarray(1);if(g===x&&(E===2||E===3)){let I=e.fromBytes(_);if(!e.isValid(I))throw new Error("bad point: is not on curve, wrong x");let T=b(I),k;try{k=e.sqrt(T)}catch(U){let K=U instanceof Error?": "+U.message:"";throw new Error("bad point: is not on curve, sqrt error"+K)}a();let N=e.isOdd(k);return(E&1)===1!==N&&(k=e.neg(k)),{x:I,y:k}}else if(g===m&&E===4){let I=e.fromBytes(_.subarray(h*0,h*1)),T=e.fromBytes(_.subarray(h*1,h*2));if(!p(I,T))throw new Error("bad point: is not on curve");return{x:I,y:T}}else throw new Error(`bad point: got length ${g}, expected compressed=${x} or uncompressed=${m}`)}let u=t.toBytes||c,f=t.fromBytes||l,b=tf(e,r.a,r.b);function p(B,h){let x=e.sqr(h),m=b(B);return e.eql(x,m)}if(!p(r.Gx,r.Gy))throw new Error("bad curve params: generator point");let v=e.mul(e.pow(r.a,Yr),Qu),w=e.mul(e.sqr(r.b),BigInt(27));if(e.is0(e.add(v,w)))throw new Error("bad curve params: a or b");function d(B,h,x=!1){if(!e.isValid(h)||x&&e.is0(h))throw new Error(`bad point coordinate ${B}`);return h}function S(B){if(!(B instanceof y))throw new Error("ProjectivePoint expected")}let L=Pe((B,h)=>{let{px:x,py:m,pz:g}=B;if(e.eql(g,e.ONE))return{x,y:m};let E=B.is0();h==null&&(h=E?e.ONE:e.inv(g));let _=e.mul(x,h),I=e.mul(m,h),T=e.mul(g,h);if(E)return{x:e.ZERO,y:e.ZERO};if(!e.eql(T,e.ONE))throw new Error("invZ was invalid");return{x:_,y:I}}),A=Pe(B=>{if(B.is0()){if(t.allowInfinityPoint&&!e.is0(B.py))return;throw new Error("bad point: ZERO")}let{x:h,y:x}=B.toAffine();if(!e.isValid(h)||!e.isValid(x))throw new Error("bad point: x or y not field elements");if(!p(h,x))throw new Error("bad point: equation left != right");if(!B.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function C(B,h,x,m,g){return x=new y(e.mul(x.px,B),x.py,x.pz),h=Ce(m,h),x=Ce(g,x),h.add(x)}class y{constructor(h,x,m){this.px=d("x",h),this.py=d("y",x,!0),this.pz=d("z",m),Object.freeze(this)}static fromAffine(h){let{x,y:m}=h||{};if(!h||!e.isValid(x)||!e.isValid(m))throw new Error("invalid affine point");if(h instanceof y)throw new Error("projective point not allowed");return e.is0(x)&&e.is0(m)?y.ZERO:new y(x,m,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){return kr(y,"pz",h)}static fromBytes(h){return ot(h),y.fromHex(h)}static fromHex(h){let x=y.fromAffine(f(H("pointHex",h)));return x.assertValidity(),x}static fromPrivateKey(h){let x=Zi(n,t.allowedPrivateKeyLengths,t.wrapPrivateKey);return y.BASE.multiply(x(h))}static msm(h,x){return Rr(y,n,h,x)}precompute(h=8,x=!0){return D.setWindowSize(this,h),x||this.multiply(Yr),this}_setWindowSize(h){this.precompute(h)}assertValidity(){A(this)}hasEvenY(){let{y:h}=this.toAffine();if(!e.isOdd)throw new Error("Field doesn't support isOdd");return!e.isOdd(h)}equals(h){S(h);let{px:x,py:m,pz:g}=this,{px:E,py:_,pz:I}=h,T=e.eql(e.mul(x,I),e.mul(E,g)),k=e.eql(e.mul(m,I),e.mul(_,g));return T&&k}negate(){return new y(this.px,e.neg(this.py),this.pz)}double(){let{a:h,b:x}=r,m=e.mul(x,Yr),{px:g,py:E,pz:_}=this,I=e.ZERO,T=e.ZERO,k=e.ZERO,N=e.mul(g,g),$=e.mul(E,E),U=e.mul(_,_),K=e.mul(g,E);return K=e.add(K,K),k=e.mul(g,_),k=e.add(k,k),I=e.mul(h,k),T=e.mul(m,U),T=e.add(I,T),I=e.sub($,T),T=e.add($,T),T=e.mul(I,T),I=e.mul(K,I),k=e.mul(m,k),U=e.mul(h,U),K=e.sub(N,U),K=e.mul(h,K),K=e.add(K,k),k=e.add(N,N),N=e.add(k,N),N=e.add(N,U),N=e.mul(N,K),T=e.add(T,N),U=e.mul(E,_),U=e.add(U,U),N=e.mul(U,K),I=e.sub(I,N),k=e.mul(U,$),k=e.add(k,k),k=e.add(k,k),new y(I,T,k)}add(h){S(h);let{px:x,py:m,pz:g}=this,{px:E,py:_,pz:I}=h,T=e.ZERO,k=e.ZERO,N=e.ZERO,$=r.a,U=e.mul(r.b,Yr),K=e.mul(x,E),W=e.mul(m,_),J=e.mul(g,I),et=e.add(x,m),q=e.add(E,_);et=e.mul(et,q),q=e.add(K,W),et=e.sub(et,q),q=e.add(x,g);let ct=e.add(E,I);return q=e.mul(q,ct),ct=e.add(K,J),q=e.sub(q,ct),ct=e.add(m,g),T=e.add(_,I),ct=e.mul(ct,T),T=e.add(W,J),ct=e.sub(ct,T),N=e.mul($,q),T=e.mul(U,J),N=e.add(T,N),T=e.sub(W,N),N=e.add(W,N),k=e.mul(T,N),W=e.add(K,K),W=e.add(W,K),J=e.mul($,J),q=e.mul(U,q),W=e.add(W,J),J=e.sub(K,J),J=e.mul($,J),q=e.add(q,J),K=e.mul(W,q),k=e.add(k,K),K=e.mul(ct,q),T=e.mul(et,T),T=e.sub(T,K),K=e.mul(et,W),N=e.mul(ct,N),N=e.add(N,K),new y(T,k,N)}subtract(h){return this.add(h.negate())}is0(){return this.equals(y.ZERO)}multiply(h){let{endo:x}=t;if(!n.isValidNot0(h))throw new Error("invalid scalar: out of range");let m,g,E=_=>D.wNAFCached(this,_,y.normalizeZ);if(x){let{k1neg:_,k1:I,k2neg:T,k2:k}=x.splitScalar(h),{p:N,f:$}=E(I),{p:U,f:K}=E(k);g=$.add(K),m=C(x.beta,N,U,_,T)}else{let{p:_,f:I}=E(h);m=_,g=I}return y.normalizeZ([m,g])[0]}multiplyUnsafe(h){let{endo:x}=t,m=this;if(!n.isValid(h))throw new Error("invalid scalar: out of range");if(h===sr||m.is0())return y.ZERO;if(h===ir)return m;if(D.hasPrecomputes(this))return this.multiply(h);if(x){let{k1neg:g,k1:E,k2neg:_,k2:I}=x.splitScalar(h),{p1:T,p2:k}=gi(y,m,E,I);return C(x.beta,T,k,g,_)}else return D.wNAFCachedUnsafe(m,h)}multiplyAndAddUnsafe(h,x,m){let g=this.multiplyUnsafe(x).add(h.multiplyUnsafe(m));return g.is0()?void 0:g}toAffine(h){return L(this,h)}isTorsionFree(){let{isTorsionFree:h}=t;return o===ir?!0:h?h(y,this):D.wNAFCachedUnsafe(this,s).is0()}clearCofactor(){let{clearCofactor:h}=t;return o===ir?this:h?h(y,this):this.multiplyUnsafe(o)}toBytes(h=!0){return Ot("isCompressed",h),this.assertValidity(),u(y,this,h)}toRawBytes(h=!0){return this.toBytes(h)}toHex(h=!0){return Lt(this.toBytes(h))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}y.BASE=new y(r.Gx,r.Gy,e.ONE),y.ZERO=new y(e.ZERO,e.ONE,e.ZERO),y.Fp=e,y.Fn=n;let P=n.BITS,D=Kr(y,t.endo?Math.ceil(P/2):P);return y}function $i(r){return Uint8Array.of(r?2:3)}function rf(r,t,e={}){Wt(t,{hash:"function"},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=t.randomBytes||ne,o=t.hmac||((m,...g)=>zo(t.hash,m,gt(...g))),{Fp:s,Fn:i}=r,{ORDER:a,BITS:c}=i;function l(m){let g=a>>ir;return m>g}function u(m){return l(m)?i.neg(m):m}function f(m,g){if(!i.isValidNot0(g))throw new Error(`invalid signature ${m}: out of range 1..CURVE.n`)}class b{constructor(g,E,_){f("r",g),f("s",E),this.r=g,this.s=E,_!=null&&(this.recovery=_),Object.freeze(this)}static fromCompact(g){let E=i.BYTES,_=H("compactSignature",g,E*2);return new b(i.fromBytes(_.subarray(0,E)),i.fromBytes(_.subarray(E,E*2)))}static fromDER(g){let{r:E,s:_}=qt.toSig(H("DER",g));return new b(E,_)}assertValidity(){}addRecoveryBit(g){return new b(this.r,this.s,g)}recoverPublicKey(g){let E=s.ORDER,{r:_,s:I,recovery:T}=this;if(T==null||![0,1,2,3].includes(T))throw new Error("recovery id invalid");if(a*Ju<E&&T>1)throw new Error("recovery id is ambiguous for h>1 curve");let N=T===2||T===3?_+a:_;if(!s.isValid(N))throw new Error("recovery id 2 or 3 invalid");let $=s.toBytes(N),U=r.fromHex(gt($i((T&1)===0),$)),K=i.inv(N),W=A(H("msgHash",g)),J=i.create(-W*K),et=i.create(I*K),q=r.BASE.multiplyUnsafe(J).add(U.multiplyUnsafe(et));if(q.is0())throw new Error("point at infinify");return q.assertValidity(),q}hasHighS(){return l(this.s)}normalizeS(){return this.hasHighS()?new b(this.r,i.neg(this.s),this.recovery):this}toBytes(g){if(g==="compact")return gt(i.toBytes(this.r),i.toBytes(this.s));if(g==="der")return Le(qt.hexFromSig(this));throw new Error("invalid format")}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return Lt(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return Lt(this.toBytes("compact"))}}let p=Zi(i,e.allowedPrivateKeyLengths,e.wrapPrivateKey),v={isValidPrivateKey(m){try{return p(m),!0}catch{return!1}},normPrivateKeyToScalar:p,randomPrivateKey:()=>{let m=a;return hi(n(oo(m)),m)},precompute(m=8,g=r.BASE){return g.precompute(m,!1)}};function w(m,g=!0){return r.fromPrivateKey(m).toBytes(g)}function d(m){if(typeof m=="bigint")return!1;if(m instanceof r)return!0;let E=H("key",m).length,_=s.BYTES,I=_+1,T=2*_+1;if(!(e.allowedPrivateKeyLengths||i.BYTES===I))return E===I||E===T}function S(m,g,E=!0){if(d(m)===!0)throw new Error("first arg must be private key");if(d(g)===!1)throw new Error("second arg must be public key");return r.fromHex(g).multiply(p(m)).toBytes(E)}let L=t.bits2int||function(m){if(m.length>8192)throw new Error("input is too large");let g=Te(m),E=m.length*8-c;return E>0?g>>BigInt(E):g},A=t.bits2int_modN||function(m){return i.create(L(m))},C=ae(c);function y(m){return Yt("num < 2^"+c,m,sr,C),i.toBytes(m)}function P(m,g,E=D){if(["recovered","canonical"].some(et=>et in E))throw new Error("sign() legacy options not supported");let{hash:_}=t,{lowS:I,prehash:T,extraEntropy:k}=E;I==null&&(I=!0),m=H("msgHash",m),Gi(E),T&&(m=H("prehashed msgHash",_(m)));let N=A(m),$=p(g),U=[y($),y(N)];if(k!=null&&k!==!1){let et=k===!0?n(s.BYTES):k;U.push(H("extraEntropy",et))}let K=gt(...U),W=N;function J(et){let q=L(et);if(!i.isValidNot0(q))return;let ct=i.inv(q),Oe=r.BASE.multiply(q).toAffine(),me=i.create(Oe.x);if(me===sr)return;let Jt=i.create(ct*i.create(W+me*$));if(Jt===sr)return;let wn=(Oe.x===me?0:2)|Number(Oe.y&ir),ye=Jt;return I&&l(Jt)&&(ye=u(Jt),wn^=1),new b(me,ye,wn)}return{seed:K,k2sig:J}}let D={lowS:t.lowS,prehash:!1},B={lowS:t.lowS,prehash:!1};function h(m,g,E=D){let{seed:_,k2sig:I}=P(m,g,E);return ri(t.hash.outputLen,i.BYTES,o)(_,I)}r.BASE.precompute(8);function x(m,g,E,_=B){let I=m;g=H("msgHash",g),E=H("publicKey",E),Gi(_);let{lowS:T,prehash:k,format:N}=_;if("strict"in _)throw new Error("options.strict was renamed to lowS");if(N!==void 0&&!["compact","der","js"].includes(N))throw new Error('format must be "compact", "der" or "js"');let $=typeof I=="string"||Be(I),U=!$&&!N&&typeof I=="object"&&I!==null&&typeof I.r=="bigint"&&typeof I.s=="bigint";if(!$&&!U)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let K,W;try{if(U)if(N===void 0||N==="js")K=new b(I.r,I.s);else throw new Error("invalid format");if($){try{N!=="compact"&&(K=b.fromDER(I))}catch(ye){if(!(ye instanceof qt.Err))throw ye}!K&&N!=="der"&&(K=b.fromCompact(I))}W=r.fromHex(E)}catch{return!1}if(!K||T&&K.hasHighS())return!1;k&&(g=t.hash(g));let{r:J,s:et}=K,q=A(g),ct=i.inv(et),Oe=i.create(q*ct),me=i.create(J*ct),Jt=r.BASE.multiplyUnsafe(Oe).add(W.multiplyUnsafe(me));return Jt.is0()?!1:i.create(Jt.x)===J}return Object.freeze({getPublicKey:w,getSharedSecret:S,sign:h,verify:x,utils:v,Point:r,Signature:b})}function nf(r){let t={a:r.a,b:r.b,p:r.Fp.ORDER,n:r.n,h:r.h,Gx:r.Gx,Gy:r.Gy},e=r.Fp,n=It(t.n,r.nBitLength),o={Fp:e,Fn:n,allowedPrivateKeyLengths:r.allowedPrivateKeyLengths,allowInfinityPoint:r.allowInfinityPoint,endo:r.endo,wrapPrivateKey:r.wrapPrivateKey,isTorsionFree:r.isTorsionFree,clearCofactor:r.clearCofactor,fromBytes:r.fromBytes,toBytes:r.toBytes};return{CURVE:t,curveOpts:o}}function of(r){let{CURVE:t,curveOpts:e}=nf(r),n={hash:r.hash,hmac:r.hmac,randomBytes:r.randomBytes,lowS:r.lowS,bits2int:r.bits2int,bits2int_modN:r.bits2int_modN};return{CURVE:t,curveOpts:e,ecdsaOpts:n}}function sf(r,t){return Object.assign({},t,{ProjectivePoint:t.Point,CURVE:r})}function ji(r){let{CURVE:t,curveOpts:e,ecdsaOpts:n}=of(r),o=ef(t,e),s=rf(o,n,e);return sf(r,s)}function Yi(r,t){let e=n=>ji({...r,hash:n});return{...e(t),create:e}}var Wr={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},jp=BigInt(0),af=BigInt(1),Fo=BigInt(2),Wi=(r,t)=>(r+t/Fo)/t;function cf(r){let t=Wr.p,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),l=r*r*r%t,u=l*l*r%t,f=z(u,e,t)*u%t,b=z(f,e,t)*u%t,p=z(b,Fo,t)*l%t,v=z(p,o,t)*p%t,w=z(v,s,t)*v%t,d=z(w,a,t)*w%t,S=z(d,c,t)*d%t,L=z(S,a,t)*w%t,A=z(L,e,t)*u%t,C=z(A,i,t)*v%t,y=z(C,n,t)*l%t,P=z(y,Fo,t);if(!Go.eql(Go.sqr(P),r))throw new Error("Cannot find square root");return P}var Go=It(Wr.p,void 0,void 0,{sqrt:cf}),Re=Yi({...Wr,Fp:Go,lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=Wr.n,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-af*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=e,i=BigInt("0x100000000000000000000000000000000"),a=Wi(s*r,t),c=Wi(-n*r,t),l=G(r-a*e-c*o,t),u=G(-a*n-c*s,t),f=l>i,b=u>i;if(f&&(l=t-l),b&&(u=t-u),l>i||u>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:f,k1:l,k2neg:b,k2:u}}}},Cr);function Xi(r,t,e,n){let o=ee.digest(e instanceof Uint8Array?e:e.subarray());if(Hr(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Re.verify(t,s,r))).catch(s=>{throw s.name==="AbortError"?s:new tr(String(s))});try{return n?.signal?.throwIfAborted(),Re.verify(t,o.digest,r)}catch(s){throw new tr(String(s))}}var Xr=class{type="secp256k1";raw;_key;constructor(t){this._key=Qi(t),this.raw=Ji(this._key)}toMultihash(){return vt.digest(Kt(this))}toCID(){return rt.createV1(114,this.toMultihash())}toString(){return F.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:dt(this.raw,t.raw)}verify(t,e,n){return Xi(this._key,e,t,n)}};function Zo(r){return new Xr(r)}function Ji(r){return Re.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Qi(r){try{return Re.ProjectivePoint.fromHex(r),r}catch(t){throw new be(String(t))}}function $o(r,t){let{Type:e,Data:n}=Pt.decode(r),o=n??new Uint8Array;switch(e){case Y.RSA:return Oo(o,t);case Y.Ed25519:return lo(o);case Y.secp256k1:return Zo(o);case Y.ECDSA:return Yn(o);default:throw new Qt}}function ta(r){let{Type:t,Data:e}=Pt.decode(r.digest),n=e??new Uint8Array;switch(t){case Y.Ed25519:return lo(n);case Y.secp256k1:return Zo(n);case Y.ECDSA:return Yn(n);default:throw new Qt}}function Kt(r){return Pt.encode({Type:Y[r.type],Data:r.raw})}var ea=Symbol.for("nodejs.util.inspect.custom"),uf=114,ar=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[En]=!0;toString(){return this.string==null&&(this.string=F.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return rt.createV1(uf,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return dt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return dt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[ea](){return`PeerId(${this.toString()})`}},cr=class extends ar{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},ur=class extends ar{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},fr=class extends ar{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},ff=2336,Jr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=vt.digest(O(this.url))}[ea](){return`PeerId(${this.url})`}[En]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return rt.createV1(ff,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=M(t)),t.toString()===this.toString())}};function jo(r){if(r.type==="Ed25519")return new ur({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new fr({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new cr({multihash:r.toCID().multihash,publicKey:r});throw new Qt}function ra(r){return jo(r.publicKey)}function lr(r){if(hf(r))return new cr({multihash:r});if(lf(r))try{let t=ta(r);if(t.type==="Ed25519")return new ur({multihash:r,publicKey:t});if(t.type==="secp256k1")return new fr({multihash:r,publicKey:t})}catch{let e=M(r.digest);return new Jr(new URL(e))}throw new vr("Supplied PeerID Multihash is invalid")}function lf(r){return r.code===vt.code}function hf(r){return r.code===ee.code}function he(r,t){let e={[Symbol.iterator]:()=>e,next:()=>{let n=r.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return e}function Qr(r){let t=Vt(F.decode(`z${r}`));return lr(t)}var hr=class{map;constructor(t){if(this.map=new Map,t!=null)for(let[e,n]of t.entries())this.map.set(e.toString(),{key:e,value:n})}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(t){return this.map.delete(t.toString())}entries(){return he(this.map.entries(),t=>[t[1].key,t[1].value])}forEach(t){this.map.forEach((e,n)=>{t(e.value,e.key,this)})}get(t){return this.map.get(t.toString())?.value}has(t){return this.map.has(t.toString())}set(t,e){this.map.set(t.toString(),{key:t,value:e})}keys(){return he(this.map.values(),t=>t.key)}values(){return he(this.map.values(),t=>t.value)}get size(){return this.map.size}};var dr=class r{set;constructor(t){if(this.set=new Set,t!=null)for(let e of t)this.set.add(e.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(t){this.set.add(t.toString())}clear(){this.set.clear()}delete(t){this.set.delete(t.toString())}entries(){return he(this.set.entries(),t=>{let e=Qr(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=Qr(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return he(this.set.values(),t=>Qr(t))}intersection(t){let e=new r;for(let n of t)this.has(n)&&e.add(n);return e}difference(t){let e=new r;for(let n of this)t.has(n)||e.add(n);return e}union(t){let e=new r;for(let n of t)e.add(n);for(let n of this)e.add(n);return e}};function Ht(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var tn=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},Ue=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new tn(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new tn(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var Yo=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function en(r={}){return df(e=>{let n=e.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function df(r,t){t=t??{};let e=t.onEnd,n=new Ue,o,s,i,a=Ht(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((d,S)=>{s=L=>{s=null,n.push(L);try{d(r(n))}catch(A){S(A)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Ht()})}},l=d=>s!=null?s(d):(n.push(d),o),u=d=>(n=new Ue,s!=null?s({error:d}):(n.push({error:d}),o)),f=d=>{if(i)return o;if(t?.objectMode!==!0&&d?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:d})},b=d=>i?o:(i=!0,d!=null?u(d):l({done:!0})),p=()=>(n=new Ue,b(),{done:!0}),v=d=>(b(d),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:p,throw:v,push:f,end:b,get readableLength(){return n.size},onEmpty:async d=>{let S=d?.signal;if(S?.throwIfAborted(),n.isEmpty())return;let L,A;S!=null&&(L=new Promise((C,y)=>{A=()=>{y(new Yo)},S.addEventListener("abort",A)}));try{await Promise.race([a.promise,L])}finally{A!=null&&S!=null&&S?.removeEventListener("abort",A)}}},e==null)return o;let w=o;return o={[Symbol.asyncIterator](){return this},next(){return w.next()},throw(d){return w.throw(d),e!=null&&(e(d),e=void 0),{done:!0}},return(){return w.return(),e!=null&&(e(),e=void 0),{done:!0}},push:f,end(d){return w.end(d),e!=null&&(e(d),e=void 0),o},get readableLength(){return w.readableLength},onEmpty:d=>w.onEmpty(d)},o}var rn=class extends Error{type;code;constructor(t,e,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=e??"ABORT_ERR"}};async function na(r,t,e){if(t==null)return r;if(t.aborted)return r.catch(()=>{}),Promise.reject(new rn(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new rn(e?.errorMessage,e?.errorCode,e?.errorName);try{return await Promise.race([r,new Promise((s,i)=>{n=()=>{i(o)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var Wo=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=Ht(),this.haveNext=Ht()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let t=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=Ht(),t}async throw(t){return this.ended=!0,this.error=t,t!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(t)),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return this.ended=!0,this.nextResult=t,this.haveNext.resolve(),t}async push(t,e){await this._push(t,e)}async end(t,e){t!=null?await this.throw(t):await this._push(void 0,e)}async _push(t,e){if(t!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=Ht(),await na(this.readNext.promise,e?.signal,e)}};function oa(){return new Wo}function pf(r){return r[Symbol.asyncIterator]!=null}async function mf(r,t,e){try{await Promise.all(r.map(async n=>{for await(let o of n)await t.push(o,{signal:e}),e.throwIfAborted()})),await t.end(void 0,{signal:e})}catch(n){await t.end(n,{signal:e}).catch(()=>{})}}async function*yf(r){let t=new AbortController,e=oa();mf(r,e,t.signal).catch(()=>{});try{yield*e}finally{t.abort()}}function*bf(r){for(let t of r)yield*t}function gf(...r){let t=[];for(let e of r)pf(e)||t.push(e);return t.length===r.length?bf(t):yf(r)}var sa=gf;function pr(r,...t){if(r==null)throw new Error("Empty pipeline");if(Xo(r)){let n=r;r=()=>n.source}else if(aa(r)||ia(r)){let n=r;r=()=>n}let e=[r,...t];if(e.length>1&&Xo(e[e.length-1])&&(e[e.length-1]=e[e.length-1].sink),e.length>2)for(let n=1;n<e.length-1;n++)Xo(e[n])&&(e[n]=wf(e[n]));return xf(...e)}var xf=(...r)=>{let t;for(;r.length>0;)t=r.shift()(t);return t},ia=r=>r?.[Symbol.asyncIterator]!=null,aa=r=>r?.[Symbol.iterator]!=null,Xo=r=>r==null?!1:r.sink!=null&&r.source!=null,wf=r=>t=>{let e=r.sink(t);if(e?.then!=null){let n=en({objectMode:!0});e.then(()=>{n.end()},i=>{n.end(i)});let o,s=r.source;if(ia(s))o=async function*(){yield*s,n.end()};else if(aa(s))o=function*(){yield*s,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return sa(n,o())}return r.source};var Qo=Da(ua(),1);var yr=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},ts=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},fa=r=>globalThis.DOMException===void 0?new ts(r):new DOMException(r),la=r=>{let t=r.reason===void 0?fa("This operation was aborted."):r.reason;return t instanceof Error?t:fa(t)};function es(r,t){let{milliseconds:e,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=t,i,a,l=new Promise((u,f)=>{if(typeof e!="number"||Math.sign(e)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${e}\``);if(t.signal){let{signal:p}=t;p.aborted&&f(la(p)),a=()=>{f(la(p))},p.addEventListener("abort",a,{once:!0})}if(e===Number.POSITIVE_INFINITY){r.then(u,f);return}let b=new yr;i=s.setTimeout.call(void 0,()=>{if(n){try{u(n())}catch(p){f(p)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?u():o instanceof Error?f(o):(b.message=o??`Promise timed out after ${e} milliseconds`,f(b))},e),(async()=>{try{u(await r)}catch(p){f(p)}})()}).finally(()=>{l.clear(),a&&t.signal&&t.signal.removeEventListener("abort",a)});return l.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},l}function rs(r,t,e){let n=0,o=r.length;for(;o>0;){let s=Math.trunc(o/2),i=n+s;e(r[i],t)<=0?(n=++i,o-=s+1):o=s}return n}var br=class{#t=[];enqueue(t,e){e={priority:0,...e};let n={priority:e.priority,id:e.id,run:t};if(this.size===0||this.#t[this.size-1].priority>=e.priority){this.#t.push(n);return}let o=rs(this.#t,n,(s,i)=>i.priority-s.priority);this.#t.splice(o,0,n)}setPriority(t,e){let n=this.#t.findIndex(s=>s.id===t);if(n===-1)throw new ReferenceError(`No promise function with the id "${t}" exists in the queue.`);let[o]=this.#t.splice(n,1);this.enqueue(o.run,{priority:e,id:t})}dequeue(){return this.#t.shift()?.run}filter(t){return this.#t.filter(e=>e.priority===t.priority).map(e=>e.run)}get size(){return this.#t.length}};var gr=class extends Qo.default{#t;#i;#s=0;#d;#a;#p=0;#r;#c;#e;#m;#n=0;#u;#o;#y;#x=1n;timeout;constructor(t){if(super(),t={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:br,...t},!(typeof t.intervalCap=="number"&&t.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${t.intervalCap?.toString()??""}\` (${typeof t.intervalCap})`);if(t.interval===void 0||!(Number.isFinite(t.interval)&&t.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${t.interval?.toString()??""}\` (${typeof t.interval})`);this.#t=t.carryoverConcurrencyCount,this.#i=t.intervalCap===Number.POSITIVE_INFINITY||t.interval===0,this.#d=t.intervalCap,this.#a=t.interval,this.#e=new t.queueClass,this.#m=t.queueClass,this.concurrency=t.concurrency,this.timeout=t.timeout,this.#y=t.throwOnTimeout===!0,this.#o=t.autoStart===!1}get#w(){return this.#i||this.#s<this.#d}get#E(){return this.#n<this.#u}#S(){this.#n--,this.#f(),this.emit("next")}#v(){this.#g(),this.#b(),this.#c=void 0}get#A(){let t=Date.now();if(this.#r===void 0){let e=this.#p-t;if(e<0)this.#s=this.#t?this.#n:0;else return this.#c===void 0&&(this.#c=setTimeout(()=>{this.#v()},e)),!0}return!1}#f(){if(this.#e.size===0)return this.#r&&clearInterval(this.#r),this.#r=void 0,this.emit("empty"),this.#n===0&&this.emit("idle"),!1;if(!this.#o){let t=!this.#A;if(this.#w&&this.#E){let e=this.#e.dequeue();return e?(this.emit("active"),e(),t&&this.#b(),!0):!1}}return!1}#b(){this.#i||this.#r!==void 0||(this.#r=setInterval(()=>{this.#g()},this.#a),this.#p=Date.now()+this.#a)}#g(){this.#s===0&&this.#n===0&&this.#r&&(clearInterval(this.#r),this.#r=void 0),this.#s=this.#t?this.#n:0,this.#l()}#l(){for(;this.#f(););}get concurrency(){return this.#u}set concurrency(t){if(!(typeof t=="number"&&t>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${t}\` (${typeof t})`);this.#u=t,this.#l()}async#I(t){return new Promise((e,n)=>{t.addEventListener("abort",()=>{n(t.reason)},{once:!0})})}setPriority(t,e){this.#e.setPriority(t,e)}async add(t,e={}){return e.id??=(this.#x++).toString(),e={timeout:this.timeout,throwOnTimeout:this.#y,...e},new Promise((n,o)=>{this.#e.enqueue(async()=>{this.#n++,this.#s++;try{e.signal?.throwIfAborted();let s=t({signal:e.signal});e.timeout&&(s=es(Promise.resolve(s),{milliseconds:e.timeout})),e.signal&&(s=Promise.race([s,this.#I(e.signal)]));let i=await s;n(i),this.emit("completed",i)}catch(s){if(s instanceof yr&&!e.throwOnTimeout){n();return}o(s),this.emit("error",s)}finally{this.#S()}},e),this.emit("add"),this.#f()})}async addAll(t,e){return Promise.all(t.map(async n=>this.add(n,e)))}start(){return this.#o?(this.#o=!1,this.#l(),this):this}pause(){this.#o=!0}clear(){this.#e=new this.#m}async onEmpty(){this.#e.size!==0&&await this.#h("empty")}async onSizeLessThan(t){this.#e.size<t||await this.#h("next",()=>this.#e.size<t)}async onIdle(){this.#n===0&&this.#e.size===0||await this.#h("idle")}async#h(t,e){return new Promise(n=>{let o=()=>{e&&!e()||(this.off(t,o),n())};this.on(t,o)})}get size(){return this.#e.size}sizeBy(t){return this.#e.filter(t).length}get pending(){return this.#n}get isPaused(){return this.#o}};function ha(r){if(r!=null){if(typeof r[Symbol.iterator]=="function")return r[Symbol.iterator]();if(typeof r[Symbol.asyncIterator]=="function")return r[Symbol.asyncIterator]();if(typeof r.next=="function")return r}throw new Error("argument is not an iterator or iterable")}function da(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function pa(r,t){let e=ha(r).return?.();da(e)&&e.catch(n=>{t.error("could not cause iterator to return",n)})}var on=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Me=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},sn=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},xr=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function an(r){return r[Symbol.asyncIterator]!=null}function ma(r,t){if(r.byteLength>t)throw new Me("Message length too long")}var un=r=>{let t=Bt(r),e=nt(t);return Bi(r,e),un.bytes=t,e};un.bytes=0;function fn(r,t){t=t??{};let e=t.lengthEncoder??un,n=t?.maxDataLength??4194304;function*o(s){ma(s,n);let i=e(s.byteLength);i instanceof Uint8Array?yield i:yield*i,s instanceof Uint8Array?yield s:yield*s}return an(r)?async function*(){for await(let s of r)yield*o(s)}():function*(){for(let s of r)yield*o(s)}()}fn.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??un,n=t?.maxDataLength??4194304;return ma(r,n),new X(e(r.byteLength),r)};var de;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(de||(de={}));var ns=r=>{let t=_i(r);return ns.bytes=Bt(t),t};ns.bytes=0;function wr(r,t){let e=new X,n=de.LENGTH,o=-1,s=t?.lengthDecoder??ns,i=t?.maxLengthLength??8,a=t?.maxDataLength??4194304;function*c(){for(;e.byteLength>0;){if(n===de.LENGTH)try{if(o=s(e),o<0)throw new on("Invalid message length");if(o>a)throw new Me("Message length too long");let l=s.bytes;e.consume(l),t?.onLength!=null&&t.onLength(o),n=de.DATA}catch(l){if(l instanceof RangeError){if(e.byteLength>i)throw new sn("Message length length too long");break}throw l}if(n===de.DATA){if(e.byteLength<o)break;let l=e.sublist(0,o);e.consume(o),t?.onData!=null&&t.onData(l),yield l,n=de.LENGTH}}}return an(r)?async function*(){for await(let l of r)e.append(l),yield*c();if(e.byteLength>0)throw new xr("Unexpected end of input")}():function*(){for(let l of r)e.append(l),yield*c();if(e.byteLength>0)throw new xr("Unexpected end of input")}()}wr.fromReader=(r,t)=>{let e=1,n=async function*(){for(;;)try{let{done:s,value:i}=await r.next(e);if(s===!0)return;i!=null&&(yield i)}catch(s){if(s.code==="ERR_UNDER_READ")return{done:!0,value:null};throw s}finally{e=1}}();return wr(n,{...t??{},onLength:s=>{e=s}})};var ln=class extends ge{id;protocol;outboundStream;inboundStream;_rawOutboundStream;_rawInboundStream;_inboundAbortController;closed;log;constructor(t,e){super(),this.log=t.logger.forComponent("libp2p-pubsub:peer-streams"),this.id=e.id,this.protocol=e.protocol,this._inboundAbortController=new AbortController,this.closed=!1}get isReadable(){return!!this.inboundStream}get isWritable(){return!!this.outboundStream}write(t){if(this.outboundStream==null){let e=this.id.toString();throw new Error("No writable connection to "+e)}this.outboundStream.push(t instanceof Uint8Array?new X(t):t)}attachInboundStream(t,e){let n=()=>{pa(t.source,this.log)};return this._inboundAbortController.signal.addEventListener("abort",n,{once:!0}),this._rawInboundStream=t,this.inboundStream=pr(this._rawInboundStream,o=>wr(o,e)),this.dispatchEvent(new CustomEvent("stream:inbound")),this.inboundStream}async attachOutboundStream(t){let e=this.outboundStream;return this.outboundStream!=null&&this.outboundStream.end(),this._rawOutboundStream=t,this.outboundStream=en({onEnd:n=>{this._rawOutboundStream?.closeWrite().catch(o=>{this.log("error closing outbound stream",o)}),this._rawOutboundStream=void 0,this.outboundStream=void 0,n!=null&&this.dispatchEvent(new CustomEvent("close"))}}),pr(this.outboundStream,n=>fn(n),this._rawOutboundStream).catch(n=>{this.log.error(n)}),e==null&&this.dispatchEvent(new CustomEvent("stream:outbound")),this.outboundStream}close(){this.closed||(this.closed=!0,this.outboundStream!=null&&this.outboundStream.end(),this.inboundStream!=null&&this._inboundAbortController.abort(),this._rawOutboundStream=void 0,this.outboundStream=void 0,this._rawInboundStream=void 0,this.inboundStream=void 0,this.dispatchEvent(new CustomEvent("close")))}};function ya(){return BigInt(`0x${M(Zr(8),"base16")}`)}var ba=(r,t)=>{let e=O(t.toString(16).padStart(16,"0"),"base16"),n=Kt(r),o=new Uint8Array(n.byteLength+e.length);return o.set(n,0),o.set(e,n.byteLength),o},ga=r=>ee.encode(r);var xa=function(r){return Array.isArray(r)?r:[r]},If=async r=>{if(r.sequenceNumber==null||r.from==null||r.signature==null)return!1;let t=lr(Vt(r.from));if(t.publicKey!=null)return!0;if(r.key!=null){let e=r.key;return jo($o(e)).equals(t)}return!1},wa=async r=>{if(r.from==null)throw new j("RPC message was missing from");if(!await If(r))return{type:"unsigned",topic:r.topic??"",data:r.data??new Uint8Array(0)};let t=lr(Vt(r.from)),e=r.key??t.publicKey;if(e==null)throw new j("RPC message was missing public key");return{type:"signed",from:t,topic:r.topic??"",sequenceNumber:_f(r.sequenceNumber??new Uint8Array(0)),data:r.data??new Uint8Array(0),signature:r.signature??new Uint8Array(0),key:e instanceof Uint8Array?$o(e):e}},Er=r=>r.type==="signed"?{from:r.from.toMultihash().bytes,data:r.data,sequenceNumber:Bf(r.sequenceNumber),topic:r.topic,signature:r.signature,key:r.key?Kt(r.key):void 0}:{data:r.data,topic:r.topic},Bf=r=>{let t=r.toString(16);return t.length%2!==0&&(t=`0${t}`),O(t,"base16")},_f=r=>BigInt(`0x${M(r,"base16")}`);var Ea=O("libp2p-pubsub:");async function Sa(r,t,e){let n={type:"signed",topic:t.topic,data:t.data,sequenceNumber:t.sequenceNumber,from:ra(r)},o=te([Ea,e(Er(n)).subarray()]);return n.signature=await r.sign(o),n.key=r.publicKey,n}async function va(r,t){if(r.type!=="signed")throw new Error('Message type must be "signed" to be verified');if(r.signature==null)throw new Error("Message must contain a signature to be verified");if(r.from==null)throw new Error("Message must contain a from property to be verified");let e=te([Ea,t({...Er(r),signature:void 0,key:void 0}).subarray()]);return Lf(r).verify(e,r.signature)}function Lf(r){if(r.type!=="signed")throw new Error('Message type must be "signed" to have a public key');if(r.from==null)throw new Error("Could not get the public key from the originator id");if(r.key!=null)return r.key;if(r.from.publicKey!=null)return r.from.publicKey;throw new Error("Could not get the public key from the originator id")}var hn=class extends ge{log;started;topics;subscriptions;peers;globalSignaturePolicy;canRelayMessage;emitSelf;topicValidators;queue;multicodecs;components;_registrarTopologyIds;enabled;maxInboundStreams;maxOutboundStreams;constructor(t,e){super();let{multicodecs:n=[],globalSignaturePolicy:o="StrictSign",canRelayMessage:s=!1,emitSelf:i=!1,messageProcessingConcurrency:a=10,maxInboundStreams:c=1,maxOutboundStreams:l=1}=e;this.log=t.logger.forComponent("libp2p:pubsub"),this.components=t,this.multicodecs=xa(n),this.enabled=e.enabled!==!1,this.started=!1,this.topics=new Map,this.subscriptions=new Set,this.peers=new hr,this.globalSignaturePolicy=o==="StrictNoSign"?"StrictNoSign":"StrictSign",this.canRelayMessage=s,this.emitSelf=i,this.topicValidators=new Map,this.queue=new gr({concurrency:a}),this.maxInboundStreams=c,this.maxOutboundStreams=l,this._onIncomingStream=this._onIncomingStream.bind(this),this._onPeerConnected=this._onPeerConnected.bind(this),this._onPeerDisconnected=this._onPeerDisconnected.bind(this)}async start(){if(this.started||!this.enabled)return;this.log("starting");let t=this.components.registrar;await Promise.all(this.multicodecs.map(async n=>{await t.handle(n,this._onIncomingStream,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams})}));let e={onConnect:this._onPeerConnected,onDisconnect:this._onPeerDisconnected};this._registrarTopologyIds=await Promise.all(this.multicodecs.map(async n=>t.register(n,e))),this.log("started"),this.started=!0}async stop(){if(!this.started||!this.enabled)return;let t=this.components.registrar;this._registrarTopologyIds!=null&&this._registrarTopologyIds?.forEach(e=>{t.unregister(e)}),await Promise.all(this.multicodecs.map(async e=>{await t.unhandle(e)})),this.log("stopping");for(let e of this.peers.values())e.close();this.peers.clear(),this.subscriptions=new Set,this.started=!1,this.log("stopped")}isStarted(){return this.started}_onIncomingStream(t){let{stream:e,connection:n}=t,o=n.remotePeer;if(e.protocol==null){e.abort(new Error("Stream was not multiplexed"));return}let s=this.addPeer(o,e.protocol),i=s.attachInboundStream(e);this.processMessages(o,i,s).catch(a=>{this.log(a)})}_onPeerConnected(t,e){if(this.log("connected %p",t),e.streams.find(n=>n.direction==="outbound"&&n.protocol!=null&&this.multicodecs.includes(n.protocol))!=null){this.log("outbound pubsub streams already present on connection from %p",t);return}Promise.resolve().then(async()=>{try{let n=await e.newStream(this.multicodecs);if(n.protocol==null){n.abort(new Error("Stream was not multiplexed"));return}await this.addPeer(t,n.protocol).attachOutboundStream(n)}catch(n){this.log.error(n)}this.send(t,{subscriptions:Array.from(this.subscriptions).map(n=>n.toString()),subscribe:!0})}).catch(n=>{this.log.error(n)})}_onPeerDisconnected(t,e){this.log("connection ended %p",t),this._removePeer(t)}addPeer(t,e){let n=this.peers.get(t);if(n!=null)return n;this.log("new peer %p",t);let o=new ln(this.components,{id:t,protocol:e});return this.peers.set(t,o),o.addEventListener("close",()=>this._removePeer(t),{once:!0}),o}_removePeer(t){let e=this.peers.get(t);if(e!=null){e.close(),this.log("delete peer %p",t),this.peers.delete(t);for(let n of this.topics.values())n.delete(t);return e}}async processMessages(t,e,n){try{await pr(e,async o=>{for await(let s of o){let i=this.decodeRpc(s),a=[];for(let c of i.messages??[]){if(c.from==null||c.data==null||c.topic==null){this.log("message from %p was missing from, data or topic fields, dropping",t);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(t,n,{subscriptions:(i.subscriptions??[]).map(c=>({subscribe:!!c.subscribe,topic:c.topic??""})),messages:a}).catch(c=>{this.log(c)})}})}catch(o){this._onPeerDisconnected(n.id,o)}}async processRpc(t,e,n){if(!this.acceptFrom(t))return this.log("received message from unacceptable peer %p",t),!1;this.log("rpc from %p",t);let{subscriptions:o,messages:s}=n;return o!=null&&o.length>0&&(this.log("subscription update from %p",t),o.forEach(i=>{this.processRpcSubOpt(t,i)}),super.dispatchEvent(new CustomEvent("subscription-change",{detail:{peerId:e.id,subscriptions:o.map(({topic:i,subscribe:a})=>({topic:`${i??""}`,subscribe:!!a}))}}))),s!=null&&s.length>0&&(this.log("messages from %p",t),this.queue.addAll(s.map(i=>async()=>{if(i.topic==null||!this.subscriptions.has(i.topic)&&!this.canRelayMessage)return this.log("received message we didn't subscribe to. Dropping."),!1;try{let a=await wa(i);await this.processMessage(t,a)}catch(a){this.log.error(a)}})).catch(i=>{this.log(i)})),!0}processRpcSubOpt(t,e){let n=e.topic;if(n==null)return;let o=this.topics.get(n);o==null&&(o=new dr,this.topics.set(n,o)),e.subscribe===!0?o.add(t):o.delete(t)}async processMessage(t,e){if(!(this.components.peerId.equals(t)&&!this.emitSelf)){try{await this.validate(t,e)}catch(n){this.log("Message is invalid, dropping it. %O",n);return}this.subscriptions.has(e.topic)&&(!this.components.peerId.equals(t)||this.emitSelf)&&super.dispatchEvent(new CustomEvent("message",{detail:e})),await this.publishMessage(t,e)}}getMsgId(t){switch(this.globalSignaturePolicy){case"StrictSign":if(t.type!=="signed")throw new j('Message type should be "signed" when signature policy is StrictSign but it was not');if(t.sequenceNumber==null)throw new j("Need sequence number when signature policy is StrictSign but it was missing");if(t.key==null)throw new j("Need key when signature policy is StrictSign but it was missing");return ba(t.key,t.sequenceNumber);case"StrictNoSign":return ga(t.data);default:throw new j("Cannot get message id: unhandled signature policy")}}acceptFrom(t){return!0}send(t,e){let{messages:n,subscriptions:o,subscribe:s}=e;this.sendRpc(t,{subscriptions:(o??[]).map(i=>({topic:i,subscribe:!!s})),messages:(n??[]).map(Er)})}sendRpc(t,e){let n=this.peers.get(t);if(n==null){this.log.error("Cannot send RPC to %p as there are no streams to it available",t);return}if(!n.isWritable){this.log.error("Cannot send RPC to %p as there is no outbound stream to it available",t);return}n.write(this.encodeRpc(e))}async validate(t,e){switch(this.globalSignaturePolicy){case"StrictNoSign":if(e.type!=="unsigned")throw new j('Message type should be "unsigned" when signature policy is StrictNoSign but it was not');if(e.signature!=null)throw new j("StrictNoSigning: signature should not be present");if(e.key!=null)throw new j("StrictNoSigning: key should not be present");if(e.sequenceNumber!=null)throw new j("StrictNoSigning: seqno should not be present");break;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.signature==null)throw new j("StrictSigning: Signing required and no signature was present");if(e.sequenceNumber==null)throw new j("StrictSigning: Signing required and no sequenceNumber was present");if(!await va(e,this.encodeMessage.bind(this)))throw new j("StrictSigning: Invalid message signature");break;default:throw new j("Cannot validate message: unhandled signature policy")}let o=this.topicValidators.get(e.topic);if(o!=null){let s=await o(t,e);if(s===qe.Reject||s===qe.Ignore)throw new j("Message validation failed")}}async buildMessage(t){switch(this.globalSignaturePolicy){case"StrictSign":return Sa(this.components.privateKey,t,this.encodeMessage.bind(this));case"StrictNoSign":return Promise.resolve({type:"unsigned",...t});default:throw new j("Cannot build message: unhandled signature policy")}}getSubscribers(t){if(!this.started)throw new Ar("not started yet");if(t==null)throw new V("Topic is required");let e=this.topics.get(t.toString());return e==null?[]:Array.from(e.values())}async publish(t,e){if(!this.started)throw new Error("Pubsub has not started");let n={from:this.components.peerId,topic:t,data:e??new Uint8Array(0),sequenceNumber:ya()};this.log("publish topic: %s from: %p data: %m",t,n.from,n.data);let o=await this.buildMessage(n),s=!1;this.emitSelf&&this.subscriptions.has(t)&&(s=!0,super.dispatchEvent(new CustomEvent("message",{detail:o})));let i=await this.publishMessage(this.components.peerId,o);return s&&(i.recipients=[...i.recipients,this.components.peerId]),i}subscribe(t){if(!this.started)throw new Error("Pubsub has not started");if(this.log("subscribe to topic: %s",t),!this.subscriptions.has(t)){this.subscriptions.add(t);for(let e of this.peers.keys())this.send(e,{subscriptions:[t],subscribe:!0})}}unsubscribe(t){if(!this.started)throw new Error("Pubsub is not started");super.removeEventListener(t);let e=this.subscriptions.has(t);if(this.log("unsubscribe from %s - am subscribed %s",t,e),e){this.subscriptions.delete(t);for(let n of this.peers.keys())this.send(n,{subscriptions:[t],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 dn=class{entries;validityMs;lastPruneTime=0;constructor(t){this.entries=new Map,this.validityMs=t.validityMs}put(t,e){this.entries.set(t,{value:e,validUntilMs:Date.now()+this.validityMs}),this.prune()}prune(){let t=Date.now();if(!(t-this.lastPruneTime<200)){this.lastPruneTime=t;for(let[e,n]of this.entries.entries())if(n.validUntilMs<t)this.entries.delete(e);else break}}has(t){return this.entries.has(t)}get(t){let e=this.entries.get(t);return e!=null&&e.validUntilMs>=Date.now()?e.value:void 0}clear(){this.entries=new Map,this.lastPruneTime=0}};var os="/floodsub/1.0.0";var pe;(function(r){let t;(function(o){let s;o.codec=()=>(s==null&&(s=bt((i,a,c={})=>{c.lengthDelimited!==!1&&a.fork(),i.subscribe!=null&&(a.uint32(8),a.bool(i.subscribe)),i.topic!=null&&(a.uint32(18),a.string(i.topic)),c.lengthDelimited!==!1&&a.ldelim()},(i,a,c={})=>{let l={},u=a==null?i.len:i.pos+a;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{l.subscribe=i.bool();break}case 2:{l.topic=i.string();break}default:{i.skipType(f&7);break}}}return l})),s),o.encode=i=>yt(i,o.codec()),o.decode=(i,a)=>mt(i,o.codec(),a)})(t=r.SubOpts||(r.SubOpts={}));let e;(function(o){let s;o.codec=()=>(s==null&&(s=bt((i,a,c={})=>{c.lengthDelimited!==!1&&a.fork(),i.from!=null&&(a.uint32(10),a.bytes(i.from)),i.data!=null&&(a.uint32(18),a.bytes(i.data)),i.sequenceNumber!=null&&(a.uint32(26),a.bytes(i.sequenceNumber)),i.topic!=null&&(a.uint32(34),a.string(i.topic)),i.signature!=null&&(a.uint32(42),a.bytes(i.signature)),i.key!=null&&(a.uint32(50),a.bytes(i.key)),c.lengthDelimited!==!1&&a.ldelim()},(i,a,c={})=>{let l={},u=a==null?i.len:i.pos+a;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{l.from=i.bytes();break}case 2:{l.data=i.bytes();break}case 3:{l.sequenceNumber=i.bytes();break}case 4:{l.topic=i.string();break}case 5:{l.signature=i.bytes();break}case 6:{l.key=i.bytes();break}default:{i.skipType(f&7);break}}}return l})),s),o.encode=i=>yt(i,o.codec()),o.decode=(i,a)=>mt(i,o.codec(),a)})(e=r.Message||(r.Message={}));let n;r.codec=()=>(n==null&&(n=bt((o,s,i={})=>{if(i.lengthDelimited!==!1&&s.fork(),o.subscriptions!=null)for(let a of o.subscriptions)s.uint32(10),r.SubOpts.codec().encode(a,s);if(o.messages!=null)for(let a of o.messages)s.uint32(18),r.Message.codec().encode(a,s);o.control!=null&&(s.uint32(26),pn.codec().encode(o.control,s)),i.lengthDelimited!==!1&&s.ldelim()},(o,s,i={})=>{let a={subscriptions:[],messages:[]},c=s==null?o.len:o.pos+s;for(;o.pos<c;){let l=o.uint32();switch(l>>>3){case 1:{if(i.limits?.subscriptions!=null&&a.subscriptions.length===i.limits.subscriptions)throw new Et('Decode error - map field "subscriptions" had too many elements');a.subscriptions.push(r.SubOpts.codec().decode(o,o.uint32(),{limits:i.limits?.subscriptions$}));break}case 2:{if(i.limits?.messages!=null&&a.messages.length===i.limits.messages)throw new Et('Decode error - map field "messages" had too many elements');a.messages.push(r.Message.codec().decode(o,o.uint32(),{limits:i.limits?.messages$}));break}case 3:{a.control=pn.codec().decode(o,o.uint32(),{limits:i.limits?.control});break}default:{o.skipType(l&7);break}}}return a})),n),r.encode=o=>yt(o,r.codec()),r.decode=(o,s)=>mt(o,r.codec(),s)})(pe||(pe={}));var pn;(function(r){let t;r.codec=()=>(t==null&&(t=bt((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.ihave!=null)for(let s of e.ihave)n.uint32(10),mn.codec().encode(s,n);if(e.iwant!=null)for(let s of e.iwant)n.uint32(18),yn.codec().encode(s,n);if(e.graft!=null)for(let s of e.graft)n.uint32(26),bn.codec().encode(s,n);if(e.prune!=null)for(let s of e.prune)n.uint32(34),gn.codec().encode(s,n);o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={ihave:[],iwant:[],graft:[],prune:[]},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{if(o.limits?.ihave!=null&&s.ihave.length===o.limits.ihave)throw new Et('Decode error - map field "ihave" had too many elements');s.ihave.push(mn.codec().decode(e,e.uint32(),{limits:o.limits?.ihave$}));break}case 2:{if(o.limits?.iwant!=null&&s.iwant.length===o.limits.iwant)throw new Et('Decode error - map field "iwant" had too many elements');s.iwant.push(yn.codec().decode(e,e.uint32(),{limits:o.limits?.iwant$}));break}case 3:{if(o.limits?.graft!=null&&s.graft.length===o.limits.graft)throw new Et('Decode error - map field "graft" had too many elements');s.graft.push(bn.codec().decode(e,e.uint32(),{limits:o.limits?.graft$}));break}case 4:{if(o.limits?.prune!=null&&s.prune.length===o.limits.prune)throw new Et('Decode error - map field "prune" had too many elements');s.prune.push(gn.codec().decode(e,e.uint32(),{limits:o.limits?.prune$}));break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>yt(e,r.codec()),r.decode=(e,n)=>mt(e,r.codec(),n)})(pn||(pn={}));var mn;(function(r){let t;r.codec=()=>(t==null&&(t=bt((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.topic!=null&&(n.uint32(10),n.string(e.topic)),e.messageIDs!=null)for(let s of e.messageIDs)n.uint32(18),n.bytes(s);o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={messageIDs:[]},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.topic=e.string();break}case 2:{if(o.limits?.messageIDs!=null&&s.messageIDs.length===o.limits.messageIDs)throw new Et('Decode error - map field "messageIDs" had too many elements');s.messageIDs.push(e.bytes());break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>yt(e,r.codec()),r.decode=(e,n)=>mt(e,r.codec(),n)})(mn||(mn={}));var yn;(function(r){let t;r.codec=()=>(t==null&&(t=bt((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.messageIDs!=null)for(let s of e.messageIDs)n.uint32(10),n.bytes(s);o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={messageIDs:[]},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{if(o.limits?.messageIDs!=null&&s.messageIDs.length===o.limits.messageIDs)throw new Et('Decode error - map field "messageIDs" had too many elements');s.messageIDs.push(e.bytes());break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>yt(e,r.codec()),r.decode=(e,n)=>mt(e,r.codec(),n)})(yn||(yn={}));var bn;(function(r){let t;r.codec=()=>(t==null&&(t=bt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.topic!=null&&(n.uint32(10),n.string(e.topic)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.topic=e.string();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>yt(e,r.codec()),r.decode=(e,n)=>mt(e,r.codec(),n)})(bn||(bn={}));var gn;(function(r){let t;r.codec=()=>(t==null&&(t=bt((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.topic!=null&&(n.uint32(10),n.string(e.topic)),e.peers!=null)for(let s of e.peers)n.uint32(18),xn.codec().encode(s,n);e.backoff!=null&&(n.uint32(24),n.uint64(e.backoff)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={peers:[]},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.topic=e.string();break}case 2:{if(o.limits?.peers!=null&&s.peers.length===o.limits.peers)throw new Et('Decode error - map field "peers" had too many elements');s.peers.push(xn.codec().decode(e,e.uint32(),{limits:o.limits?.peers$}));break}case 3:{s.backoff=e.uint64();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>yt(e,r.codec()),r.decode=(e,n)=>mt(e,r.codec(),n)})(gn||(gn={}));var xn;(function(r){let t;r.codec=()=>(t==null&&(t=bt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.peerID!=null&&(n.uint32(10),n.bytes(e.peerID)),e.signedPeerRecord!=null&&(n.uint32(18),n.bytes(e.signedPeerRecord)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.peerID=e.bytes();break}case 2:{s.signedPeerRecord=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>yt(e,r.codec()),r.decode=(e,n)=>mt(e,r.codec(),n)})(xn||(xn={}));var ss=class extends hn{seenCache;constructor(t,e){super(t,{...e,canRelayMessage:!0,multicodecs:[os]}),this.log=t.logger.forComponent("libp2p:floodsub"),this.seenCache=new dn({validityMs:e?.seenTTL??3e4})}[as]=!0;[Symbol.toStringTag]="@libp2p/floodsub";[cs]=["@libp2p/pubsub"];[us]=["@libp2p/identify"];decodeRpc(t){return pe.decode(t)}encodeRpc(t){return pe.encode(t)}decodeMessage(t){return pe.Message.decode(t)}encodeMessage(t){return pe.Message.encode(t)}async processMessage(t,e){let n=await super.getMsgId(e),o=M(n,"base64");this.seenCache.has(o)||(this.seenCache.put(o,!0),await super.processMessage(t,e))}async publishMessage(t,e){let n=this.getSubscribers(e.topic),o=[];return n==null||n.length===0?(this.log("no peers are subscribed to topic %s",e.topic),{recipients:o}):(n.forEach(s=>{if(this.components.peerId.equals(s)){this.log("not sending message on topic %s to myself",e.topic);return}if(s.equals(t)){this.log("not sending message on topic %s to sender %p",e.topic,s);return}this.log("publish msgs on topics %s %p",e.topic,s),o.push(s),this.send(s,{messages:[e]})}),{recipients:o})}};function Tf(r={}){return t=>new ss(t,r)}return Pa(Df);})();
|
|
2
|
+
"use strict";var Libp2PFloodsub=(()=>{var Fa=Object.create;var Kr=Object.defineProperty;var za=Object.getOwnPropertyDescriptor;var Ga=Object.getOwnPropertyNames;var Za=Object.getPrototypeOf,Ya=Object.prototype.hasOwnProperty;var Xa=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),ht=(r,t)=>{for(var e in t)Kr(r,e,{get:t[e],enumerable:!0})},Is=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ga(t))!Ya.call(r,o)&&o!==e&&Kr(r,o,{get:()=>t[o],enumerable:!(n=za(t,o))||n.enumerable});return r};var $a=(r,t,e)=>(e=r!=null?Fa(Za(r)):{},Is(t||!r||!r.__esModule?Kr(e,"default",{value:r,enumerable:!0}):e,r)),ja=r=>Is(Kr({},"__esModule",{value:!0}),r);var La=Xa((W0,ms)=>{"use strict";var Gf=Object.prototype.hasOwnProperty,lt="~";function Lr(){}Object.create&&(Lr.prototype=Object.create(null),new Lr().__proto__||(lt=!1));function Zf(r,t,e){this.fn=r,this.context=t,this.once=e||!1}function _a(r,t,e,n,o){if(typeof e!="function")throw new TypeError("The listener must be a function");var s=new Zf(e,n||r,o),i=lt?lt+t:t;return r._events[i]?r._events[i].fn?r._events[i]=[r._events[i],s]:r._events[i].push(s):(r._events[i]=s,r._eventsCount++),r}function mn(r,t){--r._eventsCount===0?r._events=new Lr:delete r._events[t]}function ut(){this._events=new Lr,this._eventsCount=0}ut.prototype.eventNames=function(){var t=[],e,n;if(this._eventsCount===0)return t;for(n in e=this._events)Gf.call(e,n)&&t.push(lt?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(e)):t};ut.prototype.listeners=function(t){var e=lt?lt+t:t,n=this._events[e];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,s=n.length,i=new Array(s);o<s;o++)i[o]=n[o].fn;return i};ut.prototype.listenerCount=function(t){var e=lt?lt+t:t,n=this._events[e];return n?n.fn?1:n.length:0};ut.prototype.emit=function(t,e,n,o,s,i){var a=lt?lt+t:t;if(!this._events[a])return!1;var c=this._events[a],u=arguments.length,d,f;if(c.fn){switch(c.once&&this.removeListener(t,c.fn,void 0,!0),u){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,e),!0;case 3:return c.fn.call(c.context,e,n),!0;case 4:return c.fn.call(c.context,e,n,o),!0;case 5:return c.fn.call(c.context,e,n,o,s),!0;case 6:return c.fn.call(c.context,e,n,o,s,i),!0}for(f=1,d=new Array(u-1);f<u;f++)d[f-1]=arguments[f];c.fn.apply(c.context,d)}else{var l=c.length,h;for(f=0;f<l;f++)switch(c[f].once&&this.removeListener(t,c[f].fn,void 0,!0),u){case 1:c[f].fn.call(c[f].context);break;case 2:c[f].fn.call(c[f].context,e);break;case 3:c[f].fn.call(c[f].context,e,n);break;case 4:c[f].fn.call(c[f].context,e,n,o);break;default:if(!d)for(h=1,d=new Array(u-1);h<u;h++)d[h-1]=arguments[h];c[f].fn.apply(c[f].context,d)}}return!0};ut.prototype.on=function(t,e,n){return _a(this,t,e,n,!1)};ut.prototype.once=function(t,e,n){return _a(this,t,e,n,!0)};ut.prototype.removeListener=function(t,e,n,o){var s=lt?lt+t:t;if(!this._events[s])return this;if(!e)return mn(this,s),this;var i=this._events[s];if(i.fn)i.fn===e&&(!o||i.once)&&(!n||i.context===n)&&mn(this,s);else{for(var a=0,c=[],u=i.length;a<u;a++)(i[a].fn!==e||o&&!i[a].once||n&&i[a].context!==n)&&c.push(i[a]);c.length?this._events[s]=c.length===1?c[0]:c:mn(this,s)}return this};ut.prototype.removeAllListeners=function(t){var e;return t?(e=lt?lt+t:t,this._events[e]&&mn(this,e)):(this._events=new Lr,this._eventsCount=0),this};ut.prototype.off=ut.prototype.removeListener;ut.prototype.addListener=ut.prototype.on;ut.prefixed=lt;ut.EventEmitter=ut;typeof ms<"u"&&(ms.exports=ut)});var tl={};ht(tl,{floodsub:()=>Qf,multicodec:()=>Es});var Pn=Symbol.for("@libp2p/peer-id");var Qe;(function(r){r.Accept="accept",r.Ignore="ignore",r.Reject="reject"})(Qe||(Qe={}));var Bs=Symbol.for("@libp2p/pubsub");var Y=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Te=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Rr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var J=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var Ur=class extends Error{static name="NotStartedError";constructor(t="Not started"){super(t),this.name="NotStartedError"}};var he=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var De=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let e=this.#t.get(t);return e==null?0:e.length}addEventListener(t,e,n){super.addEventListener(t,e,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:e,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,e,n){super.removeEventListener(t.toString(),e??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==e),this.#t.set(t,o))}dispatchEvent(t){let e=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),e}safeDispatchEvent(t,e={}){return this.dispatchEvent(new CustomEvent(t,e))}};var _s=Symbol.for("@libp2p/service-capabilities"),Ls=Symbol.for("@libp2p/service-dependencies");var Rn={};ht(Rn,{base58btc:()=>X,base58flickr:()=>nc});var _l=new Uint8Array(0);function Ts(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Kt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function Ds(r){return new TextEncoder().encode(r)}function Ps(r){return new TextDecoder().decode(r)}function Wa(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var a=r.length,c=r.charAt(0),u=Math.log(a)/Math.log(256),d=Math.log(256)/Math.log(a);function f(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var x=0,p=0,S=0,B=g.length;S!==B&&g[S]===0;)S++,x++;for(var v=(B-S)*d+1>>>0,T=new Uint8Array(v);S!==B;){for(var C=g[S],_=0,R=v-1;(C!==0||_<p)&&R!==-1;R--,_++)C+=256*T[R]>>>0,T[R]=C%a>>>0,C=C/a>>>0;if(C!==0)throw new Error("Non-zero carry");p=_,S++}for(var U=v-p;U!==v&&T[U]===0;)U++;for(var D=c.repeat(x);U<v;++U)D+=r.charAt(T[U]);return D}function l(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var x=0;if(g[x]!==" "){for(var p=0,S=0;g[x]===c;)p++,x++;for(var B=(g.length-x)*u+1>>>0,v=new Uint8Array(B);g[x];){var T=e[g.charCodeAt(x)];if(T===255)return;for(var C=0,_=B-1;(T!==0||C<S)&&_!==-1;_--,C++)T+=a*v[_]>>>0,v[_]=T%256>>>0,T=T/256>>>0;if(T!==0)throw new Error("Non-zero carry");S=C,x++}if(g[x]!==" "){for(var R=B-S;R!==B&&v[R]===0;)R++;for(var U=new Uint8Array(p+(B-R)),D=p;R!==B;)U[D++]=v[R++];return U}}}function h(g){var x=l(g);if(x)return x;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:l,decode:h}}var Ja=Wa,Qa=Ja,Cs=Qa;var kn=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Cn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Ns(this,t)}},Nn=class{decoders;constructor(t){this.decoders=t}or(t){return Ns(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Ns(r,t){return new Nn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Kn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new kn(t,e,n),this.decoder=new Cn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Pe({name:r,prefix:t,encode:e,decode:n}){return new Kn(r,t,e,n)}function Qt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Cs(e,r);return Pe({prefix:t,name:r,encode:n,decode:s=>Kt(o(s))})}function tc(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let d=t[r[u]];if(d===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|d,i+=e,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function ec(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function rc(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function $({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=rc(n);return Pe({prefix:t,name:r,encode(s){return ec(s,n,e)},decode(s){return tc(s,o,e,r)}})}var X=Qt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),nc=Qt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Un={};ht(Un,{base32:()=>ke,base32hex:()=>ac,base32hexpad:()=>uc,base32hexpadupper:()=>fc,base32hexupper:()=>cc,base32pad:()=>sc,base32padupper:()=>ic,base32upper:()=>oc,base32z:()=>lc});var ke=$({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),oc=$({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),sc=$({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),ic=$({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ac=$({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),cc=$({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),uc=$({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),fc=$({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),lc=$({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Mn={};ht(Mn,{base36:()=>tr,base36upper:()=>hc});var tr=Qt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),hc=Qt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var dc=Us,Ks=128,pc=127,mc=~pc,yc=Math.pow(2,31);function Us(r,t,e){t=t||[],e=e||0;for(var n=e;r>=yc;)t[e++]=r&255|Ks,r/=128;for(;r&mc;)t[e++]=r&255|Ks,r>>>=7;return t[e]=r|0,Us.bytes=e-n+1,t}var bc=On,gc=128,Rs=127;function On(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw On.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&Rs)<<o:(i&Rs)*Math.pow(2,o),o+=7}while(i>=gc);return On.bytes=s-n,e}var xc=Math.pow(2,7),wc=Math.pow(2,14),Ec=Math.pow(2,21),Sc=Math.pow(2,28),vc=Math.pow(2,35),Ac=Math.pow(2,42),Ic=Math.pow(2,49),Bc=Math.pow(2,56),_c=Math.pow(2,63),Lc=function(r){return r<xc?1:r<wc?2:r<Ec?3:r<Sc?4:r<vc?5:r<Ac?6:r<Ic?7:r<Bc?8:r<_c?9:10},Tc={encode:dc,decode:bc,encodingLength:Lc},Dc=Tc,er=Dc;function rr(r,t=0){return[er.decode(r,t),er.decode.bytes]}function Ce(r,t,e=0){return er.encode(r,t,e),t}function Ne(r){return er.encodingLength(r)}function _t(r,t){let e=t.byteLength,n=Ne(r),o=n+Ne(e),s=new Uint8Array(o+e);return Ce(r,s,0),Ce(e,s,n),s.set(t,o),new Ke(r,e,t,s)}function te(r){let t=Kt(r),[e,n]=rr(t),[o,s]=rr(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Ke(e,o,i,t)}function Ms(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Ts(r.bytes,e.bytes)}}var Ke=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function Os(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return kc(e,qn(r),t??X.encoder);default:return Cc(e,qn(r),t??ke.encoder)}}var qs=new WeakMap;function qn(r){let t=qs.get(r);if(t==null){let e=new Map;return qs.set(r,e),e}return t}var st=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==nr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Nc)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=_t(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&Ms(t.multihash,n.multihash)}toString(t){return Os(this,t)}toJSON(){return{"/":Os(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:s,bytes:i}=e;return new r(n,o,s,i??Hs(n,o,s.bytes))}else if(e[Kc]===!0){let{version:n,multihash:o,code:s}=e,i=te(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==nr)throw new Error(`Version 0 CID must use dag-pb (code: ${nr}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Hs(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,nr,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=Kt(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new Ke(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[f,l]=rr(t.subarray(e));return e+=l,f},o=n(),s=nr;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),c=n(),u=e+c,d=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:d,size:u}}static parse(t,e){let[n,o]=Pc(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return qn(s).set(n,t),s}};function Pc(r,t){switch(r[0]){case"Q":{let e=t??X;return[X.prefix,e.decode(`${X.prefix}${r}`)]}case X.prefix:{let e=t??X;return[X.prefix,e.decode(r)]}case ke.prefix:{let e=t??ke;return[ke.prefix,e.decode(r)]}case tr.prefix:{let e=t??tr;return[tr.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function kc(r,t,e){let{prefix:n}=e;if(n!==X.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function Cc(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var nr=112,Nc=18;function Hs(r,t,e){let n=Ne(r),o=n+Ne(t),s=new Uint8Array(o+e.byteLength);return Ce(r,s,0),Ce(t,s,n),s.set(e,o),s}var Kc=Symbol.for("@ipld/js-cid/CID");var Hn={};ht(Hn,{identity:()=>Lt});var Vs=0,Rc="identity",Fs=Kt;function Uc(r){return _t(Vs,Fs(r))}var Lt={code:Vs,name:Rc,encode:Fs,digest:Uc};function dt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Rt(r=0){return new Uint8Array(r)}function it(r=0){return new Uint8Array(r)}function de(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=it(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var Gs=Symbol.for("@achingbrain/uint8arraylist");function zs(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function Or(r){return!!r?.[Gs]}var et=class r{bufs;length;[Gs]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(Or(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(Or(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=zs(this.bufs,t);return e.buf[e.index]}set(t,e){let n=zs(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(Or(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:o}=this._subList(t,e);return de(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:de(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=[...n],s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let u=t>=a&&t<c,d=e>a&&e<=c;if(u&&d){if(t===a&&e===c){n.push(i);break}let f=t-a;n.push(i.subarray(f,f+(e-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(d){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Or(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let f=0;f<s;f++)i[f]=-1;for(let f=0;f<o;f++)i[n[f]]=f;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,d;for(let f=e;f<=c;f+=d){d=0;for(let l=u;l>=0;l--){let h=this.get(f+l);if(n[l]!==h){d=Math.max(1,l-a[h]);break}}if(d===0)return f}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=it(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=Rt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=Rt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=Rt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=it(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=Rt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=Rt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=Rt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=Rt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=Rt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!dt(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};var Vn={};ht(Vn,{base10:()=>Mc});var Mc=Qt({prefix:"9",name:"base10",alphabet:"0123456789"});var Fn={};ht(Fn,{base16:()=>Oc,base16upper:()=>qc});var Oc=$({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),qc=$({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var zn={};ht(zn,{base2:()=>Hc});var Hc=$({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Gn={};ht(Gn,{base256emoji:()=>Zc});var Zs=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}"),Vc=Zs.reduce((r,t,e)=>(r[e]=t,r),[]),Fc=Zs.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function zc(r){return r.reduce((t,e)=>(t+=Vc[e],t),"")}function Gc(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=Fc[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Zc=Pe({prefix:"\u{1F680}",name:"base256emoji",encode:zc,decode:Gc});var Zn={};ht(Zn,{base64:()=>Yc,base64pad:()=>Xc,base64url:()=>$c,base64urlpad:()=>jc});var Yc=$({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Xc=$({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),$c=$({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),jc=$({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Yn={};ht(Yn,{base8:()=>Wc});var Wc=$({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Xn={};ht(Xn,{identity:()=>Jc});var Jc=Pe({prefix:"\0",name:"identity",encode:r=>Ps(r),decode:r=>Ds(r)});var fh=new TextEncoder,lh=new TextDecoder;var Wn={};ht(Wn,{sha256:()=>pe,sha512:()=>eu});function jn({name:r,code:t,encode:e}){return new $n(r,t,e)}var $n=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?_t(this.code,e):e.then(n=>_t(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Xs(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var pe=jn({name:"sha2-256",code:18,encode:Xs("SHA-256")}),eu=jn({name:"sha2-512",code:19,encode:Xs("SHA-512")});var Jn={...Xn,...zn,...Yn,...Vn,...Fn,...Un,...Mn,...Rn,...Zn,...Gn},vh={...Wn,...Hn};function js(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var $s=js("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Qn=js("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=it(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),ru={utf8:$s,"utf-8":$s,hex:Jn.base16,latin1:Qn,ascii:Qn,binary:Qn,...Jn},qr=ru;function z(r,t="utf8"){let e=qr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function H(r,t="utf8"){let e=qr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var nu=parseInt("11111",2),to=parseInt("10000000",2),ou=parseInt("01111111",2),Ws={0:or,1:or,2:su,3:cu,4:uu,5:au,6:iu,16:or,22:or,48:or};function Ut(r,t={offset:0}){let e=r[t.offset]νif(t.offset++,Ws[e]!=null)return Ws[e](r,t);throw new Error("No decoder for tag "+e)}function sr(r,t){let e=0;if((r[t.offset]&to)===to){let n=r[t.offset]&ou,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=r[t.offset].toString(16).padStart(2,"0");e=parseInt(o,16)}else e=r[t.offset],t.offset++;return e}function or(r,t){sr(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=Ut(r,t);if(n===null)break;e.push(n)}return e}function su(r,t){let e=sr(r,t),n=t.offset,o=t.offset+e,s=[];for(let i=n;i<o;i++)i===n&&r[i]===0||s.push(r[i]);return t.offset+=e,Uint8Array.from(s)}function iu(r,t){let e=sr(r,t),n=t.offset+e,o=r[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let u=r[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let d=0;for(let f=0;f<c.length;f++)d+=c[f]<<f*7;a+=`.${d}`,c=[]}}return a}function au(r,t){return t.offset++,null}function cu(r,t){let e=sr(r,t),n=r[t.offset];t.offset++;let o=r.subarray(t.offset,t.offset+e-1);if(t.offset+=e,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function uu(r,t){let e=sr(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function fu(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new et;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function eo(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=fu(r.byteLength);return new et(Uint8Array.from([t.byteLength|to]),t)}function pt(r){let t=new et,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new et(Uint8Array.from([2]),eo(t),t)}function Hr(r){let t=Uint8Array.from([0]),e=new et(t,r);return new et(Uint8Array.from([3]),eo(e),e)}function re(r,t=48){let e=new et;for(let n of r)e.append(n);return new et(Uint8Array.from([t]),eo(e),e)}async function Js(r,t,e,n){let o=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,e.subarray());return n?.signal?.throwIfAborted(),s}var 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"},ro=32,no=48,oo=66;function so(r){let t=Ut(r);return Qs(t)}function Qs(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===ro*2+1)return n=H(t.subarray(e,e+ro),"base64url"),o=H(t.subarray(e+ro),"base64url"),new Re({...pu,key_ops:["verify"],x:n,y:o});if(t.byteLength===no*2+1)return n=H(t.subarray(e,e+no),"base64url"),o=H(t.subarray(e+no),"base64url"),new Re({...mu,key_ops:["verify"],x:n,y:o});if(t.byteLength===oo*2+1)return n=H(t.subarray(e,e+oo),"base64url"),o=H(t.subarray(e+oo),"base64url"),new Re({...yu,key_ops:["verify"],x:n,y:o});throw new Y(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function ti(r){return re([pt(Uint8Array.from([1])),re([bu(r.crv)],160),re([Hr(new et(Uint8Array.from([4]),z(r.x??"","base64url"),z(r.y??"","base64url")))],161)]).subarray()}function bu(r){if(r==="P-256")return lu;if(r==="P-384")return hu;if(r==="P-521")return du;throw new Y(`Invalid curve ${r}`)}var Re=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=ti(this.jwk)),this._raw}toMultihash(){return Lt.digest(Mt(this))}toCID(){return st.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:dt(this.raw,t.raw)}async verify(t,e,n){return Js(this.jwk,e,t,n)}};var me=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function ye(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function ir(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function j(r,...t){if(!ye(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error("Uint8Array expected of length "+t+", got length="+r.length)}function Vr(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");ir(r.outputLen),ir(r.blockLen)}function Me(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function ri(r,t){j(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}function qt(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function Fr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Tt(r,t){return r<<32-t|r>>>t}var ni=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",gu=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function At(r){if(j(r),ni)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=gu[r[e]];return t}var Ot={_0:48,_9:57,A:65,F:70,a:97,f:102};function ei(r){if(r>=Ot._0&&r<=Ot._9)return r-Ot._0;if(r>=Ot.A&&r<=Ot.F)return r-(Ot.A-10);if(r>=Ot.a&&r<=Ot.f)return r-(Ot.a-10)}function be(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(ni)return Uint8Array.fromHex(r);let t=r.length,e=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,s=0;o<e;o++,s+=2){let i=ei(r.charCodeAt(s)),a=ei(r.charCodeAt(s+1));if(i===void 0||a===void 0){let c=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function io(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function ar(r){return typeof r=="string"&&(r=io(r)),j(r),r}function mt(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];j(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}var Ue=class{};function ao(r){let t=n=>r().update(ar(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function ge(r=32){if(me&&typeof me.getRandomValues=="function")return me.getRandomValues(new Uint8Array(r));if(me&&typeof me.randomBytes=="function")return Uint8Array.from(me.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function xu(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(e>>o&s),a=Number(e&s),c=n?4:0,u=n?0:4;r.setUint32(t+c,i,n),r.setUint32(t+u,a,n)}function oi(r,t,e){return r&t^~r&e}function si(r,t,e){return r&t^r&e^t&e}var cr=class extends Ue{constructor(t,e,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=Fr(this.buffer)}update(t){Me(this),t=ar(t),j(t);let{view:e,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=Fr(t);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Me(this),ri(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,qt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let f=i;f<o;f++)e[f]=0;xu(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=Fr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,d=this.get();if(u>d.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)a.setUint32(4*f,d[f],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Ht=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ot=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var zr=BigInt(4294967295),ii=BigInt(32);function wu(r,t=!1){return t?{h:Number(r&zr),l:Number(r>>ii&zr)}:{h:Number(r>>ii&zr)|0,l:Number(r&zr)|0}}function ai(r,t=!1){let e=r.length,n=new Uint32Array(e),o=new Uint32Array(e);for(let s=0;s<e;s++){let{h:i,l:a}=wu(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var co=(r,t,e)=>r>>>e,uo=(r,t,e)=>r<<32-e|t>>>e,xe=(r,t,e)=>r>>>e|t<<32-e,we=(r,t,e)=>r<<32-e|t>>>e,ur=(r,t,e)=>r<<64-e|t>>>e-32,fr=(r,t,e)=>r>>>e-32|t<<64-e;function kt(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var ci=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),ui=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,fi=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),li=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,hi=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),di=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var Su=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]),ne=new Uint32Array(64),Gr=class extends cr{constructor(t=32){super(64,t,8,!1),this.A=Ht[0]|0,this.B=Ht[1]|0,this.C=Ht[2]|0,this.D=Ht[3]|0,this.E=Ht[4]|0,this.F=Ht[5]|0,this.G=Ht[6]|0,this.H=Ht[7]|0}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,e,n,o,s,i,a,c]}set(t,e,n,o,s,i,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,e){for(let f=0;f<16;f++,e+=4)ne[f]=t.getUint32(e,!1);for(let f=16;f<64;f++){let l=ne[f-15],h=ne[f-2],g=Tt(l,7)^Tt(l,18)^l>>>3,x=Tt(h,17)^Tt(h,19)^h>>>10;ne[f]=x+ne[f-7]+g+ne[f-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:d}=this;for(let f=0;f<64;f++){let l=Tt(a,6)^Tt(a,11)^Tt(a,25),h=d+l+oi(a,c,u)+Su[f]+ne[f]|0,x=(Tt(n,2)^Tt(n,13)^Tt(n,22))+si(n,o,s)|0;d=u,u=c,c=a,a=i+h|0,i=s,s=o,o=n,n=h+x|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,d=d+this.H|0,this.set(n,o,s,i,a,c,u,d)}roundClean(){qt(ne)}destroy(){this.set(0,0,0,0,0,0,0,0),qt(this.buffer)}};var pi=ai(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),vu=pi[0],Au=pi[1],oe=new Uint32Array(80),se=new Uint32Array(80),fo=class extends cr{constructor(t=64){super(128,t,16,!1),this.Ah=ot[0]|0,this.Al=ot[1]|0,this.Bh=ot[2]|0,this.Bl=ot[3]|0,this.Ch=ot[4]|0,this.Cl=ot[5]|0,this.Dh=ot[6]|0,this.Dl=ot[7]|0,this.Eh=ot[8]|0,this.El=ot[9]|0,this.Fh=ot[10]|0,this.Fl=ot[11]|0,this.Gh=ot[12]|0,this.Gl=ot[13]|0,this.Hh=ot[14]|0,this.Hl=ot[15]|0}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:d,Fh:f,Fl:l,Gh:h,Gl:g,Hh:x,Hl:p}=this;return[t,e,n,o,s,i,a,c,u,d,f,l,h,g,x,p]}set(t,e,n,o,s,i,a,c,u,d,f,l,h,g,x,p){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=d|0,this.Fh=f|0,this.Fl=l|0,this.Gh=h|0,this.Gl=g|0,this.Hh=x|0,this.Hl=p|0}process(t,e){for(let v=0;v<16;v++,e+=4)oe[v]=t.getUint32(e),se[v]=t.getUint32(e+=4);for(let v=16;v<80;v++){let T=oe[v-15]|0,C=se[v-15]|0,_=xe(T,C,1)^xe(T,C,8)^co(T,C,7),R=we(T,C,1)^we(T,C,8)^uo(T,C,7),U=oe[v-2]|0,D=se[v-2]|0,y=xe(U,D,19)^ur(U,D,61)^co(U,D,6),m=we(U,D,19)^fr(U,D,61)^uo(U,D,6),E=fi(R,m,se[v-7],se[v-16]),A=li(E,_,y,oe[v-7],oe[v-16]);oe[v]=A|0,se[v]=E|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:d,Eh:f,El:l,Fh:h,Fl:g,Gh:x,Gl:p,Hh:S,Hl:B}=this;for(let v=0;v<80;v++){let T=xe(f,l,14)^xe(f,l,18)^ur(f,l,41),C=we(f,l,14)^we(f,l,18)^fr(f,l,41),_=f&h^~f&x,R=l&g^~l&p,U=hi(B,C,R,Au[v],se[v]),D=di(U,S,T,_,vu[v],oe[v]),y=U|0,m=xe(n,o,28)^ur(n,o,34)^ur(n,o,39),E=we(n,o,28)^fr(n,o,34)^fr(n,o,39),A=n&s^n&a^s&a,P=o&i^o&c^i&c;S=x|0,B=p|0,x=h|0,p=g|0,h=f|0,g=l|0,{h:f,l}=kt(u|0,d|0,D|0,y|0),u=a|0,d=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let k=ci(y,E,P);n=ui(k,D,m,A),o=k|0}({h:n,l:o}=kt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=kt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=kt(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:d}=kt(this.Dh|0,this.Dl|0,u|0,d|0),{h:f,l}=kt(this.Eh|0,this.El|0,f|0,l|0),{h,l:g}=kt(this.Fh|0,this.Fl|0,h|0,g|0),{h:x,l:p}=kt(this.Gh|0,this.Gl|0,x|0,p|0),{h:S,l:B}=kt(this.Hh|0,this.Hl|0,S|0,B|0),this.set(n,o,s,i,a,c,u,d,f,l,h,g,x,p,S,B)}roundClean(){qt(oe,se)}destroy(){qt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Zr=ao(()=>new Gr);var mi=ao(()=>new fo);var po=BigInt(0),ho=BigInt(1);function Vt(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}function lr(r){let t=r.toString(16);return t.length&1?"0"+t:t}function yi(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?po:BigInt("0x"+r)}function Oe(r){return yi(At(r))}function Ft(r){return j(r),yi(At(Uint8Array.from(r).reverse()))}function Yr(r,t){return be(r.toString(16).padStart(t*2,"0"))}function zt(r,t){return Yr(r,t).reverse()}function V(r,t,e){let n;if(typeof t=="string")try{n=be(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(ye(t))n=Uint8Array.from(t);else throw new Error(r+" must be hex string or Uint8Array");let o=n.length;if(typeof e=="number"&&o!==e)throw new Error(r+" of length "+e+" expected, got "+o);return n}function bi(r,t){if(r.length!==t.length)return!1;let e=0;for(let n=0;n<r.length;n++)e|=r[n]^t[n];return e===0}var lo=r=>typeof r=="bigint"&&po<=r;function gi(r,t,e){return lo(r)&&lo(t)&&lo(e)&&t<=r&&r<e}function ie(r,t,e,n){if(!gi(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function Xr(r){let t;for(t=0;r>po;r>>=ho,t+=1);return t}var ae=r=>(ho<<BigInt(r))-ho;function xi(r,t,e){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof e!="function")throw new Error("hmacFn must be a function");let n=h=>new Uint8Array(h),o=h=>Uint8Array.of(h),s=n(r),i=n(r),a=0,c=()=>{s.fill(1),i.fill(0),a=0},u=(...h)=>e(i,s,...h),d=(h=n(0))=>{i=u(o(0),h),s=u(),h.length!==0&&(i=u(o(1),h),s=u())},f=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let h=0,g=[];for(;h<t;){s=u();let x=s.slice();g.push(x),h+=s.length}return mt(...g)};return(h,g)=>{c(),d(h);let x;for(;!(x=g(f()));)d();return c(),x}}function ce(r,t,e={}){if(!r||typeof r!="object")throw new Error("expected valid options object");function n(o,s,i){let a=r[o];if(i&&a===void 0)return;let c=typeof a;if(c!==s||a===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${c}`)}Object.entries(t).forEach(([o,s])=>n(o,s,!1)),Object.entries(e).forEach(([o,s])=>n(o,s,!0))}function qe(r){let t=new WeakMap;return(e,...n)=>{let o=t.get(e);if(o!==void 0)return o;let s=r(e,...n);return t.set(e,s),s}}var ft=BigInt(0),nt=BigInt(1),Ee=BigInt(2),Si=BigInt(3),vi=BigInt(4),Ai=BigInt(5),Iu=BigInt(7),Ii=BigInt(8),Bu=BigInt(9),Bi=BigInt(16);function W(r,t){let e=r%t;return e>=ft?e:t+e}function Z(r,t,e){let n=r;for(;t-- >ft;)n*=n,n%=e;return n}function wi(r,t){if(r===ft)throw new Error("invert: expected non-zero number");if(t<=ft)throw new Error("invert: expected positive modulus, got "+t);let e=W(r,t),n=t,o=ft,s=nt,i=nt,a=ft;for(;e!==ft;){let u=n/e,d=n%e,f=o-i*u,l=s-a*u;n=e,e=d,o=i,s=a,i=f,a=l}if(n!==nt)throw new Error("invert: does not exist");return W(o,t)}function mo(r,t,e){if(!r.eql(r.sqr(t),e))throw new Error("Cannot find square root")}function _i(r,t){let e=(r.ORDER+nt)/vi,n=r.pow(t,e);return mo(r,n,t),n}function _u(r,t){let e=(r.ORDER-Ai)/Ii,n=r.mul(t,Ee),o=r.pow(n,e),s=r.mul(t,o),i=r.mul(r.mul(s,Ee),o),a=r.mul(s,r.sub(i,r.ONE));return mo(r,a,t),a}function Lu(r){let t=Et(r),e=Li(r),n=e(t,t.neg(t.ONE)),o=e(t,n),s=e(t,t.neg(n)),i=(r+Iu)/Bi;return(a,c)=>{let u=a.pow(c,i),d=a.mul(u,n),f=a.mul(u,o),l=a.mul(u,s),h=a.eql(a.sqr(d),c),g=a.eql(a.sqr(f),c);u=a.cmov(u,d,h),d=a.cmov(l,f,g);let x=a.eql(a.sqr(d),c),p=a.cmov(u,d,x);return mo(a,p,c),p}}function Li(r){if(r<Si)throw new Error("sqrt is not defined for small field");let t=r-nt,e=0;for(;t%Ee===ft;)t/=Ee,e++;let n=Ee,o=Et(r);for(;Ei(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return _i;let s=o.pow(n,t),i=(t+nt)/Ee;return function(c,u){if(c.is0(u))return u;if(Ei(c,u)!==1)throw new Error("Cannot find square root");let d=e,f=c.mul(c.ONE,s),l=c.pow(u,t),h=c.pow(u,i);for(;!c.eql(l,c.ONE);){if(c.is0(l))return c.ZERO;let g=1,x=c.sqr(l);for(;!c.eql(x,c.ONE);)if(g++,x=c.sqr(x),g===d)throw new Error("Cannot find square root");let p=nt<<BigInt(d-g-1),S=c.pow(f,p);d=g,f=c.sqr(S),l=c.mul(l,f),h=c.mul(h,S)}return h}}function Tu(r){return r%vi===Si?_i:r%Ii===Ai?_u:r%Bi===Bu?Lu(r):Li(r)}var Gt=(r,t)=>(W(r,t)&nt)===nt,Du=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function yo(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},e=Du.reduce((n,o)=>(n[o]="function",n),t);return ce(r,e),r}function Pu(r,t,e){if(e<ft)throw new Error("invalid exponent, negatives unsupported");if(e===ft)return r.ONE;if(e===nt)return t;let n=r.ONE,o=t;for(;e>ft;)e&nt&&(n=r.mul(n,o)),o=r.sqr(o),e>>=nt;return n}function hr(r,t,e=!1){let n=new Array(t.length).fill(e?r.ZERO:void 0),o=t.reduce((i,a,c)=>r.is0(a)?i:(n[c]=i,r.mul(i,a)),r.ONE),s=r.inv(o);return t.reduceRight((i,a,c)=>r.is0(a)?i:(n[c]=r.mul(i,n[c]),r.mul(i,a)),s),n}function Ei(r,t){let e=(r.ORDER-nt)/Ee,n=r.pow(t,e),o=r.eql(n,r.ONE),s=r.eql(n,r.ZERO),i=r.eql(n,r.neg(r.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function Ti(r,t){t!==void 0&&ir(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function Et(r,t,e=!1,n={}){if(r<=ft)throw new Error("invalid field: expected ORDER > 0, got "+r);let o,s,i=!1,a;if(typeof t=="object"&&t!=null){if(n.sqrt||e)throw new Error("cannot specify opts in two arguments");let l=t;l.BITS&&(o=l.BITS),l.sqrt&&(s=l.sqrt),typeof l.isLE=="boolean"&&(e=l.isLE),typeof l.modOnDecode=="boolean"&&(i=l.modOnDecode),a=l.allowedLengths}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:c,nByteLength:u}=Ti(r,o);if(u>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let d,f=Object.freeze({ORDER:r,isLE:e,BITS:c,BYTES:u,MASK:ae(c),ZERO:ft,ONE:nt,allowedLengths:a,create:l=>W(l,r),isValid:l=>{if(typeof l!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof l);return ft<=l&&l<r},is0:l=>l===ft,isValidNot0:l=>!f.is0(l)&&f.isValid(l),isOdd:l=>(l&nt)===nt,neg:l=>W(-l,r),eql:(l,h)=>l===h,sqr:l=>W(l*l,r),add:(l,h)=>W(l+h,r),sub:(l,h)=>W(l-h,r),mul:(l,h)=>W(l*h,r),pow:(l,h)=>Pu(f,l,h),div:(l,h)=>W(l*wi(h,r),r),sqrN:l=>l*l,addN:(l,h)=>l+h,subN:(l,h)=>l-h,mulN:(l,h)=>l*h,inv:l=>wi(l,r),sqrt:s||(l=>(d||(d=Tu(r)),d(f,l))),toBytes:l=>e?zt(l,u):Yr(l,u),fromBytes:(l,h=!0)=>{if(a){if(!a.includes(l.length)||l.length>u)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+l.length);let x=new Uint8Array(u);x.set(l,e?0:x.length-l.length),l=x}if(l.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+l.length);let g=e?Ft(l):Oe(l);if(i&&(g=W(g,r)),!h&&!f.isValid(g))throw new Error("invalid field element: outside of range 0..ORDER");return g},invertBatch:l=>hr(f,l),cmov:(l,h,g)=>g?h:l});return Object.freeze(f)}function Di(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let t=r.toString(2).length;return Math.ceil(t/8)}function bo(r){let t=Di(r);return t+Math.ceil(t/2)}function go(r,t,e=!1){let n=r.length,o=Di(t),s=bo(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?Ft(r):Oe(r),a=W(i,t-nt)+nt;return e?zt(a,o):Yr(a,o)}var He=BigInt(0),Se=BigInt(1);function dr(r,t){let e=t.negate();return r?e:t}function Zt(r,t){let e=hr(r.Fp,t.map(n=>n.Z));return t.map((n,o)=>r.fromAffine(n.toAffine(e[o])))}function Ni(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function xo(r,t){Ni(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=ae(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Pi(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,a=Number(r&o),c=r>>i;a>n&&(a-=s,c+=Se);let u=t*n,d=u+Math.abs(a)-1,f=a===0,l=a<0,h=t%2!==0;return{nextN:c,offset:d,isZero:f,isNeg:l,isNegF:h,offsetF:u}}function ku(r,t){if(!Array.isArray(r))throw new Error("array expected");r.forEach((e,n)=>{if(!(e instanceof t))throw new Error("invalid point at index "+n)})}function Cu(r,t){if(!Array.isArray(r))throw new Error("array of scalars expected");r.forEach((e,n)=>{if(!t.isValid(e))throw new Error("invalid scalar at index "+n)})}var wo=new WeakMap,Ki=new WeakMap;function Eo(r){return Ki.get(r)||1}function ki(r){if(r!==He)throw new Error("invalid wNAF")}var Ve=class{constructor(t,e){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=e}_unsafeLadder(t,e,n=this.ZERO){let o=t;for(;e>He;)e&Se&&(n=n.add(o)),o=o.double(),e>>=Se;return n}precomputeWindow(t,e){let{windows:n,windowSize:o}=xo(e,this.bits),s=[],i=t,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let u=1;u<o;u++)a=a.add(i),s.push(a);i=a.double()}return s}wNAF(t,e,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=xo(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:u,isZero:d,isNeg:f,isNegF:l,offsetF:h}=Pi(n,a,i);n=c,d?s=s.add(dr(l,e[h])):o=o.add(dr(f,e[u]))}return ki(n),{p:o,f:s}}wNAFUnsafe(t,e,n,o=this.ZERO){let s=xo(t,this.bits);for(let i=0;i<s.windows&&n!==He;i++){let{nextN:a,offset:c,isZero:u,isNeg:d}=Pi(n,i,s);if(n=a,!u){let f=e[c];o=o.add(d?f.negate():f)}}return ki(n),o}getPrecomputes(t,e,n){let o=wo.get(e);return o||(o=this.precomputeWindow(e,t),t!==1&&(typeof n=="function"&&(o=n(o)),wo.set(e,o))),o}cached(t,e,n){let o=Eo(t);return this.wNAF(o,this.getPrecomputes(o,t,n),e)}unsafe(t,e,n,o){let s=Eo(t);return s===1?this._unsafeLadder(t,e,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),e,o)}createCache(t,e){Ni(e,this.bits),Ki.set(t,e),wo.delete(t)}hasCache(t){return Eo(t)!==1}};function Ri(r,t,e,n){let o=t,s=r.ZERO,i=r.ZERO;for(;e>He||n>He;)e&Se&&(s=s.add(o)),n&Se&&(i=i.add(o)),o=o.double(),e>>=Se,n>>=Se;return{p1:s,p2:i}}function Fe(r,t,e,n){ku(e,r),Cu(n,t);let o=e.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=r.ZERO,a=Xr(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let u=ae(c),d=new Array(Number(u)+1).fill(i),f=Math.floor((t.BITS-1)/c)*c,l=i;for(let h=f;h>=0;h-=c){d.fill(i);for(let x=0;x<s;x++){let p=n[x],S=Number(p>>BigInt(h)&u);d[S]=d[S].add(e[x])}let g=i;for(let x=d.length-1,p=i;x>0;x--)p=p.add(d[x]),g=g.add(p);if(l=l.add(g),h!==0)for(let x=0;x<c;x++)l=l.double()}return l}function Ci(r,t){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return yo(t),t}else return Et(r)}function $r(r,t,e={}){if(!t||typeof t!="object")throw new Error(`expected valid ${r} CURVE object`);for(let a of["p","n","h"]){let c=t[a];if(!(typeof c=="bigint"&&c>He))throw new Error(`CURVE.${a} must be positive bigint`)}let n=Ci(t.p,e.Fp),o=Ci(t.n,e.Fn),i=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let a of i)if(!n.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return{Fp:n,Fn:o}}var Ct=BigInt(0),rt=BigInt(1),So=BigInt(2),Nu=BigInt(8);function Ku(r,t,e,n){let o=r.sqr(e),s=r.sqr(n),i=r.add(r.mul(t.a,o),s),a=r.add(r.ONE,r.mul(t.d,r.mul(o,s)));return r.eql(i,a)}function Ru(r,t={}){let{Fp:e,Fn:n}=$r("edwards",r,t),{h:o,n:s}=r;ce(t,{},{uvRatio:"function"});let i=So<<BigInt(n.BYTES*8)-rt,a=x=>e.create(x),c=t.uvRatio||((x,p)=>{try{return{isValid:!0,value:e.sqrt(e.div(x,p))}}catch{return{isValid:!1,value:Ct}}});if(!Ku(e,r,r.Gx,r.Gy))throw new Error("bad curve params: generator point");function u(x,p,S=!1){let B=S?rt:Ct;return ie("coordinate "+x,p,B,i),p}function d(x){if(!(x instanceof h))throw new Error("ExtendedPoint expected")}let f=qe((x,p)=>{let{X:S,Y:B,Z:v}=x,T=x.is0();p==null&&(p=T?Nu:e.inv(v));let C=a(S*p),_=a(B*p),R=e.mul(v,p);if(T)return{x:Ct,y:rt};if(R!==rt)throw new Error("invZ was invalid");return{x:C,y:_}}),l=qe(x=>{let{a:p,d:S}=r;if(x.is0())throw new Error("bad point: ZERO");let{X:B,Y:v,Z:T,T:C}=x,_=a(B*B),R=a(v*v),U=a(T*T),D=a(U*U),y=a(_*p),m=a(U*a(y+R)),E=a(D+a(S*a(_*R)));if(m!==E)throw new Error("bad point: equation left != right (1)");let A=a(B*v),P=a(T*C);if(A!==P)throw new Error("bad point: equation left != right (2)");return!0});class h{constructor(p,S,B,v){this.X=u("x",p),this.Y=u("y",S),this.Z=u("z",B,!0),this.T=u("t",v),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(p){return Zt(h,p)}static msm(p,S){return Fe(h,n,p,S)}_setWindowSize(p){this.precompute(p)}static fromAffine(p){if(p instanceof h)throw new Error("extended point not allowed");let{x:S,y:B}=p||{};return u("x",S),u("y",B),new h(S,B,rt,a(S*B))}precompute(p=8,S=!0){return g.createCache(this,p),S||this.multiply(So),this}assertValidity(){l(this)}equals(p){d(p);let{X:S,Y:B,Z:v}=this,{X:T,Y:C,Z:_}=p,R=a(S*_),U=a(T*v),D=a(B*_),y=a(C*v);return R===U&&D===y}is0(){return this.equals(h.ZERO)}negate(){return new h(a(-this.X),this.Y,this.Z,a(-this.T))}double(){let{a:p}=r,{X:S,Y:B,Z:v}=this,T=a(S*S),C=a(B*B),_=a(So*a(v*v)),R=a(p*T),U=S+B,D=a(a(U*U)-T-C),y=R+C,m=y-_,E=R-C,A=a(D*m),P=a(y*E),k=a(D*E),w=a(m*y);return new h(A,P,w,k)}add(p){d(p);let{a:S,d:B}=r,{X:v,Y:T,Z:C,T:_}=this,{X:R,Y:U,Z:D,T:y}=p,m=a(v*R),E=a(T*U),A=a(_*B*y),P=a(C*D),k=a((v+T)*(R+U)-m-E),w=P-A,b=P+A,I=a(E-S*m),L=a(k*w),N=a(b*I),K=a(k*I),M=a(w*b);return new h(L,N,M,K)}subtract(p){return this.add(p.negate())}multiply(p){let S=p;ie("scalar",S,rt,s);let{p:B,f:v}=g.cached(this,S,T=>Zt(h,T));return Zt(h,[B,v])[0]}multiplyUnsafe(p,S=h.ZERO){let B=p;return ie("scalar",B,Ct,s),B===Ct?h.ZERO:this.is0()||B===rt?this:g.unsafe(this,B,v=>Zt(h,v),S)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}isTorsionFree(){return g.unsafe(this,s).is0()}toAffine(p){return f(this,p)}clearCofactor(){return o===rt?this:this.multiplyUnsafe(o)}static fromBytes(p,S=!1){return j(p),h.fromHex(p,S)}static fromHex(p,S=!1){let{d:B,a:v}=r,T=e.BYTES;p=V("pointHex",p,T),Vt("zip215",S);let C=p.slice(),_=p[T-1];C[T-1]=_&-129;let R=Ft(C),U=S?i:e.ORDER;ie("pointHex.y",R,Ct,U);let D=a(R*R),y=a(D-rt),m=a(B*D-v),{isValid:E,value:A}=c(y,m);if(!E)throw new Error("Point.fromHex: invalid y coordinate");let P=(A&rt)===rt,k=(_&128)!==0;if(!S&&A===Ct&&k)throw new Error("Point.fromHex: x=0 and x_0=1");return k!==P&&(A=a(-A)),h.fromAffine({x:A,y:R})}toBytes(){let{x:p,y:S}=this.toAffine(),B=zt(S,e.BYTES);return B[B.length-1]|=p&rt?128:0,B}toRawBytes(){return this.toBytes()}toHex(){return At(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}h.BASE=new h(r.Gx,r.Gy,rt,a(r.Gx*r.Gy)),h.ZERO=new h(Ct,rt,rt,Ct),h.Fp=e,h.Fn=n;let g=new Ve(h,n.BYTES*8);return h}var jr=class{constructor(t){this.ep=t}static fromBytes(t){throw new Error("fromBytes must be implemented by subclass")}static fromHex(t){throw new Error("fromHex must be implemented by subclass")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(t){return this.ep.toAffine(t)}toRawBytes(){return this.toBytes()}toHex(){return At(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(t){return this.assertSame(t),this.init(this.ep.add(t.ep))}subtract(t){return this.assertSame(t),this.init(this.ep.subtract(t.ep))}multiply(t){return this.init(this.ep.multiply(t))}multiplyUnsafe(t){return this.init(this.ep.multiplyUnsafe(t))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(t,e){return this.init(this.ep.precompute(t,e))}};function Uu(r,t,e){if(typeof t!="function")throw new Error('"hash" function param is required');ce(e,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=e,{BASE:o,Fp:s,Fn:i}=r,a=i.ORDER,c=e.randomBytes||ge,u=e.adjustScalarBytes||(m=>m),d=e.domain||((m,E,A)=>{if(Vt("phflag",A),E.length||A)throw new Error("Contexts/pre-hash are not supported");return m});function f(m){return i.create(m)}function l(m){return f(Ft(m))}function h(m){let E=s.BYTES;m=V("private key",m,E);let A=V("hashed private key",t(m),2*E),P=u(A.slice(0,E)),k=A.slice(E,2*E),w=l(P);return{head:P,prefix:k,scalar:w}}function g(m){let{head:E,prefix:A,scalar:P}=h(m),k=o.multiply(P),w=k.toBytes();return{head:E,prefix:A,scalar:P,point:k,pointBytes:w}}function x(m){return g(m).pointBytes}function p(m=Uint8Array.of(),...E){let A=mt(...E);return l(t(d(A,V("context",m),!!n)))}function S(m,E,A={}){m=V("message",m),n&&(m=n(m));let{prefix:P,scalar:k,pointBytes:w}=g(E),b=p(A.context,P,m),I=o.multiply(b).toBytes(),L=p(A.context,I,w,m),N=f(b+L*k);ie("signature.s",N,Ct,a);let K=s.BYTES,M=mt(I,zt(N,K));return V("result",M,K*2)}let B={zip215:!0};function v(m,E,A,P=B){let{context:k,zip215:w}=P,b=s.BYTES;m=V("signature",m,2*b),E=V("message",E),A=V("publicKey",A,b),w!==void 0&&Vt("zip215",w),n&&(E=n(E));let I=Ft(m.slice(b,2*b)),L,N,K;try{L=r.fromHex(A,w),N=r.fromHex(m.slice(0,b),w),K=o.multiplyUnsafe(I)}catch{return!1}if(!w&&L.isSmallOrder())return!1;let M=p(k,N.toBytes(),L.toBytes(),E);return N.add(L.multiplyUnsafe(M)).subtract(K).clearCofactor().is0()}o.precompute(8);let T=s.BYTES,C={secret:T,public:T,signature:2*T,seed:T};function _(m=c(C.seed)){return m}let R={getExtendedPublicKey:g,randomSecretKey:_,isValidSecretKey:D,isValidPublicKey:y,randomPrivateKey:_,toMontgomery(m){let{y:E}=r.fromBytes(m),A=T===32;if(!A&&T!==57)throw new Error("only defined for 25519 and 448");let P=A?s.div(rt+E,rt-E):s.div(E-rt,E+rt);return s.toBytes(P)},toMontgomeryPriv(m){j(m,T);let E=t(m.subarray(0,T));return u(E).subarray(0,T)},precompute(m=8,E=r.BASE){return E.precompute(m,!1)}};function U(m){let E=R.randomSecretKey(m);return{secretKey:E,publicKey:x(E)}}function D(m){try{return!!i.fromBytes(m,!1)}catch{return!1}}function y(m,E){try{return!!r.fromBytes(m,E)}catch{return!1}}return Object.freeze({keygen:U,getPublicKey:x,sign:S,verify:v,utils:R,Point:r,info:{type:"edwards",lengths:C}})}function Mu(r){let t={a:r.a,d:r.d,p:r.Fp.ORDER,n:r.n,h:r.h,Gx:r.Gx,Gy:r.Gy},e=r.Fp,n=Et(t.n,r.nBitLength,!0),o={Fp:e,Fn:n,uvRatio:r.uvRatio},s={randomBytes:r.randomBytes,adjustScalarBytes:r.adjustScalarBytes,domain:r.domain,prehash:r.prehash,mapToCurve:r.mapToCurve};return{CURVE:t,curveOpts:o,hash:r.hash,eddsaOpts:s}}function Ou(r,t){return Object.assign({},t,{ExtendedPoint:t.Point,CURVE:r})}function Ui(r){let{CURVE:t,curveOpts:e,hash:n,eddsaOpts:o}=Mu(r),s=Ru(t,e),i=Uu(s,n,o);return Ou(r,i)}var qu=BigInt(0),Yt=BigInt(1),Mi=BigInt(2),Pd=BigInt(3),Hu=BigInt(5),Vu=BigInt(8),pr={p:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Vu,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Fu(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=pr.p,a=r*r%s*r%s,c=Z(a,Mi,s)*a%s,u=Z(c,Yt,s)*r%s,d=Z(u,Hu,s)*u%s,f=Z(d,t,s)*d%s,l=Z(f,e,s)*f%s,h=Z(l,n,s)*l%s,g=Z(h,o,s)*h%s,x=Z(g,o,s)*h%s,p=Z(x,t,s)*d%s;return{pow_p_5_8:Z(p,Mi,s)*r%s,b2:a}}function zu(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var vo=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Bo(r,t){let e=pr.p,n=W(t*t*t,e),o=W(n*n*t,e),s=Fu(r*o).pow_p_5_8,i=W(r*n*s,e),a=W(t*i*i,e),c=i,u=W(i*vo,e),d=a===r,f=a===W(-r,e),l=a===W(-r*vo,e);return d&&(i=c),(f||l)&&(i=u),Gt(i,e)&&(i=W(-i,e)),{isValid:d||f,value:i}}var ve=Et(pr.p,{isLE:!0}),Gu=Et(pr.n,{isLE:!0}),Zu={...pr,Fp:ve,hash:mi,adjustScalarBytes:zu,uvRatio:Bo},St=Ui(Zu);var Ao=vo,Yu=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Xu=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),$u=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),ju=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Oi=r=>Bo(Yt,r),Wu=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Io=r=>St.CURVE.Fp.create(Ft(r)&Wu);function qi(r){let{d:t}=St.CURVE,e=St.CURVE.Fp.ORDER,n=St.CURVE.Fp.create,o=n(Ao*r*r),s=n((o+Yt)*$u),i=BigInt(-1),a=n((i-t*o)*n(o+t)),{isValid:c,value:u}=Bo(s,a),d=n(u*r);Gt(d,e)||(d=n(-d)),c||(u=d),c||(i=o);let f=n(i*(o-Yt)*ju-a),l=u*u,h=n((u+u)*a),g=n(f*Yu),x=n(Yt-l),p=n(Yt+l);return new St.Point(n(h*p),n(x*g),n(g*p),n(h*x))}function Ju(r){j(r,64);let t=Io(r.subarray(0,32)),e=qi(t),n=Io(r.subarray(32,64)),o=qi(n);return new Xt(e.add(o))}var Xt=class r extends jr{constructor(t){super(t)}static fromAffine(t){return new r(St.Point.fromAffine(t))}assertSame(t){if(!(t instanceof r))throw new Error("RistrettoPoint expected")}init(t){return new r(t)}static hashToCurve(t){return Ju(V("ristrettoHash",t,64))}static fromBytes(t){j(t,32);let{a:e,d:n}=St.CURVE,o=ve.ORDER,s=ve.create,i=Io(t);if(!bi(zt(i,32),t)||Gt(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),c=s(Yt+e*a),u=s(Yt-e*a),d=s(c*c),f=s(u*u),l=s(e*n*d-f),{isValid:h,value:g}=Oi(s(l*f)),x=s(g*u),p=s(g*x*l),S=s((i+i)*x);Gt(S,o)&&(S=s(-S));let B=s(c*p),v=s(S*B);if(!h||Gt(v,o)||B===qu)throw new Error("invalid ristretto255 encoding 2");return new r(new St.Point(S,B,Yt,v))}static fromHex(t){return r.fromBytes(V("ristrettoHex",t,32))}static msm(t,e){return Fe(r,St.Point.Fn,t,e)}toBytes(){let{X:t,Y:e,Z:n,T:o}=this.ep,s=ve.ORDER,i=ve.create,a=i(i(n+e)*i(n-e)),c=i(t*e),u=i(c*c),{value:d}=Oi(i(a*u)),f=i(d*a),l=i(d*c),h=i(f*l*o),g;if(Gt(o*h,s)){let p=i(e*Ao),S=i(t*Ao);t=p,e=S,g=i(f*Xu)}else g=l;Gt(t*h,s)&&(e=i(-e));let x=i((n-e)*g);return Gt(x,s)&&(x=i(-x)),zt(x,32)}equals(t){this.assertSame(t);let{X:e,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=ve.create,a=i(e*s)===i(n*o),c=i(n*s)===i(e*o);return a||c}is0(){return this.equals(r.ZERO)}};Xt.BASE=new Xt(St.Point.BASE);Xt.ZERO=new Xt(St.Point.ZERO);Xt.Fp=ve;Xt.Fn=Gu;var mr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Wr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Hi={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new Wr("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var It=Hi;var Jr=32;var _o,Qu=(async()=>{try{return await It.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function tf(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await It.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await It.get().subtle.verify({name:"Ed25519"},n,t,e instanceof Uint8Array?e:e.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function ef(r,t,e){return St.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function Vi(r,t,e){return _o==null&&(_o=await Qu),_o?tf(r,t,e):ef(r,t,e)}function Qr(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var tn=class{type="Ed25519";raw;constructor(t){this.raw=Lo(t,Jr)}toMultihash(){return Lt.digest(Mt(this))}toCID(){return st.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:dt(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let o=Vi(this.raw,e,t);return Qr(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function To(r){return r=Lo(r,Jr),new tn(r)}function Lo(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new Y(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var nf=Math.pow(2,7),of=Math.pow(2,14),sf=Math.pow(2,21),Do=Math.pow(2,28),Po=Math.pow(2,35),ko=Math.pow(2,42),Co=Math.pow(2,49),O=128,at=127;function Dt(r){if(r<nf)return 1;if(r<of)return 2;if(r<sf)return 3;if(r<Do)return 4;if(r<Po)return 5;if(r<ko)return 6;if(r<Co)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function No(r,t,e=0){switch(Dt(r)){case 8:t[e++]=r&255|O,r/=128;case 7:t[e++]=r&255|O,r/=128;case 6:t[e++]=r&255|O,r/=128;case 5:t[e++]=r&255|O,r/=128;case 4:t[e++]=r&255|O,r>>>=7;case 3:t[e++]=r&255|O,r>>>=7;case 2:t[e++]=r&255|O,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function af(r,t,e=0){switch(Dt(r)){case 8:t.set(e++,r&255|O),r/=128;case 7:t.set(e++,r&255|O),r/=128;case 6:t.set(e++,r&255|O),r/=128;case 5:t.set(e++,r&255|O),r/=128;case 4:t.set(e++,r&255|O),r>>>=7;case 3:t.set(e++,r&255|O),r>>>=7;case 2:t.set(e++,r&255|O),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function Ko(r,t){let e=r[t],n=0;if(n+=e&at,e<O||(e=r[t+1],n+=(e&at)<<7,e<O)||(e=r[t+2],n+=(e&at)<<14,e<O)||(e=r[t+3],n+=(e&at)<<21,e<O)||(e=r[t+4],n+=(e&at)*Do,e<O)||(e=r[t+5],n+=(e&at)*Po,e<O)||(e=r[t+6],n+=(e&at)*ko,e<O)||(e=r[t+7],n+=(e&at)*Co,e<O))return n;throw new RangeError("Could not decode varint")}function cf(r,t){let e=r.get(t),n=0;if(n+=e&at,e<O||(e=r.get(t+1),n+=(e&at)<<7,e<O)||(e=r.get(t+2),n+=(e&at)<<14,e<O)||(e=r.get(t+3),n+=(e&at)<<21,e<O)||(e=r.get(t+4),n+=(e&at)*Do,e<O)||(e=r.get(t+5),n+=(e&at)*Po,e<O)||(e=r.get(t+6),n+=(e&at)*ko,e<O)||(e=r.get(t+7),n+=(e&at)*Co,e<O))return n;throw new RangeError("Could not decode varint")}function zi(r,t,e=0){return t==null&&(t=it(Dt(r))),t instanceof Uint8Array?No(r,t,e):af(r,t,e)}function Gi(r,t=0){return r instanceof Uint8Array?Ko(r,t):cf(r,t)}var Ro=new Float32Array([-0]),ue=new Uint8Array(Ro.buffer);function Yi(r,t,e){Ro[0]=r,t[e]=ue[0],t[e+1]=ue[1],t[e+2]=ue[2],t[e+3]=ue[3]}function Xi(r,t){return ue[0]=r[t],ue[1]=r[t+1],ue[2]=r[t+2],ue[3]=r[t+3],Ro[0]}var Uo=new Float64Array([-0]),ct=new Uint8Array(Uo.buffer);function $i(r,t,e){Uo[0]=r,t[e]=ct[0],t[e+1]=ct[1],t[e+2]=ct[2],t[e+3]=ct[3],t[e+4]=ct[4],t[e+5]=ct[5],t[e+6]=ct[6],t[e+7]=ct[7]}function ji(r,t){return ct[0]=r[t],ct[1]=r[t+1],ct[2]=r[t+2],ct[3]=r[t+3],ct[4]=r[t+4],ct[5]=r[t+5],ct[6]=r[t+6],ct[7]=r[t+7],Uo[0]}var uf=BigInt(Number.MAX_SAFE_INTEGER),ff=BigInt(Number.MIN_SAFE_INTEGER),vt=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return Ae;if(t<uf&&t>ff)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>Wi&&(o=0n,++n>Wi&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return Ae;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):Ae}},Ae=new vt(0,0);Ae.toBigInt=function(){return 0n};Ae.zzEncode=Ae.zzDecode=function(){return this};Ae.length=function(){return 1};var Wi=4294967296n;function Ji(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Qi(r,t,e){if(e-t<1)return"";let o,s=[],i=0,a;for(;t<e;)a=r[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function Mo(r,t,e){let n=e,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function Pt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function en(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Oo=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Pt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Pt(this,4);return en(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Pt(this,4);return en(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Pt(this,4);let t=Xi(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Pt(this,4);let t=ji(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw Pt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Qi(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Pt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Pt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new vt(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw Pt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw Pt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Pt(this,8);let t=en(this.buf,this.pos+=4),e=en(this.buf,this.pos+=4);return new vt(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Ko(this.buf,this.pos);return this.pos+=Dt(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function qo(r){return new Oo(r instanceof Uint8Array?r:r.subarray())}function yt(r,t,e){let n=qo(r);return t.decode(n,void 0,e)}function Ho(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return it(i);o+i>t&&(n=it(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Ie=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Vo(){}var zo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},lf=Ho();function hf(r){return globalThis.Buffer!=null?it(r):lf(r)}var br=class{len;head;tail;states;constructor(){this.len=0,this.head=new Ie(Vo,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new Ie(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Go((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(rn,10,vt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=vt.fromBigInt(t);return this._push(rn,e.length(),e)}uint64Number(t){return this._push(No,Dt(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=vt.fromBigInt(t).zzEncode();return this._push(rn,e.length(),e)}sint64Number(t){let e=vt.fromNumber(t).zzEncode();return this._push(rn,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Fo,1,t?1:0)}fixed32(t){return this._push(yr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=vt.fromBigInt(t);return this._push(yr,4,e.lo)._push(yr,4,e.hi)}fixed64Number(t){let e=vt.fromNumber(t);return this._push(yr,4,e.lo)._push(yr,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Yi,4,t)}double(t){return this._push($i,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Fo,1,0):this.uint32(e)._push(pf,e,t)}string(t){let e=Ji(t);return e!==0?this.uint32(e)._push(Mo,e,t):this._push(Fo,1,0)}fork(){return this.states=new zo(this),this.head=this.tail=new Ie(Vo,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 Ie(Vo,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=hf(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Fo(r,t,e){t[e]=r&255}function df(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Go=class extends Ie{next;constructor(t,e){super(df,t,e),this.next=void 0}};function rn(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function yr(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function pf(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(br.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(mf,t,r),this},br.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(yf,t,r),this});function mf(r,t,e){t.set(r,e)}function yf(r,t,e){r.length<40?Mo(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(z(r),e)}function Zo(){return new br}function bt(r,t){let e=Zo();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var ze;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(ze||(ze={}));function nn(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Yo(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(s,i){let a=t(s);i.int32(a)},n=function(s){let i=s.int32();return t(i)};return nn("enum",ze.VARINT,e,n)}function gt(r,t){return nn("message",ze.LENGTH_DELIMITED,r,t)}var Bt=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var Q;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(Q||(Q={}));var Xo;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(Xo||(Xo={}));(function(r){r.codec=()=>Yo(Xo)})(Q||(Q={}));var Nt;(function(r){let t;r.codec=()=>(t==null&&(t=gt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),Q.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=Q.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>bt(e,r.codec()),r.decode=(e,n)=>yt(e,r.codec(),n)})(Nt||(Nt={}));var $o;(function(r){let t;r.codec=()=>(t==null&&(t=gt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),Q.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.Type=Q.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>bt(e,r.codec()),r.decode=(e,n)=>yt(e,r.codec(),n)})($o||($o={}));function on(r){if(isNaN(r)||r<=0)throw new Y("random bytes length must be a Number bigger than 0");return ge(r)}var xr={};ht(xr,{MAX_RSA_KEY_SIZE:()=>jo,generateRSAKeyPair:()=>sa,jwkToJWKKeyPair:()=>ia,jwkToPkcs1:()=>wf,jwkToPkix:()=>ts,jwkToRSAPrivateKey:()=>os,pkcs1MessageToJwk:()=>Jo,pkcs1MessageToRSAPrivateKey:()=>es,pkcs1ToJwk:()=>xf,pkcs1ToRSAPrivateKey:()=>oa,pkixMessageToJwk:()=>Qo,pkixMessageToRSAPublicKey:()=>ns,pkixToJwk:()=>Ef,pkixToRSAPublicKey:()=>rs});var sn=Zr;var Ge=class{type="RSA";jwk;_raw;_multihash;constructor(t,e){this.jwk=t,this._multihash=e}get raw(){return this._raw==null&&(this._raw=xr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return st.createV1(114,this._multihash)}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:dt(this.raw,t.raw)}verify(t,e,n){return na(this.jwk,e,t,n)}},gr=class{type="RSA";jwk;_raw;publicKey;constructor(t,e){this.jwk=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=xr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:dt(this.raw,t.raw)}sign(t,e){return ra(this.jwk,t,e)}};var jo=8192,Wo=18,bf=1062,gf=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function xf(r){let t=Ut(r);return Jo(t)}function Jo(r){return{n:H(r[1],"base64url"),e:H(r[2],"base64url"),d:H(r[3],"base64url"),p:H(r[4],"base64url"),q:H(r[5],"base64url"),dp:H(r[6],"base64url"),dq:H(r[7],"base64url"),qi:H(r[8],"base64url"),kty:"RSA"}}function wf(r){if(r.n==null||r.e==null||r.d==null||r.p==null||r.q==null||r.dp==null||r.dq==null||r.qi==null)throw new Y("JWK was missing components");return re([pt(Uint8Array.from([0])),pt(z(r.n,"base64url")),pt(z(r.e,"base64url")),pt(z(r.d,"base64url")),pt(z(r.p,"base64url")),pt(z(r.q,"base64url")),pt(z(r.dp,"base64url")),pt(z(r.dq,"base64url")),pt(z(r.qi,"base64url"))]).subarray()}function Ef(r){let t=Ut(r,{offset:0});return Qo(t)}function Qo(r){let t=Ut(r[1],{offset:0});return{kty:"RSA",n:H(t[0],"base64url"),e:H(t[1],"base64url")}}function ts(r){if(r.n==null||r.e==null)throw new Y("JWK was missing components");return re([gf,Hr(re([pt(z(r.n,"base64url")),pt(z(r.e,"base64url"))]))]).subarray()}function oa(r){let t=Ut(r);return es(t)}function es(r){let t=Jo(r);return os(t)}function rs(r,t){if(r.byteLength>=bf)throw new Te("Key size is too large");let e=Ut(r,{offset:0});return ns(e,r,t)}function ns(r,t,e){let n=Qo(r);if(e==null){let o=sn(Nt.encode({Type:Q.RSA,Data:t}));e=_t(Wo,o)}return new Ge(n,e)}function os(r){if(ca(r)>jo)throw new Y("Key size is too large");let t=ia(r),e=sn(Nt.encode({Type:Q.RSA,Data:ts(t.publicKey)})),n=_t(Wo,e);return new gr(t.privateKey,new Ge(t.publicKey,n))}async function sa(r){if(r>jo)throw new Y("Key size is too large");let t=await aa(r),e=sn(Nt.encode({Type:Q.RSA,Data:ts(t.publicKey)})),n=_t(Wo,e);return new gr(t.privateKey,new Ge(t.publicKey,n))}function ia(r){if(r==null)throw new Y("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function aa(r,t){let e=await It.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await Sf(e,t);return{privateKey:n[0],publicKey:n[1]}}async function ra(r,t,e){let n=await It.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);e?.signal?.throwIfAborted();let o=await It.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return e?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function na(r,t,e,n){let o=await It.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await It.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,e instanceof Uint8Array?e:e.subarray());return n?.signal?.throwIfAborted(),s}async function Sf(r,t){if(r.privateKey==null||r.publicKey==null)throw new Y("Private and public key are required");let e=await Promise.all([It.get().subtle.exportKey("jwk",r.privateKey),It.get().subtle.exportKey("jwk",r.publicKey)]);return t?.signal?.throwIfAborted(),e}function ca(r){if(r.kty!=="RSA")throw new Y("invalid key type");if(r.n==null)throw new Y("invalid key modulus");return z(r.n,"base64url").length*8}var an=class extends Ue{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,Vr(t);let n=ar(e);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),qt(s)}update(t){return Me(this),this.iHash.update(t),this}digestInto(t){Me(this),j(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:e,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},ss=(r,t,e)=>new an(r,t).update(e).digest();ss.create=(r,t)=>new an(r,t);var ua=(r,t)=>(r+(r>=0?t:-t)/la)/t;function vf(r,t,e){let[[n,o],[s,i]]=t,a=ua(i*r,e),c=ua(-o*r,e),u=r-a*n-c*s,d=-a*o-c*i,f=u<jt,l=d<jt;f&&(u=-u),l&&(d=-d);let h=ae(Math.ceil(Xr(e)/2))+Ye;if(u<jt||u>=h||d<jt||d>=h)throw new Error("splitScalar (endomorphism): failed, k="+r);return{k1neg:f,k1:u,k2neg:l,k2:d}}function fa(r){r.lowS!==void 0&&Vt("lowS",r.lowS),r.prehash!==void 0&&Vt("prehash",r.prehash)}var is=class extends Error{constructor(t=""){super(t)}},$t={Err:is,_tlv:{encode:(r,t)=>{let{Err:e}=$t;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,o=lr(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?lr(o.length/2|128):"";return lr(r)+s+o+t},decode(r,t){let{Err:e}=$t,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new e("tlv.decode(long): indefinite length not supported");if(c>4)throw new e("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+c);if(u.length!==c)throw new e("tlv.decode: length bytes not complete");if(u[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let d of u)i=i<<8|d;if(n+=c,i<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=$t;if(r<jt)throw new t("integer: negative integers are not allowed");let e=lr(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return e},decode(r){let{Err:t}=$t;if(r[0]&128)throw new t("invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Oe(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=$t,o=V("signature",r),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:u,l:d}=n.decode(2,c);if(d.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(u)}},hexFromSig(r){let{_tlv:t,_int:e}=$t,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}},jt=BigInt(0),Ye=BigInt(1),la=BigInt(2),cn=BigInt(3),Af=BigInt(4);function If(r,t,e){function n(o){let s=r.sqr(o),i=r.mul(s,o);return r.add(r.add(i,r.mul(o,t)),e)}return n}function Ze(r,t){let{BYTES:e}=r,n;if(typeof t=="bigint")n=t;else{let o=V("private key",t);try{n=r.fromBytes(o)}catch{throw new Error(`invalid private key: expected ui8a of size ${e}, got ${typeof t}`)}}if(!r.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function Bf(r,t={}){let{Fp:e,Fn:n}=$r("weierstrass",r,t),{h:o,n:s}=r;ce(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:i}=t;if(i&&(!e.is0(r.a)||typeof i.beta!="bigint"||!Array.isArray(i.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');function a(){if(!e.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function c(D,y,m){let{x:E,y:A}=y.toAffine(),P=e.toBytes(E);if(Vt("isCompressed",m),m){a();let k=!e.isOdd(A);return mt(ha(k),P)}else return mt(Uint8Array.of(4),P,e.toBytes(A))}function u(D){j(D);let y=e.BYTES,m=y+1,E=2*y+1,A=D.length,P=D[0],k=D.subarray(1);if(A===m&&(P===2||P===3)){let w=e.fromBytes(k);if(!e.isValid(w))throw new Error("bad point: is not on curve, wrong x");let b=l(w),I;try{I=e.sqrt(b)}catch(K){let M=K instanceof Error?": "+K.message:"";throw new Error("bad point: is not on curve, sqrt error"+M)}a();let L=e.isOdd(I);return(P&1)===1!==L&&(I=e.neg(I)),{x:w,y:I}}else if(A===E&&P===4){let w=e.fromBytes(k.subarray(y*0,y*1)),b=e.fromBytes(k.subarray(y*1,y*2));if(!h(w,b))throw new Error("bad point: is not on curve");return{x:w,y:b}}else throw new Error(`bad point: got length ${A}, expected compressed=${m} or uncompressed=${E}`)}let d=t.toBytes||c,f=t.fromBytes||u,l=If(e,r.a,r.b);function h(D,y){let m=e.sqr(y),E=l(D);return e.eql(m,E)}if(!h(r.Gx,r.Gy))throw new Error("bad curve params: generator point");let g=e.mul(e.pow(r.a,cn),Af),x=e.mul(e.sqr(r.b),BigInt(27));if(e.is0(e.add(g,x)))throw new Error("bad curve params: a or b");function p(D,y,m=!1){if(!e.isValid(y)||m&&e.is0(y))throw new Error(`bad point coordinate ${D}`);return y}function S(D){if(!(D instanceof _))throw new Error("ProjectivePoint expected")}function B(D){if(!i||!i.basises)throw new Error("no endo");return vf(D,i.basises,n.ORDER)}let v=qe((D,y)=>{let{X:m,Y:E,Z:A}=D;if(e.eql(A,e.ONE))return{x:m,y:E};let P=D.is0();y==null&&(y=P?e.ONE:e.inv(A));let k=e.mul(m,y),w=e.mul(E,y),b=e.mul(A,y);if(P)return{x:e.ZERO,y:e.ZERO};if(!e.eql(b,e.ONE))throw new Error("invZ was invalid");return{x:k,y:w}}),T=qe(D=>{if(D.is0()){if(t.allowInfinityPoint&&!e.is0(D.Y))return;throw new Error("bad point: ZERO")}let{x:y,y:m}=D.toAffine();if(!e.isValid(y)||!e.isValid(m))throw new Error("bad point: x or y not field elements");if(!h(y,m))throw new Error("bad point: equation left != right");if(!D.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function C(D,y,m,E,A){return m=new _(e.mul(m.X,D),m.Y,m.Z),y=dr(E,y),m=dr(A,m),y.add(m)}class _{constructor(y,m,E){this.X=p("x",y),this.Y=p("y",m,!0),this.Z=p("z",E),Object.freeze(this)}static fromAffine(y){let{x:m,y:E}=y||{};if(!y||!e.isValid(m)||!e.isValid(E))throw new Error("invalid affine point");if(y instanceof _)throw new Error("projective point not allowed");return e.is0(m)&&e.is0(E)?_.ZERO:new _(m,E,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}static normalizeZ(y){return Zt(_,y)}static fromBytes(y){return j(y),_.fromHex(y)}static fromHex(y){let m=_.fromAffine(f(V("pointHex",y)));return m.assertValidity(),m}static fromPrivateKey(y){return _.BASE.multiply(Ze(n,y))}static msm(y,m){return Fe(_,n,y,m)}_setWindowSize(y){this.precompute(y)}precompute(y=8,m=!0){return U.createCache(this,y),m||this.multiply(cn),this}assertValidity(){T(this)}hasEvenY(){let{y}=this.toAffine();if(!e.isOdd)throw new Error("Field doesn't support isOdd");return!e.isOdd(y)}equals(y){S(y);let{X:m,Y:E,Z:A}=this,{X:P,Y:k,Z:w}=y,b=e.eql(e.mul(m,w),e.mul(P,A)),I=e.eql(e.mul(E,w),e.mul(k,A));return b&&I}negate(){return new _(this.X,e.neg(this.Y),this.Z)}double(){let{a:y,b:m}=r,E=e.mul(m,cn),{X:A,Y:P,Z:k}=this,w=e.ZERO,b=e.ZERO,I=e.ZERO,L=e.mul(A,A),N=e.mul(P,P),K=e.mul(k,k),M=e.mul(A,P);return M=e.add(M,M),I=e.mul(A,k),I=e.add(I,I),w=e.mul(y,I),b=e.mul(E,K),b=e.add(w,b),w=e.sub(N,b),b=e.add(N,b),b=e.mul(w,b),w=e.mul(M,w),I=e.mul(E,I),K=e.mul(y,K),M=e.sub(L,K),M=e.mul(y,M),M=e.add(M,I),I=e.add(L,L),L=e.add(I,L),L=e.add(L,K),L=e.mul(L,M),b=e.add(b,L),K=e.mul(P,k),K=e.add(K,K),L=e.mul(K,M),w=e.sub(w,L),I=e.mul(K,N),I=e.add(I,I),I=e.add(I,I),new _(w,b,I)}add(y){S(y);let{X:m,Y:E,Z:A}=this,{X:P,Y:k,Z:w}=y,b=e.ZERO,I=e.ZERO,L=e.ZERO,N=r.a,K=e.mul(r.b,cn),M=e.mul(m,P),G=e.mul(E,k),F=e.mul(A,w),xt=e.add(m,E),q=e.add(P,k);xt=e.mul(xt,q),q=e.add(M,G),xt=e.sub(xt,q),q=e.add(m,A);let tt=e.add(P,w);return q=e.mul(q,tt),tt=e.add(M,F),q=e.sub(q,tt),tt=e.add(E,A),b=e.add(k,w),tt=e.mul(tt,b),b=e.add(G,F),tt=e.sub(tt,b),L=e.mul(N,q),b=e.mul(K,F),L=e.add(b,L),b=e.sub(G,L),L=e.add(G,L),I=e.mul(b,L),G=e.add(M,M),G=e.add(G,M),F=e.mul(N,F),q=e.mul(K,q),G=e.add(G,F),F=e.sub(M,F),F=e.mul(N,F),q=e.add(q,F),M=e.mul(G,q),I=e.add(I,M),M=e.mul(tt,q),b=e.mul(xt,b),b=e.sub(b,M),M=e.mul(xt,G),L=e.mul(tt,L),L=e.add(L,M),new _(b,I,L)}subtract(y){return this.add(y.negate())}is0(){return this.equals(_.ZERO)}multiply(y){let{endo:m}=t;if(!n.isValidNot0(y))throw new Error("invalid scalar: out of range");let E,A,P=k=>U.cached(this,k,w=>Zt(_,w));if(m){let{k1neg:k,k1:w,k2neg:b,k2:I}=B(y),{p:L,f:N}=P(w),{p:K,f:M}=P(I);A=N.add(M),E=C(m.beta,L,K,k,b)}else{let{p:k,f:w}=P(y);E=k,A=w}return Zt(_,[E,A])[0]}multiplyUnsafe(y){let{endo:m}=t,E=this;if(!n.isValid(y))throw new Error("invalid scalar: out of range");if(y===jt||E.is0())return _.ZERO;if(y===Ye)return E;if(U.hasCache(this))return this.multiply(y);if(m){let{k1neg:A,k1:P,k2neg:k,k2:w}=B(y),{p1:b,p2:I}=Ri(_,E,P,w);return C(m.beta,b,I,A,k)}else return U.unsafe(E,y)}multiplyAndAddUnsafe(y,m,E){let A=this.multiplyUnsafe(m).add(y.multiplyUnsafe(E));return A.is0()?void 0:A}toAffine(y){return v(this,y)}isTorsionFree(){let{isTorsionFree:y}=t;return o===Ye?!0:y?y(_,this):U.unsafe(this,s).is0()}clearCofactor(){let{clearCofactor:y}=t;return o===Ye?this:y?y(_,this):this.multiplyUnsafe(o)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}toBytes(y=!0){return Vt("isCompressed",y),this.assertValidity(),d(_,this,y)}toRawBytes(y=!0){return this.toBytes(y)}toHex(y=!0){return At(this.toBytes(y))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}_.BASE=new _(r.Gx,r.Gy,e.ONE),_.ZERO=new _(e.ZERO,e.ONE,e.ZERO),_.Fp=e,_.Fn=n;let R=n.BITS,U=new Ve(_,t.endo?Math.ceil(R/2):R);return _}function ha(r){return Uint8Array.of(r?2:3)}function _f(r,t,e={}){Vr(t),ce(e,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=e.randomBytes||ge,o=e.hmac||((w,...b)=>ss(t,w,mt(...b))),{Fp:s,Fn:i}=r,{ORDER:a,BITS:c}=i,u=bo(a),d={secret:i.BYTES,public:1+s.BYTES,publicUncompressed:1+2*s.BYTES,signature:2*i.BYTES,seed:u};function f(w){let b=a>>Ye;return w>b}function l(w){return f(w)?i.neg(w):w}function h(w,b){if(!i.isValidNot0(b))throw new Error(`invalid signature ${w}: out of range 1..CURVE.n`)}class g{constructor(b,I,L){h("r",b),h("s",I),this.r=b,this.s=I,L!=null&&(this.recovery=L),Object.freeze(this)}static fromBytes(b,I="compact"){if(I==="compact"){let L=i.BYTES;j(b,L*2);let N=b.subarray(0,L),K=b.subarray(L,L*2);return new g(i.fromBytes(N),i.fromBytes(K))}if(I==="der"){j(b);let{r:L,s:N}=$t.toSig(b);return new g(L,N)}throw new Error("invalid format")}static fromHex(b,I){return this.fromBytes(be(b),I)}addRecoveryBit(b){return new g(this.r,this.s,b)}recoverPublicKey(b){let I=s.ORDER,{r:L,s:N,recovery:K}=this;if(K==null||![0,1,2,3].includes(K))throw new Error("recovery id invalid");if(a*la<I&&K>1)throw new Error("recovery id is ambiguous for h>1 curve");let G=K===2||K===3?L+a:L;if(!s.isValid(G))throw new Error("recovery id 2 or 3 invalid");let F=s.toBytes(G),xt=r.fromHex(mt(ha((K&1)===0),F)),q=i.inv(G),tt=R(V("msgHash",b)),wt=i.create(-tt*q),Jt=i.create(N*q),fe=r.BASE.multiplyUnsafe(wt).add(xt.multiplyUnsafe(Jt));if(fe.is0())throw new Error("point at infinify");return fe.assertValidity(),fe}hasHighS(){return f(this.s)}normalizeS(){return this.hasHighS()?new g(this.r,i.neg(this.s),this.recovery):this}toBytes(b="compact"){if(b==="compact")return mt(i.toBytes(this.r),i.toBytes(this.s));if(b==="der")return be($t.hexFromSig(this));throw new Error("invalid format")}toHex(b){return At(this.toBytes(b))}assertValidity(){}static fromCompact(b){return g.fromBytes(V("sig",b),"compact")}static fromDER(b){return g.fromBytes(V("sig",b),"der")}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return At(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return At(this.toBytes("compact"))}}function x(w){try{return!!Ze(i,w)}catch{return!1}}function p(w,b){try{let I=w.length;return b===!0&&I!==d.public||b===!1&&I!==d.publicUncompressed?!1:!!r.fromBytes(w)}catch{return!1}}function S(w=n(u)){return go(w,a)}let B={isValidSecretKey:x,isValidPublicKey:p,randomSecretKey:S,isValidPrivateKey:x,randomPrivateKey:S,normPrivateKeyToScalar:w=>Ze(i,w),precompute(w=8,b=r.BASE){return b.precompute(w,!1)}};function v(w,b=!0){return r.BASE.multiply(Ze(i,w)).toBytes(b)}function T(w){if(typeof w=="bigint")return!1;if(w instanceof r)return!0;if(i.allowedLengths||d.secret===d.public)return;let b=V("key",w).length;return b===d.public||b===d.publicUncompressed}function C(w,b,I=!0){if(T(w)===!0)throw new Error("first arg must be private key");if(T(b)===!1)throw new Error("second arg must be public key");let L=Ze(i,w);return r.fromHex(b).multiply(L).toBytes(I)}let _=e.bits2int||function(w){if(w.length>8192)throw new Error("input is too large");let b=Oe(w),I=w.length*8-c;return I>0?b>>BigInt(I):b},R=e.bits2int_modN||function(w){return i.create(_(w))},U=ae(c);function D(w){return ie("num < 2^"+c,w,jt,U),i.toBytes(w)}function y(w,b,I=m){if(["recovered","canonical"].some(wt=>wt in I))throw new Error("sign() legacy options not supported");let{lowS:L,prehash:N,extraEntropy:K}=I;L==null&&(L=!0),w=V("msgHash",w),fa(I),N&&(w=V("prehashed msgHash",t(w)));let M=R(w),G=Ze(i,b),F=[D(G),D(M)];if(K!=null&&K!==!1){let wt=K===!0?n(d.secret):K;F.push(V("extraEntropy",wt))}let xt=mt(...F),q=M;function tt(wt){let Jt=_(wt);if(!i.isValidNot0(Jt))return;let fe=i.inv(Jt),We=r.BASE.multiply(Jt).toAffine(),le=i.create(We.x);if(le===jt)return;let Je=i.create(fe*i.create(q+le*G));if(Je===jt)return;let vs=(We.x===le?0:2)|Number(We.y&Ye),As=Je;return L&&f(Je)&&(As=l(Je),vs^=1),new g(le,As,vs)}return{seed:xt,k2sig:tt}}let m={lowS:e.lowS,prehash:!1},E={lowS:e.lowS,prehash:!1};function A(w,b,I=m){let{seed:L,k2sig:N}=y(w,b,I);return xi(t.outputLen,i.BYTES,o)(L,N)}r.BASE.precompute(8);function P(w,b,I,L=E){let N=w;b=V("msgHash",b),I=V("publicKey",I),fa(L);let{lowS:K,prehash:M,format:G}=L;if("strict"in L)throw new Error("options.strict was renamed to lowS");let F,xt;if(G===void 0){let q=typeof N=="string"||ye(N),tt=!q&&N!==null&&typeof N=="object"&&typeof N.r=="bigint"&&typeof N.s=="bigint";if(!q&&!tt)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(tt)F=new g(N.r,N.s);else if(q){try{F=g.fromDER(N)}catch(wt){if(!(wt instanceof $t.Err))throw wt}if(!F)try{F=g.fromCompact(N)}catch{return!1}}}else if(G==="compact"||G==="der"){if(typeof N!="string"&&!ye(N))throw new Error('"der" / "compact" format expects Uint8Array signature');F=g.fromBytes(V("sig",N),G)}else if(G==="js"){if(!(N instanceof g))throw new Error('"js" format expects Signature instance');F=N}else throw new Error('format must be "compact", "der" or "js"');if(!F)return!1;try{if(xt=r.fromHex(I),K&&F.hasHighS())return!1;M&&(b=t(b));let{r:q,s:tt}=F,wt=R(b),Jt=i.inv(tt),fe=i.create(wt*Jt),We=i.create(q*Jt),le=r.BASE.multiplyUnsafe(fe).add(xt.multiplyUnsafe(We));return le.is0()?!1:i.create(le.x)===q}catch{return!1}}function k(w){let b=B.randomSecretKey(w);return{secretKey:b,publicKey:v(b)}}return Object.freeze({keygen:k,getPublicKey:v,sign:A,verify:P,getSharedSecret:C,utils:B,Point:r,Signature:g,info:{type:"weierstrass",lengths:d,publicKeyHasPrefix:!0}})}function Lf(r){let t={a:r.a,b:r.b,p:r.Fp.ORDER,n:r.n,h:r.h,Gx:r.Gx,Gy:r.Gy},e=r.Fp,n=r.allowedPrivateKeyLengths?Array.from(new Set(r.allowedPrivateKeyLengths.map(i=>Math.ceil(i/2)))):void 0,o=Et(t.n,{BITS:r.nBitLength,allowedLengths:n,modOnDecode:r.wrapPrivateKey}),s={Fp:e,Fn:o,allowInfinityPoint:r.allowInfinityPoint,endo:r.endo,isTorsionFree:r.isTorsionFree,clearCofactor:r.clearCofactor,fromBytes:r.fromBytes,toBytes:r.toBytes};return{CURVE:t,curveOpts:s}}function Tf(r){let{CURVE:t,curveOpts:e}=Lf(r),n={hmac:r.hmac,randomBytes:r.randomBytes,lowS:r.lowS,bits2int:r.bits2int,bits2int_modN:r.bits2int_modN};return{CURVE:t,curveOpts:e,hash:r.hash,ecdsaOpts:n}}function Df(r,t){return Object.assign({},t,{ProjectivePoint:t.Point,CURVE:r})}function da(r){let{CURVE:t,curveOpts:e,hash:n,ecdsaOpts:o}=Tf(r),s=Bf(t,e),i=_f(s,n,o);return Df(r,i)}function pa(r,t){let e=n=>da({...r,hash:n});return{...e(t),create:e}}var cs={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Pf={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var ma=BigInt(2);function kf(r){let t=cs.p,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=r*r*r%t,d=u*u*r%t,f=Z(d,e,t)*d%t,l=Z(f,e,t)*d%t,h=Z(l,ma,t)*u%t,g=Z(h,o,t)*h%t,x=Z(g,s,t)*g%t,p=Z(x,a,t)*x%t,S=Z(p,c,t)*p%t,B=Z(S,a,t)*x%t,v=Z(B,e,t)*d%t,T=Z(v,i,t)*g%t,C=Z(T,n,t)*u%t,_=Z(C,ma,t);if(!as.eql(as.sqr(_),r))throw new Error("Cannot find square root");return _}var as=Et(cs.p,void 0,void 0,{sqrt:kf}),Xe=pa({...cs,Fp:as,lowS:!0,endo:Pf},Zr);function ya(r,t,e,n){let o=pe.digest(e instanceof Uint8Array?e:e.subarray());if(Qr(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Xe.verify(t,s,r))).catch(s=>{throw s.name==="AbortError"?s:new mr(String(s))});try{return n?.signal?.throwIfAborted(),Xe.verify(t,o.digest,r)}catch(s){throw new mr(String(s))}}var un=class{type="secp256k1";raw;_key;constructor(t){this._key=ga(t),this.raw=ba(this._key)}toMultihash(){return Lt.digest(Mt(this))}toCID(){return st.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:dt(this.raw,t.raw)}verify(t,e,n){return ya(this._key,e,t,n)}};function us(r){return new un(r)}function ba(r){return Xe.ProjectivePoint.fromHex(r).toRawBytes(!0)}function ga(r){try{return Xe.ProjectivePoint.fromHex(r),r}catch(t){throw new Te(String(t))}}function fs(r,t){let{Type:e,Data:n}=Nt.decode(r),o=n??new Uint8Array;switch(e){case Q.RSA:return rs(o,t);case Q.Ed25519:return To(o);case Q.secp256k1:return us(o);case Q.ECDSA:return so(o);default:throw new he}}function xa(r){let{Type:t,Data:e}=Nt.decode(r.digest),n=e??new Uint8Array;switch(t){case Q.Ed25519:return To(n);case Q.secp256k1:return us(n);case Q.ECDSA:return so(n);default:throw new he}}function Mt(r){return Nt.encode({Type:Q[r.type],Data:r.raw})}var wa=Symbol.for("nodejs.util.inspect.custom"),Cf=114,wr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Pn]=!0;toString(){return this.string==null&&(this.string=X.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return st.createV1(Cf,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return dt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return dt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[wa](){return`PeerId(${this.toString()})`}},Er=class extends wr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Sr=class extends wr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},vr=class extends wr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Nf=2336,fn=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Lt.digest(z(this.url))}[wa](){return`PeerId(${this.url})`}[Pn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return st.createV1(Nf,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=H(t)),t.toString()===this.toString())}};function ls(r){if(r.type==="Ed25519")return new Sr({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new vr({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new Er({multihash:r.toCID().multihash,publicKey:r});throw new he}function Ea(r){return ls(r.publicKey)}function Ar(r){if(Rf(r))return new Er({multihash:r});if(Kf(r))try{let t=xa(r);if(t.type==="Ed25519")return new Sr({multihash:r,publicKey:t});if(t.type==="secp256k1")return new vr({multihash:r,publicKey:t})}catch{let e=H(r.digest);return new fn(new URL(e))}throw new Rr("Supplied PeerID Multihash is invalid")}function Kf(r){return r.code===Lt.code}function Rf(r){return r.code===pe.code}function Be(r,t){let e={[Symbol.iterator]:()=>e,next:()=>{let n=r.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return e}function ln(r){let t=te(X.decode(`z${r}`));return Ar(t)}var Ir=class{map;constructor(t){if(this.map=new Map,t!=null)for(let[e,n]of t.entries())this.map.set(e.toString(),{key:e,value:n})}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(t){return this.map.delete(t.toString())}entries(){return Be(this.map.entries(),t=>[t[1].key,t[1].value])}forEach(t){this.map.forEach((e,n)=>{t(e.value,e.key,this)})}get(t){return this.map.get(t.toString())?.value}has(t){return this.map.has(t.toString())}set(t,e){this.map.set(t.toString(),{key:t,value:e})}keys(){return Be(this.map.values(),t=>t.key)}values(){return Be(this.map.values(),t=>t.value)}get size(){return this.map.size}};var Br=class r{set;constructor(t){if(this.set=new Set,t!=null)for(let e of t)this.set.add(e.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(t){this.set.add(t.toString())}clear(){this.set.clear()}delete(t){this.set.delete(t.toString())}entries(){return Be(this.set.entries(),t=>{let e=ln(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=ln(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return Be(this.set.values(),t=>ln(t))}intersection(t){let e=new r;for(let n of t)this.has(n)&&e.add(n);return e}difference(t){let e=new r;for(let n of this)t.has(n)||e.add(n);return e}union(t){let e=new r;for(let n of t)e.add(n);for(let n of this)e.add(n);return e}};function Wt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var hn=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},$e=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new hn(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new hn(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var hs=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function dn(r={}){return Uf(e=>{let n=e.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function Uf(r,t){t=t??{};let e=t.onEnd,n=new $e,o,s,i,a=Wt(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((p,S)=>{s=B=>{s=null,n.push(B);try{p(r(n))}catch(v){S(v)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Wt()})}},u=p=>s!=null?s(p):(n.push(p),o),d=p=>(n=new $e,s!=null?s({error:p}):(n.push({error:p}),o)),f=p=>{if(i)return o;if(t?.objectMode!==!0&&p?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:p})},l=p=>i?o:(i=!0,p!=null?d(p):u({done:!0})),h=()=>(n=new $e,l(),{done:!0}),g=p=>(l(p),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:h,throw:g,push:f,end:l,get readableLength(){return n.size},onEmpty:async p=>{let S=p?.signal;if(S?.throwIfAborted(),n.isEmpty())return;let B,v;S!=null&&(B=new Promise((T,C)=>{v=()=>{C(new hs)},S.addEventListener("abort",v)}));try{await Promise.race([a.promise,B])}finally{v!=null&&S!=null&&S?.removeEventListener("abort",v)}}},e==null)return o;let x=o;return o={[Symbol.asyncIterator](){return this},next(){return x.next()},throw(p){return x.throw(p),e!=null&&(e(p),e=void 0),{done:!0}},return(){return x.return(),e!=null&&(e(),e=void 0),{done:!0}},push:f,end(p){return x.end(p),e!=null&&(e(p),e=void 0),o},get readableLength(){return x.readableLength},onEmpty:p=>x.onEmpty(p)},o}var pn=class extends Error{type;code;constructor(t,e,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=e??"ABORT_ERR"}};async function Sa(r,t,e){if(t==null)return r;if(t.aborted)return r.catch(()=>{}),Promise.reject(new pn(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new pn(e?.errorMessage,e?.errorCode,e?.errorName);try{return await Promise.race([r,new Promise((s,i)=>{n=()=>{i(o)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var ds=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=Wt(),this.haveNext=Wt()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let t=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=Wt(),t}async throw(t){return this.ended=!0,this.error=t,t!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(t)),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return this.ended=!0,this.nextResult=t,this.haveNext.resolve(),t}async push(t,e){await this._push(t,e)}async end(t,e){t!=null?await this.throw(t):await this._push(void 0,e)}async _push(t,e){if(t!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=Wt(),await Sa(this.readNext.promise,e?.signal,e)}};function va(){return new ds}function Mf(r){return r[Symbol.asyncIterator]!=null}async function Of(r,t,e){try{await Promise.all(r.map(async n=>{for await(let o of n)await t.push(o,{signal:e}),e.throwIfAborted()})),await t.end(void 0,{signal:e})}catch(n){await t.end(n,{signal:e}).catch(()=>{})}}async function*qf(r){let t=new AbortController,e=va();Of(r,e,t.signal).catch(()=>{});try{yield*e}finally{t.abort()}}function*Hf(r){for(let t of r)yield*t}function Vf(...r){let t=[];for(let e of r)Mf(e)||t.push(e);return t.length===r.length?Hf(t):qf(r)}var Aa=Vf;function _r(r,...t){if(r==null)throw new Error("Empty pipeline");if(ps(r)){let n=r;r=()=>n.source}else if(Ba(r)||Ia(r)){let n=r;r=()=>n}let e=[r,...t];if(e.length>1&&ps(e[e.length-1])&&(e[e.length-1]=e[e.length-1].sink),e.length>2)for(let n=1;n<e.length-1;n++)ps(e[n])&&(e[n]=zf(e[n]));return Ff(...e)}var Ff=(...r)=>{let t;for(;r.length>0;)t=r.shift()(t);return t},Ia=r=>r?.[Symbol.asyncIterator]!=null,Ba=r=>r?.[Symbol.iterator]!=null,ps=r=>r==null?!1:r.sink!=null&&r.source!=null,zf=r=>t=>{let e=r.sink(t);if(e?.then!=null){let n=dn({objectMode:!0});e.then(()=>{n.end()},i=>{n.end(i)});let o,s=r.source;if(Ia(s))o=async function*(){yield*s,n.end()};else if(Ba(s))o=function*(){yield*s,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return Aa(n,o())}return r.source};var ys=$a(La(),1);var Tr=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},bs=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},Ta=r=>globalThis.DOMException===void 0?new bs(r):new DOMException(r),Da=r=>{let t=r.reason===void 0?Ta("This operation was aborted."):r.reason;return t instanceof Error?t:Ta(t)};function gs(r,t){let{milliseconds:e,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=t,i,a,u=new Promise((d,f)=>{if(typeof e!="number"||Math.sign(e)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${e}\``);if(t.signal){let{signal:h}=t;h.aborted&&f(Da(h)),a=()=>{f(Da(h))},h.addEventListener("abort",a,{once:!0})}if(e===Number.POSITIVE_INFINITY){r.then(d,f);return}let l=new Tr;i=s.setTimeout.call(void 0,()=>{if(n){try{d(n())}catch(h){f(h)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?d():o instanceof Error?f(o):(l.message=o??`Promise timed out after ${e} milliseconds`,f(l))},e),(async()=>{try{d(await r)}catch(h){f(h)}})()}).finally(()=>{u.clear(),a&&t.signal&&t.signal.removeEventListener("abort",a)});return u.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},u}function xs(r,t,e){let n=0,o=r.length;for(;o>0;){let s=Math.trunc(o/2),i=n+s;e(r[i],t)<=0?(n=++i,o-=s+1):o=s}return n}var Dr=class{#t=[];enqueue(t,e){e={priority:0,...e};let n={priority:e.priority,id:e.id,run:t};if(this.size===0||this.#t[this.size-1].priority>=e.priority){this.#t.push(n);return}let o=xs(this.#t,n,(s,i)=>i.priority-s.priority);this.#t.splice(o,0,n)}setPriority(t,e){let n=this.#t.findIndex(s=>s.id===t);if(n===-1)throw new ReferenceError(`No promise function with the id "${t}" exists in the queue.`);let[o]=this.#t.splice(n,1);this.enqueue(o.run,{priority:e,id:t})}dequeue(){return this.#t.shift()?.run}filter(t){return this.#t.filter(e=>e.priority===t.priority).map(e=>e.run)}get size(){return this.#t.length}};var Pr=class extends ys.default{#t;#i;#s=0;#d;#a;#p=0;#r;#c;#e;#m;#n=0;#u;#o;#y;#x=1n;timeout;constructor(t){if(super(),t={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Dr,...t},!(typeof t.intervalCap=="number"&&t.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${t.intervalCap?.toString()??""}\` (${typeof t.intervalCap})`);if(t.interval===void 0||!(Number.isFinite(t.interval)&&t.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${t.interval?.toString()??""}\` (${typeof t.interval})`);this.#t=t.carryoverConcurrencyCount,this.#i=t.intervalCap===Number.POSITIVE_INFINITY||t.interval===0,this.#d=t.intervalCap,this.#a=t.interval,this.#e=new t.queueClass,this.#m=t.queueClass,this.concurrency=t.concurrency,this.timeout=t.timeout,this.#y=t.throwOnTimeout===!0,this.#o=t.autoStart===!1}get#w(){return this.#i||this.#s<this.#d}get#E(){return this.#n<this.#u}#S(){this.#n--,this.#f(),this.emit("next")}#v(){this.#g(),this.#b(),this.#c=void 0}get#A(){let t=Date.now();if(this.#r===void 0){let e=this.#p-t;if(e<0)this.#s=this.#t?this.#n:0;else return this.#c===void 0&&(this.#c=setTimeout(()=>{this.#v()},e)),!0}return!1}#f(){if(this.#e.size===0)return this.#r&&clearInterval(this.#r),this.#r=void 0,this.emit("empty"),this.#n===0&&this.emit("idle"),!1;if(!this.#o){let t=!this.#A;if(this.#w&&this.#E){let e=this.#e.dequeue();return e?(this.emit("active"),e(),t&&this.#b(),!0):!1}}return!1}#b(){this.#i||this.#r!==void 0||(this.#r=setInterval(()=>{this.#g()},this.#a),this.#p=Date.now()+this.#a)}#g(){this.#s===0&&this.#n===0&&this.#r&&(clearInterval(this.#r),this.#r=void 0),this.#s=this.#t?this.#n:0,this.#l()}#l(){for(;this.#f(););}get concurrency(){return this.#u}set concurrency(t){if(!(typeof t=="number"&&t>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${t}\` (${typeof t})`);this.#u=t,this.#l()}async#I(t){return new Promise((e,n)=>{t.addEventListener("abort",()=>{n(t.reason)},{once:!0})})}setPriority(t,e){this.#e.setPriority(t,e)}async add(t,e={}){return e.id??=(this.#x++).toString(),e={timeout:this.timeout,throwOnTimeout:this.#y,...e},new Promise((n,o)=>{this.#e.enqueue(async()=>{this.#n++,this.#s++;try{e.signal?.throwIfAborted();let s=t({signal:e.signal});e.timeout&&(s=gs(Promise.resolve(s),{milliseconds:e.timeout})),e.signal&&(s=Promise.race([s,this.#I(e.signal)]));let i=await s;n(i),this.emit("completed",i)}catch(s){if(s instanceof Tr&&!e.throwOnTimeout){n();return}o(s),this.emit("error",s)}finally{this.#S()}},e),this.emit("add"),this.#f()})}async addAll(t,e){return Promise.all(t.map(async n=>this.add(n,e)))}start(){return this.#o?(this.#o=!1,this.#l(),this):this}pause(){this.#o=!0}clear(){this.#e=new this.#m}async onEmpty(){this.#e.size!==0&&await this.#h("empty")}async onSizeLessThan(t){this.#e.size<t||await this.#h("next",()=>this.#e.size<t)}async onIdle(){this.#n===0&&this.#e.size===0||await this.#h("idle")}async#h(t,e){return new Promise(n=>{let o=()=>{e&&!e()||(this.off(t,o),n())};this.on(t,o)})}get size(){return this.#e.size}sizeBy(t){return this.#e.filter(t).length}get pending(){return this.#n}get isPaused(){return this.#o}};function Pa(r){if(r!=null){if(typeof r[Symbol.iterator]=="function")return r[Symbol.iterator]();if(typeof r[Symbol.asyncIterator]=="function")return r[Symbol.asyncIterator]();if(typeof r.next=="function")return r}throw new Error("argument is not an iterator or iterable")}function ka(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Ca(r,t){let e=Pa(r).return?.();ka(e)&&e.catch(n=>{t.error("could not cause iterator to return",n)})}var yn=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},je=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},bn=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},kr=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function gn(r){return r[Symbol.asyncIterator]!=null}function Na(r,t){if(r.byteLength>t)throw new je("Message length too long")}var wn=r=>{let t=Dt(r),e=it(t);return zi(r,e),wn.bytes=t,e};wn.bytes=0;function En(r,t){t=t??{};let e=t.lengthEncoder??wn,n=t?.maxDataLength??4194304;function*o(s){Na(s,n);let i=e(s.byteLength);i instanceof Uint8Array?yield i:yield*i,s instanceof Uint8Array?yield s:yield*s}return gn(r)?async function*(){for await(let s of r)yield*o(s)}():function*(){for(let s of r)yield*o(s)}()}En.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??wn,n=t?.maxDataLength??4194304;return Na(r,n),new et(e(r.byteLength),r)};var _e;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(_e||(_e={}));var ws=r=>{let t=Gi(r);return ws.bytes=Dt(t),t};ws.bytes=0;function Cr(r,t){let e=new et,n=_e.LENGTH,o=-1,s=t?.lengthDecoder??ws,i=t?.maxLengthLength??8,a=t?.maxDataLength??4194304;function*c(){for(;e.byteLength>0;){if(n===_e.LENGTH)try{if(o=s(e),o<0)throw new yn("Invalid message length");if(o>a)throw new je("Message length too long");let u=s.bytes;e.consume(u),t?.onLength!=null&&t.onLength(o),n=_e.DATA}catch(u){if(u instanceof RangeError){if(e.byteLength>i)throw new bn("Message length length too long");break}throw u}if(n===_e.DATA){if(e.byteLength<o)break;let u=e.sublist(0,o);e.consume(o),t?.onData!=null&&t.onData(u),yield u,n=_e.LENGTH}}}return gn(r)?async function*(){for await(let u of r)e.append(u),yield*c();if(e.byteLength>0)throw new kr("Unexpected end of input")}():function*(){for(let u of r)e.append(u),yield*c();if(e.byteLength>0)throw new kr("Unexpected end of input")}()}Cr.fromReader=(r,t)=>{let e=1,n=async function*(){for(;;)try{let{done:s,value:i}=await r.next(e);if(s===!0)return;i!=null&&(yield i)}catch(s){if(s.code==="ERR_UNDER_READ")return{done:!0,value:null};throw s}finally{e=1}}();return Cr(n,{...t??{},onLength:s=>{e=s}})};var Sn=class extends De{id;protocol;outboundStream;inboundStream;_rawOutboundStream;_rawInboundStream;_inboundAbortController;closed;log;constructor(t,e){super(),this.log=t.logger.forComponent("libp2p-pubsub:peer-streams"),this.id=e.id,this.protocol=e.protocol,this._inboundAbortController=new AbortController,this.closed=!1}get isReadable(){return!!this.inboundStream}get isWritable(){return!!this.outboundStream}write(t){if(this.outboundStream==null){let e=this.id.toString();throw new Error("No writable connection to "+e)}this.outboundStream.push(t instanceof Uint8Array?new et(t):t)}attachInboundStream(t,e){let n=()=>{Ca(t.source,this.log)};return this._inboundAbortController.signal.addEventListener("abort",n,{once:!0}),this._rawInboundStream=t,this.inboundStream=_r(this._rawInboundStream,o=>Cr(o,e)),this.dispatchEvent(new CustomEvent("stream:inbound")),this.inboundStream}async attachOutboundStream(t){let e=this.outboundStream;return this.outboundStream!=null&&this.outboundStream.end(),this._rawOutboundStream=t,this.outboundStream=dn({onEnd:n=>{this._rawOutboundStream?.closeWrite().catch(o=>{this.log("error closing outbound stream",o)}),this._rawOutboundStream=void 0,this.outboundStream=void 0,n!=null&&this.dispatchEvent(new CustomEvent("close"))}}),_r(this.outboundStream,n=>En(n),this._rawOutboundStream).catch(n=>{this.log.error(n)}),e==null&&this.dispatchEvent(new CustomEvent("stream:outbound")),this.outboundStream}close(){this.closed||(this.closed=!0,this.outboundStream!=null&&this.outboundStream.end(),this.inboundStream!=null&&this._inboundAbortController.abort(),this._rawOutboundStream=void 0,this.outboundStream=void 0,this._rawInboundStream=void 0,this.inboundStream=void 0,this.dispatchEvent(new CustomEvent("close")))}};function Ka(){return BigInt(`0x${H(on(8),"base16")}`)}var Ra=(r,t)=>{let e=z(t.toString(16).padStart(16,"0"),"base16"),n=Mt(r),o=new Uint8Array(n.byteLength+e.length);return o.set(n,0),o.set(e,n.byteLength),o},Ua=r=>pe.encode(r);var Ma=function(r){return Array.isArray(r)?r:[r]},$f=async r=>{if(r.sequenceNumber==null||r.from==null||r.signature==null)return!1;let t=Ar(te(r.from));if(t.publicKey!=null)return!0;if(r.key!=null){let e=r.key;return ls(fs(e)).equals(t)}return!1},Oa=async r=>{if(r.from==null)throw new J("RPC message was missing from");if(!await $f(r))return{type:"unsigned",topic:r.topic??"",data:r.data??new Uint8Array(0)};let t=Ar(te(r.from)),e=r.key??t.publicKey;if(e==null)throw new J("RPC message was missing public key");return{type:"signed",from:t,topic:r.topic??"",sequenceNumber:Wf(r.sequenceNumber??new Uint8Array(0)),data:r.data??new Uint8Array(0),signature:r.signature??new Uint8Array(0),key:e instanceof Uint8Array?fs(e):e}},Nr=r=>r.type==="signed"?{from:r.from.toMultihash().bytes,data:r.data,sequenceNumber:jf(r.sequenceNumber),topic:r.topic,signature:r.signature,key:r.key?Mt(r.key):void 0}:{data:r.data,topic:r.topic},jf=r=>{let t=r.toString(16);return t.length%2!==0&&(t=`0${t}`),z(t,"base16")},Wf=r=>BigInt(`0x${H(r,"base16")}`);var qa=z("libp2p-pubsub:");async function Ha(r,t,e){let n={type:"signed",topic:t.topic,data:t.data,sequenceNumber:t.sequenceNumber,from:Ea(r)},o=de([qa,e(Nr(n)).subarray()]);return n.signature=await r.sign(o),n.key=r.publicKey,n}async function Va(r,t){if(r.type!=="signed")throw new Error('Message type must be "signed" to be verified');if(r.signature==null)throw new Error("Message must contain a signature to be verified");if(r.from==null)throw new Error("Message must contain a from property to be verified");let e=de([qa,t({...Nr(r),signature:void 0,key:void 0}).subarray()]);return Jf(r).verify(e,r.signature)}function Jf(r){if(r.type!=="signed")throw new Error('Message type must be "signed" to have a public key');if(r.from==null)throw new Error("Could not get the public key from the originator id");if(r.key!=null)return r.key;if(r.from.publicKey!=null)return r.from.publicKey;throw new Error("Could not get the public key from the originator id")}var vn=class extends De{log;started;topics;subscriptions;peers;globalSignaturePolicy;canRelayMessage;emitSelf;topicValidators;queue;multicodecs;components;_registrarTopologyIds;enabled;maxInboundStreams;maxOutboundStreams;constructor(t,e){super();let{multicodecs:n=[],globalSignaturePolicy:o="StrictSign",canRelayMessage:s=!1,emitSelf:i=!1,messageProcessingConcurrency:a=10,maxInboundStreams:c=1,maxOutboundStreams:u=1}=e;this.log=t.logger.forComponent("libp2p:pubsub"),this.components=t,this.multicodecs=Ma(n),this.enabled=e.enabled!==!1,this.started=!1,this.topics=new Map,this.subscriptions=new Set,this.peers=new Ir,this.globalSignaturePolicy=o==="StrictNoSign"?"StrictNoSign":"StrictSign",this.canRelayMessage=s,this.emitSelf=i,this.topicValidators=new Map,this.queue=new Pr({concurrency:a}),this.maxInboundStreams=c,this.maxOutboundStreams=u,this._onIncomingStream=this._onIncomingStream.bind(this),this._onPeerConnected=this._onPeerConnected.bind(this),this._onPeerDisconnected=this._onPeerDisconnected.bind(this)}async start(){if(this.started||!this.enabled)return;this.log("starting");let t=this.components.registrar;await Promise.all(this.multicodecs.map(async n=>{await t.handle(n,this._onIncomingStream,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams})}));let e={onConnect:this._onPeerConnected,onDisconnect:this._onPeerDisconnected};this._registrarTopologyIds=await Promise.all(this.multicodecs.map(async n=>t.register(n,e))),this.log("started"),this.started=!0}async stop(){if(!this.started||!this.enabled)return;let t=this.components.registrar;this._registrarTopologyIds!=null&&this._registrarTopologyIds?.forEach(e=>{t.unregister(e)}),await Promise.all(this.multicodecs.map(async e=>{await t.unhandle(e)})),this.log("stopping");for(let e of this.peers.values())e.close();this.peers.clear(),this.subscriptions=new Set,this.started=!1,this.log("stopped")}isStarted(){return this.started}_onIncomingStream(t){let{stream:e,connection:n}=t,o=n.remotePeer;if(e.protocol==null){e.abort(new Error("Stream was not multiplexed"));return}let s=this.addPeer(o,e.protocol),i=s.attachInboundStream(e);this.processMessages(o,i,s).catch(a=>{this.log(a)})}_onPeerConnected(t,e){if(this.log("connected %p",t),e.streams.find(n=>n.direction==="outbound"&&n.protocol!=null&&this.multicodecs.includes(n.protocol))!=null){this.log("outbound pubsub streams already present on connection from %p",t);return}Promise.resolve().then(async()=>{try{let n=await e.newStream(this.multicodecs);if(n.protocol==null){n.abort(new Error("Stream was not multiplexed"));return}await this.addPeer(t,n.protocol).attachOutboundStream(n)}catch(n){this.log.error(n)}this.send(t,{subscriptions:Array.from(this.subscriptions).map(n=>n.toString()),subscribe:!0})}).catch(n=>{this.log.error(n)})}_onPeerDisconnected(t,e){this.log("connection ended %p",t),this._removePeer(t)}addPeer(t,e){let n=this.peers.get(t);if(n!=null)return n;this.log("new peer %p",t);let o=new Sn(this.components,{id:t,protocol:e});return this.peers.set(t,o),o.addEventListener("close",()=>this._removePeer(t),{once:!0}),o}_removePeer(t){let e=this.peers.get(t);if(e!=null){e.close(),this.log("delete peer %p",t),this.peers.delete(t);for(let n of this.topics.values())n.delete(t);return e}}async processMessages(t,e,n){try{await _r(e,async o=>{for await(let s of o){let i=this.decodeRpc(s),a=[];for(let c of i.messages??[]){if(c.from==null||c.data==null||c.topic==null){this.log("message from %p was missing from, data or topic fields, dropping",t);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(t,n,{subscriptions:(i.subscriptions??[]).map(c=>({subscribe:!!c.subscribe,topic:c.topic??""})),messages:a}).catch(c=>{this.log(c)})}})}catch(o){this._onPeerDisconnected(n.id,o)}}async processRpc(t,e,n){if(!this.acceptFrom(t))return this.log("received message from unacceptable peer %p",t),!1;this.log("rpc from %p",t);let{subscriptions:o,messages:s}=n;return o!=null&&o.length>0&&(this.log("subscription update from %p",t),o.forEach(i=>{this.processRpcSubOpt(t,i)}),super.dispatchEvent(new CustomEvent("subscription-change",{detail:{peerId:e.id,subscriptions:o.map(({topic:i,subscribe:a})=>({topic:`${i??""}`,subscribe:!!a}))}}))),s!=null&&s.length>0&&(this.log("messages from %p",t),this.queue.addAll(s.map(i=>async()=>{if(i.topic==null||!this.subscriptions.has(i.topic)&&!this.canRelayMessage)return this.log("received message we didn't subscribe to. Dropping."),!1;try{let a=await Oa(i);await this.processMessage(t,a)}catch(a){this.log.error(a)}})).catch(i=>{this.log(i)})),!0}processRpcSubOpt(t,e){let n=e.topic;if(n==null)return;let o=this.topics.get(n);o==null&&(o=new Br,this.topics.set(n,o)),e.subscribe===!0?o.add(t):o.delete(t)}async processMessage(t,e){if(!(this.components.peerId.equals(t)&&!this.emitSelf)){try{await this.validate(t,e)}catch(n){this.log("Message is invalid, dropping it. %O",n);return}this.subscriptions.has(e.topic)&&(!this.components.peerId.equals(t)||this.emitSelf)&&super.dispatchEvent(new CustomEvent("message",{detail:e})),await this.publishMessage(t,e)}}getMsgId(t){switch(this.globalSignaturePolicy){case"StrictSign":if(t.type!=="signed")throw new J('Message type should be "signed" when signature policy is StrictSign but it was not');if(t.sequenceNumber==null)throw new J("Need sequence number when signature policy is StrictSign but it was missing");if(t.key==null)throw new J("Need key when signature policy is StrictSign but it was missing");return Ra(t.key,t.sequenceNumber);case"StrictNoSign":return Ua(t.data);default:throw new J("Cannot get message id: unhandled signature policy")}}acceptFrom(t){return!0}send(t,e){let{messages:n,subscriptions:o,subscribe:s}=e;this.sendRpc(t,{subscriptions:(o??[]).map(i=>({topic:i,subscribe:!!s})),messages:(n??[]).map(Nr)})}sendRpc(t,e){let n=this.peers.get(t);if(n==null){this.log.error("Cannot send RPC to %p as there are no streams to it available",t);return}if(!n.isWritable){this.log.error("Cannot send RPC to %p as there is no outbound stream to it available",t);return}n.write(this.encodeRpc(e))}async validate(t,e){switch(this.globalSignaturePolicy){case"StrictNoSign":if(e.type!=="unsigned")throw new J('Message type should be "unsigned" when signature policy is StrictNoSign but it was not');if(e.signature!=null)throw new J("StrictNoSigning: signature should not be present");if(e.key!=null)throw new J("StrictNoSigning: key should not be present");if(e.sequenceNumber!=null)throw new J("StrictNoSigning: seqno should not be present");break;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.signature==null)throw new J("StrictSigning: Signing required and no signature was present");if(e.sequenceNumber==null)throw new J("StrictSigning: Signing required and no sequenceNumber was present");if(!await Va(e,this.encodeMessage.bind(this)))throw new J("StrictSigning: Invalid message signature");break;default:throw new J("Cannot validate message: unhandled signature policy")}let o=this.topicValidators.get(e.topic);if(o!=null){let s=await o(t,e);if(s===Qe.Reject||s===Qe.Ignore)throw new J("Message validation failed")}}async buildMessage(t){switch(this.globalSignaturePolicy){case"StrictSign":return Ha(this.components.privateKey,t,this.encodeMessage.bind(this));case"StrictNoSign":return Promise.resolve({type:"unsigned",...t});default:throw new J("Cannot build message: unhandled signature policy")}}getSubscribers(t){if(!this.started)throw new Ur("not started yet");if(t==null)throw new Y("Topic is required");let e=this.topics.get(t.toString());return e==null?[]:Array.from(e.values())}async publish(t,e){if(!this.started)throw new Error("Pubsub has not started");let n={from:this.components.peerId,topic:t,data:e??new Uint8Array(0),sequenceNumber:Ka()};this.log("publish topic: %s from: %p data: %m",t,n.from,n.data);let o=await this.buildMessage(n),s=!1;this.emitSelf&&this.subscriptions.has(t)&&(s=!0,super.dispatchEvent(new CustomEvent("message",{detail:o})));let i=await this.publishMessage(this.components.peerId,o);return s&&(i.recipients=[...i.recipients,this.components.peerId]),i}subscribe(t){if(!this.started)throw new Error("Pubsub has not started");if(this.log("subscribe to topic: %s",t),!this.subscriptions.has(t)){this.subscriptions.add(t);for(let e of this.peers.keys())this.send(e,{subscriptions:[t],subscribe:!0})}}unsubscribe(t){if(!this.started)throw new Error("Pubsub is not started");super.removeEventListener(t);let e=this.subscriptions.has(t);if(this.log("unsubscribe from %s - am subscribed %s",t,e),e){this.subscriptions.delete(t);for(let n of this.peers.keys())this.send(n,{subscriptions:[t],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 An=class{entries;validityMs;lastPruneTime=0;constructor(t){this.entries=new Map,this.validityMs=t.validityMs}put(t,e){this.entries.set(t,{value:e,validUntilMs:Date.now()+this.validityMs}),this.prune()}prune(){let t=Date.now();if(!(t-this.lastPruneTime<200)){this.lastPruneTime=t;for(let[e,n]of this.entries.entries())if(n.validUntilMs<t)this.entries.delete(e);else break}}has(t){return this.entries.has(t)}get(t){let e=this.entries.get(t);return e!=null&&e.validUntilMs>=Date.now()?e.value:void 0}clear(){this.entries=new Map,this.lastPruneTime=0}};var Es="/floodsub/1.0.0";var Le;(function(r){let t;(function(o){let s;o.codec=()=>(s==null&&(s=gt((i,a,c={})=>{c.lengthDelimited!==!1&&a.fork(),i.subscribe!=null&&(a.uint32(8),a.bool(i.subscribe)),i.topic!=null&&(a.uint32(18),a.string(i.topic)),c.lengthDelimited!==!1&&a.ldelim()},(i,a,c={})=>{let u={},d=a==null?i.len:i.pos+a;for(;i.pos<d;){let f=i.uint32();switch(f>>>3){case 1:{u.subscribe=i.bool();break}case 2:{u.topic=i.string();break}default:{i.skipType(f&7);break}}}return u})),s),o.encode=i=>bt(i,o.codec()),o.decode=(i,a)=>yt(i,o.codec(),a)})(t=r.SubOpts||(r.SubOpts={}));let e;(function(o){let s;o.codec=()=>(s==null&&(s=gt((i,a,c={})=>{c.lengthDelimited!==!1&&a.fork(),i.from!=null&&(a.uint32(10),a.bytes(i.from)),i.data!=null&&(a.uint32(18),a.bytes(i.data)),i.sequenceNumber!=null&&(a.uint32(26),a.bytes(i.sequenceNumber)),i.topic!=null&&(a.uint32(34),a.string(i.topic)),i.signature!=null&&(a.uint32(42),a.bytes(i.signature)),i.key!=null&&(a.uint32(50),a.bytes(i.key)),c.lengthDelimited!==!1&&a.ldelim()},(i,a,c={})=>{let u={},d=a==null?i.len:i.pos+a;for(;i.pos<d;){let f=i.uint32();switch(f>>>3){case 1:{u.from=i.bytes();break}case 2:{u.data=i.bytes();break}case 3:{u.sequenceNumber=i.bytes();break}case 4:{u.topic=i.string();break}case 5:{u.signature=i.bytes();break}case 6:{u.key=i.bytes();break}default:{i.skipType(f&7);break}}}return u})),s),o.encode=i=>bt(i,o.codec()),o.decode=(i,a)=>yt(i,o.codec(),a)})(e=r.Message||(r.Message={}));let n;r.codec=()=>(n==null&&(n=gt((o,s,i={})=>{if(i.lengthDelimited!==!1&&s.fork(),o.subscriptions!=null)for(let a of o.subscriptions)s.uint32(10),r.SubOpts.codec().encode(a,s);if(o.messages!=null)for(let a of o.messages)s.uint32(18),r.Message.codec().encode(a,s);o.control!=null&&(s.uint32(26),In.codec().encode(o.control,s)),i.lengthDelimited!==!1&&s.ldelim()},(o,s,i={})=>{let a={subscriptions:[],messages:[]},c=s==null?o.len:o.pos+s;for(;o.pos<c;){let u=o.uint32();switch(u>>>3){case 1:{if(i.limits?.subscriptions!=null&&a.subscriptions.length===i.limits.subscriptions)throw new Bt('Decode error - map field "subscriptions" had too many elements');a.subscriptions.push(r.SubOpts.codec().decode(o,o.uint32(),{limits:i.limits?.subscriptions$}));break}case 2:{if(i.limits?.messages!=null&&a.messages.length===i.limits.messages)throw new Bt('Decode error - map field "messages" had too many elements');a.messages.push(r.Message.codec().decode(o,o.uint32(),{limits:i.limits?.messages$}));break}case 3:{a.control=In.codec().decode(o,o.uint32(),{limits:i.limits?.control});break}default:{o.skipType(u&7);break}}}return a})),n),r.encode=o=>bt(o,r.codec()),r.decode=(o,s)=>yt(o,r.codec(),s)})(Le||(Le={}));var In;(function(r){let t;r.codec=()=>(t==null&&(t=gt((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.ihave!=null)for(let s of e.ihave)n.uint32(10),Bn.codec().encode(s,n);if(e.iwant!=null)for(let s of e.iwant)n.uint32(18),_n.codec().encode(s,n);if(e.graft!=null)for(let s of e.graft)n.uint32(26),Ln.codec().encode(s,n);if(e.prune!=null)for(let s of e.prune)n.uint32(34),Tn.codec().encode(s,n);o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={ihave:[],iwant:[],graft:[],prune:[]},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{if(o.limits?.ihave!=null&&s.ihave.length===o.limits.ihave)throw new Bt('Decode error - map field "ihave" had too many elements');s.ihave.push(Bn.codec().decode(e,e.uint32(),{limits:o.limits?.ihave$}));break}case 2:{if(o.limits?.iwant!=null&&s.iwant.length===o.limits.iwant)throw new Bt('Decode error - map field "iwant" had too many elements');s.iwant.push(_n.codec().decode(e,e.uint32(),{limits:o.limits?.iwant$}));break}case 3:{if(o.limits?.graft!=null&&s.graft.length===o.limits.graft)throw new Bt('Decode error - map field "graft" had too many elements');s.graft.push(Ln.codec().decode(e,e.uint32(),{limits:o.limits?.graft$}));break}case 4:{if(o.limits?.prune!=null&&s.prune.length===o.limits.prune)throw new Bt('Decode error - map field "prune" had too many elements');s.prune.push(Tn.codec().decode(e,e.uint32(),{limits:o.limits?.prune$}));break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>bt(e,r.codec()),r.decode=(e,n)=>yt(e,r.codec(),n)})(In||(In={}));var Bn;(function(r){let t;r.codec=()=>(t==null&&(t=gt((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.topic!=null&&(n.uint32(10),n.string(e.topic)),e.messageIDs!=null)for(let s of e.messageIDs)n.uint32(18),n.bytes(s);o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={messageIDs:[]},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.topic=e.string();break}case 2:{if(o.limits?.messageIDs!=null&&s.messageIDs.length===o.limits.messageIDs)throw new Bt('Decode error - map field "messageIDs" had too many elements');s.messageIDs.push(e.bytes());break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>bt(e,r.codec()),r.decode=(e,n)=>yt(e,r.codec(),n)})(Bn||(Bn={}));var _n;(function(r){let t;r.codec=()=>(t==null&&(t=gt((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.messageIDs!=null)for(let s of e.messageIDs)n.uint32(10),n.bytes(s);o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={messageIDs:[]},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{if(o.limits?.messageIDs!=null&&s.messageIDs.length===o.limits.messageIDs)throw new Bt('Decode error - map field "messageIDs" had too many elements');s.messageIDs.push(e.bytes());break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>bt(e,r.codec()),r.decode=(e,n)=>yt(e,r.codec(),n)})(_n||(_n={}));var Ln;(function(r){let t;r.codec=()=>(t==null&&(t=gt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.topic!=null&&(n.uint32(10),n.string(e.topic)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.topic=e.string();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>bt(e,r.codec()),r.decode=(e,n)=>yt(e,r.codec(),n)})(Ln||(Ln={}));var Tn;(function(r){let t;r.codec=()=>(t==null&&(t=gt((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.topic!=null&&(n.uint32(10),n.string(e.topic)),e.peers!=null)for(let s of e.peers)n.uint32(18),Dn.codec().encode(s,n);e.backoff!=null&&(n.uint32(24),n.uint64(e.backoff)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={peers:[]},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.topic=e.string();break}case 2:{if(o.limits?.peers!=null&&s.peers.length===o.limits.peers)throw new Bt('Decode error - map field "peers" had too many elements');s.peers.push(Dn.codec().decode(e,e.uint32(),{limits:o.limits?.peers$}));break}case 3:{s.backoff=e.uint64();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>bt(e,r.codec()),r.decode=(e,n)=>yt(e,r.codec(),n)})(Tn||(Tn={}));var Dn;(function(r){let t;r.codec=()=>(t==null&&(t=gt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.peerID!=null&&(n.uint32(10),n.bytes(e.peerID)),e.signedPeerRecord!=null&&(n.uint32(18),n.bytes(e.signedPeerRecord)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{s.peerID=e.bytes();break}case 2:{s.signedPeerRecord=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>bt(e,r.codec()),r.decode=(e,n)=>yt(e,r.codec(),n)})(Dn||(Dn={}));var Ss=class extends vn{seenCache;constructor(t,e){super(t,{...e,canRelayMessage:!0,multicodecs:[Es]}),this.log=t.logger.forComponent("libp2p:floodsub"),this.seenCache=new An({validityMs:e?.seenTTL??3e4})}[Bs]=!0;[Symbol.toStringTag]="@libp2p/floodsub";[_s]=["@libp2p/pubsub"];[Ls]=["@libp2p/identify"];decodeRpc(t){return Le.decode(t)}encodeRpc(t){return Le.encode(t)}decodeMessage(t){return Le.Message.decode(t)}encodeMessage(t){return Le.Message.encode(t)}async processMessage(t,e){let n=await super.getMsgId(e),o=H(n,"base64");this.seenCache.has(o)||(this.seenCache.put(o,!0),await super.processMessage(t,e))}async publishMessage(t,e){let n=this.getSubscribers(e.topic),o=[];return n==null||n.length===0?(this.log("no peers are subscribed to topic %s",e.topic),{recipients:o}):(n.forEach(s=>{if(this.components.peerId.equals(s)){this.log("not sending message on topic %s to myself",e.topic);return}if(s.equals(t)){this.log("not sending message on topic %s to sender %p",e.topic,s);return}this.log("publish msgs on topics %s %p",e.topic,s),o.push(s),this.send(s,{messages:[e]})}),{recipients:o})}};function Qf(r={}){return t=>new Ss(t,r)}return ja(tl);})();
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
@noble/hashes/esm/utils.js:
|