@libp2p/floodsub 11.0.0 → 11.0.1-39e2e541a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,18 +1,17 @@
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 $a=Object.create;var kr=Object.defineProperty;var Ya=Object.getOwnPropertyDescriptor;var Xa=Object.getOwnPropertyNames;var Wa=Object.getPrototypeOf,Ja=Object.prototype.hasOwnProperty;var Qa=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),yt=(r,t)=>{for(var e in t)kr(r,e,{get:t[e],enumerable:!0})},Ks=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Xa(t))!Ja.call(r,o)&&o!==e&&kr(r,o,{get:()=>t[o],enumerable:!(n=Ya(t,o))||n.enumerable});return r};var tc=(r,t,e)=>(e=r!=null?$a(Wa(r)):{},Ks(t||!r||!r.__esModule?kr(e,"default",{value:r,enumerable:!0}):e,r)),ec=r=>Ks(kr({},"__esModule",{value:!0}),r);var Ma=Qa((Fy,Ts)=>{"use strict";var nl=Object.prototype.hasOwnProperty,pt="~";function Pr(){}Object.create&&(Pr.prototype=Object.create(null),new Pr().__proto__||(pt=!1));function ol(r,t,e){this.fn=r,this.context=t,this.once=e||!1}function Ua(r,t,e,n,o){if(typeof e!="function")throw new TypeError("The listener must be a function");var s=new ol(e,n||r,o),i=pt?pt+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 An(r,t){--r._eventsCount===0?r._events=new Pr:delete r._events[t]}function lt(){this._events=new Pr,this._eventsCount=0}lt.prototype.eventNames=function(){var t=[],e,n;if(this._eventsCount===0)return t;for(n in e=this._events)nl.call(e,n)&&t.push(pt?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(e)):t};lt.prototype.listeners=function(t){var e=pt?pt+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};lt.prototype.listenerCount=function(t){var e=pt?pt+t:t,n=this._events[e];return n?n.fn?1:n.length:0};lt.prototype.emit=function(t,e,n,o,s,i){var a=pt?pt+t:t;if(!this._events[a])return!1;var c=this._events[a],u=arguments.length,d,l;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(l=1,d=new Array(u-1);l<u;l++)d[l-1]=arguments[l];c.fn.apply(c.context,d)}else{var f=c.length,h;for(l=0;l<f;l++)switch(c[l].once&&this.removeListener(t,c[l].fn,void 0,!0),u){case 1:c[l].fn.call(c[l].context);break;case 2:c[l].fn.call(c[l].context,e);break;case 3:c[l].fn.call(c[l].context,e,n);break;case 4:c[l].fn.call(c[l].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[l].fn.apply(c[l].context,d)}}return!0};lt.prototype.on=function(t,e,n){return Ua(this,t,e,n,!1)};lt.prototype.once=function(t,e,n){return Ua(this,t,e,n,!0)};lt.prototype.removeListener=function(t,e,n,o){var s=pt?pt+t:t;if(!this._events[s])return this;if(!e)return An(this,s),this;var i=this._events[s];if(i.fn)i.fn===e&&(!o||i.once)&&(!n||i.context===n)&&An(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:An(this,s)}return this};lt.prototype.removeAllListeners=function(t){var e;return t?(e=pt?pt+t:t,this._events[e]&&An(this,e)):(this._events=new Pr,this._eventsCount=0),this};lt.prototype.off=lt.prototype.removeListener;lt.prototype.addListener=lt.prototype.on;lt.prefixed=pt;lt.EventEmitter=lt;typeof Ts<"u"&&(Ts.exports=lt)});var ml={};yt(ml,{StrictNoSign:()=>hl,StrictSign:()=>ll,TopicValidatorResult:()=>Je,floodsub:()=>pl,isPubSub:()=>dl,protocol:()=>Cs,pubSubSymbol:()=>Qe});var Qe=Symbol.for("@libp2p/pubsub");var Ur=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var j=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Le=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Mr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Q=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var Or=class extends Error{static name="NotStartedError";constructor(t="Not started"){super(t),this.name="NotStartedError"}};var de=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Rn=Symbol.for("@libp2p/peer-id");var _e=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 ks=Symbol.for("@libp2p/service-capabilities"),Us=Symbol.for("@libp2p/service-dependencies");var On={};yt(On,{base58btc:()=>Z,base58flickr:()=>cc});var jl=new Uint8Array(0);function Ms(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 Os(r){return new TextEncoder().encode(r)}function qs(r){return new TextDecoder().decode(r)}function rc(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 l(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var E=0,v=0,b=0,A=p.length;b!==A&&p[b]===0;)b++,E++;for(var w=(A-b)*d+1>>>0,_=new Uint8Array(w);b!==A;){for(var C=p[b],M=0,U=w-1;(C!==0||M<v)&&U!==-1;U--,M++)C+=256*_[U]>>>0,_[U]=C%a>>>0,C=C/a>>>0;if(C!==0)throw new Error("Non-zero carry");v=M,b++}for(var R=w-v;R!==w&&_[R]===0;)R++;for(var x=c.repeat(E);R<w;++R)x+=r.charAt(_[R]);return x}function f(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var E=0;if(p[E]!==" "){for(var v=0,b=0;p[E]===c;)v++,E++;for(var A=(p.length-E)*u+1>>>0,w=new Uint8Array(A);p[E];){var _=e[p.charCodeAt(E)];if(_===255)return;for(var C=0,M=A-1;(_!==0||C<b)&&M!==-1;M--,C++)_+=a*w[M]>>>0,w[M]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");b=C,E++}if(p[E]!==" "){for(var U=A-b;U!==A&&w[U]===0;)U++;for(var R=new Uint8Array(v+(A-U)),x=v;U!==A;)R[x++]=w[U++];return R}}}function h(p){var E=f(p);if(E)return E;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:f,decode:h}}var nc=rc,oc=nc,Vs=oc;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")}},kn=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 Fs(this,t)}},Un=class{decoders;constructor(t){this.decoders=t}or(t){return Fs(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 Fs(r,t){return new Un({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Mn=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 kn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Te({name:r,prefix:t,encode:e,decode:n}){return new Mn(r,t,e,n)}function te({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Vs(e,r);return Te({prefix:t,name:r,encode:n,decode:s=>kt(o(s))})}function sc(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 ic(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 ac(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function W({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=ac(n);return Te({prefix:t,name:r,encode(s){return ic(s,n,e)},decode(s){return sc(s,o,e,r)}})}var Z=te({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),cc=te({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var qn={};yt(qn,{base32:()=>De,base32hex:()=>hc,base32hexpad:()=>pc,base32hexpadupper:()=>mc,base32hexupper:()=>dc,base32pad:()=>fc,base32padupper:()=>lc,base32upper:()=>uc,base32z:()=>yc});var De=W({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),uc=W({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),fc=W({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),lc=W({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),hc=W({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),dc=W({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),pc=W({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),mc=W({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),yc=W({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Hn={};yt(Hn,{base36:()=>tr,base36upper:()=>bc});var tr=te({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),bc=te({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var gc=js,zs=128,wc=127,xc=~wc,Ec=Math.pow(2,31);function js(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Ec;)t[e++]=r&255|zs,r/=128;for(;r&xc;)t[e++]=r&255|zs,r>>>=7;return t[e]=r|0,js.bytes=e-n+1,t}var vc=Vn,Sc=128,Gs=127;function Vn(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Vn.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&Gs)<<o:(i&Gs)*Math.pow(2,o),o+=7}while(i>=Sc);return Vn.bytes=s-n,e}var Ac=Math.pow(2,7),Ic=Math.pow(2,14),Bc=Math.pow(2,21),Lc=Math.pow(2,28),_c=Math.pow(2,35),Tc=Math.pow(2,42),Dc=Math.pow(2,49),Pc=Math.pow(2,56),Cc=Math.pow(2,63),Nc=function(r){return r<Ac?1:r<Ic?2:r<Bc?3:r<Lc?4:r<_c?5:r<Tc?6:r<Dc?7:r<Pc?8:r<Cc?9:10},Rc={encode:gc,decode:vc,encodingLength:Nc},Kc=Rc,er=Kc;function rr(r,t=0){return[er.decode(r,t),er.decode.bytes]}function Pe(r,t,e=0){return er.encode(r,t,e),t}function Ce(r){return er.encodingLength(r)}function Nt(r,t){let e=t.byteLength,n=Ce(r),o=n+Ce(e),s=new Uint8Array(o+e);return Pe(r,s,0),Pe(e,s,n),s.set(t,o),new Ne(r,e,t,s)}function ee(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 Ne(e,o,i,t)}function Zs(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Ms(r.bytes,e.bytes)}}var Ne=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function $s(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Uc(e,Fn(r),t??Z.encoder);default:return Mc(e,Fn(r),t??De.encoder)}}var Ys=new WeakMap;function Fn(r){let t=Ys.get(r);if(t==null){let e=new Map;return Ys.set(r,e),e}return t}var at=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!==Oc)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=Nt(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&&Zs(t.multihash,n.multihash)}toString(t){return $s(this,t)}toJSON(){return{"/":$s(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??Xs(n,o,s.bytes))}else if(e[qc]===!0){let{version:n,multihash:o,code:s}=e,i=ee(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=Xs(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 Ne(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[l,f]=rr(t.subarray(e));return e+=f,l},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]=kc(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Fn(s).set(n,t),s}};function kc(r,t){switch(r[0]){case"Q":{let e=t??Z;return[Z.prefix,e.decode(`${Z.prefix}${r}`)]}case Z.prefix:{let e=t??Z;return[Z.prefix,e.decode(r)]}case De.prefix:{let e=t??De;return[De.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 Uc(r,t,e){let{prefix:n}=e;if(n!==Z.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 Mc(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,Oc=18;function Xs(r,t,e){let n=Ce(r),o=n+Ce(t),s=new Uint8Array(o+e.byteLength);return Pe(r,s,0),Pe(t,s,n),s.set(e,o),s}var qc=Symbol.for("@ipld/js-cid/CID");var zn={};yt(zn,{identity:()=>Dt});var Ws=0,Hc="identity",Js=kt;function Vc(r,t){if(t?.truncate!=null&&t.truncate!==r.byteLength){if(t.truncate<0||t.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t.truncate)}return Nt(Ws,Js(r))}var Dt={code:Ws,name:Hc,encode:Js,digest:Vc};function bt(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 Ut(r=0){return new Uint8Array(r)}function ct(r=0){return new Uint8Array(r)}function pe(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=ct(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var ti=Symbol.for("@achingbrain/uint8arraylist");function Qs(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 Hr(r){return!!r?.[ti]}var et=class r{bufs;length;[ti]=!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(Hr(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(Hr(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=Qs(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Qs(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(Hr(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 pe(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:pe(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 l=t-a;n.push(i.subarray(l,l+(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(!Hr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,d;for(let l=e;l<=c;l+=d){d=0;for(let f=u;f>=0;f--){let h=this.get(l+f);if(n[f]!==h){d=Math.max(1,f-a[h]);break}}if(d===0)return l}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=ct(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=Ut(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=Ut(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=Ut(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=ct(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=Ut(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=Ut(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=Ut(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=Ut(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=Ut(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(!bt(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 Gn={};yt(Gn,{base10:()=>Fc});var Fc=te({prefix:"9",name:"base10",alphabet:"0123456789"});var jn={};yt(jn,{base16:()=>zc,base16upper:()=>Gc});var zc=W({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Gc=W({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Zn={};yt(Zn,{base2:()=>jc});var jc=W({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var $n={};yt($n,{base256emoji:()=>Wc});var ei=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}"),Zc=ei.reduce((r,t,e)=>(r[e]=t,r),[]),$c=ei.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Yc(r){return r.reduce((t,e)=>(t+=Zc[e],t),"")}function Xc(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=$c[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Wc=Te({prefix:"\u{1F680}",name:"base256emoji",encode:Yc,decode:Xc});var Yn={};yt(Yn,{base64:()=>Jc,base64pad:()=>Qc,base64url:()=>tu,base64urlpad:()=>eu});var Jc=W({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Qc=W({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),tu=W({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),eu=W({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Xn={};yt(Xn,{base8:()=>ru});var ru=W({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Wn={};yt(Wn,{identity:()=>nu});var nu=Te({prefix:"\0",name:"identity",encode:r=>qs(r),decode:r=>Os(r)});var Th=new TextEncoder,Dh=new TextDecoder;var to={};yt(to,{sha256:()=>me,sha512:()=>au});var iu=20;function Qn({name:r,code:t,encode:e,minDigestLength:n,maxDigestLength:o}){return new Jn(r,t,e,n,o)}var Jn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,e,n,o,s){this.name=t,this.code=e,this.encode=n,this.minDigestLength=o??iu,this.maxDigestLength=s}digest(t,e){if(e?.truncate!=null){if(e.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&e.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?ri(n,this.code,e?.truncate):n.then(o=>ri(o,this.code,e?.truncate))}else throw Error("Unknown type, must be binary type")}};function ri(r,t,e){if(e!=null&&e!==r.byteLength){if(e>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e)}return Nt(t,r)}function oi(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var me=Qn({name:"sha2-256",code:18,encode:oi("SHA-256")}),au=Qn({name:"sha2-512",code:19,encode:oi("SHA-512")});var eo={...Wn,...Zn,...Xn,...Gn,...jn,...qn,...Hn,...On,...Yn,...$n},Vh={...to,...zn};function ii(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var si=ii("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),ro=ii("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=ct(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),cu={utf8:si,"utf-8":si,hex:eo.base16,latin1:ro,ascii:ro,binary:ro,...eo},Vr=cu;function z(r,t="utf8"){let e=Vr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function H(r,t="utf8"){let e=Vr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var uu=parseInt("11111",2),no=parseInt("10000000",2),fu=parseInt("01111111",2),ai={0:or,1:or,2:lu,3:pu,4:mu,5:du,6:hu,16:or,22:or,48:or};function Mt(r,t={offset:0}){let e=r[t.offset]&uu;if(t.offset++,ai[e]!=null)return ai[e](r,t);throw new Error("No decoder for tag "+e)}function sr(r,t){let e=0;if((r[t.offset]&no)===no){let n=r[t.offset]&fu,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=Mt(r,t);if(n===null)break;e.push(n)}return e}function lu(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 hu(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 l=0;l<c.length;l++)d+=c[l]<<l*7;a+=`.${d}`,c=[]}}return a}function du(r,t){return t.offset++,null}function pu(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 mu(r,t){let e=sr(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function yu(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 oo(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=yu(r.byteLength);return new et(Uint8Array.from([t.byteLength|no]),t)}function gt(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]),oo(t),t)}function Fr(r){let t=Uint8Array.from([0]),e=new et(t,r);return new et(Uint8Array.from([3]),oo(e),e)}function ne(r,t=48){let e=new et;for(let n of r)e.append(n);return new et(Uint8Array.from([t]),oo(e),e)}async function ci(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 bu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),gu=Uint8Array.from([6,5,43,129,4,0,34]),wu=Uint8Array.from([6,5,43,129,4,0,35]),xu={ext:!0,kty:"EC",crv:"P-256"},Eu={ext:!0,kty:"EC",crv:"P-384"},vu={ext:!0,kty:"EC",crv:"P-521"},so=32,io=48,ao=66;function co(r){let t=Mt(r);return ui(t)}function ui(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===so*2+1)return n=H(t.subarray(e,e+so),"base64url"),o=H(t.subarray(e+so),"base64url"),new Re({...xu,key_ops:["verify"],x:n,y:o});if(t.byteLength===io*2+1)return n=H(t.subarray(e,e+io),"base64url"),o=H(t.subarray(e+io),"base64url"),new Re({...Eu,key_ops:["verify"],x:n,y:o});if(t.byteLength===ao*2+1)return n=H(t.subarray(e,e+ao),"base64url"),o=H(t.subarray(e+ao),"base64url"),new Re({...vu,key_ops:["verify"],x:n,y:o});throw new j(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function fi(r){return ne([gt(Uint8Array.from([1])),ne([Su(r.crv)],160),ne([Fr(new et(Uint8Array.from([4]),z(r.x??"","base64url"),z(r.y??"","base64url")))],161)]).subarray()}function Su(r){if(r==="P-256")return bu;if(r==="P-384")return gu;if(r==="P-521")return wu;throw new j(`Invalid curve ${r}`)}var Re=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=fi(this.jwk)),this._raw}toMultihash(){return Dt.digest(Ot(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return Z.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}async verify(t,e,n){return ci(this.jwk,e,t,n)}};var ye=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Ht(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 wt(r,...t){if(!Ht(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 zr(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 ke(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 hi(r,t){wt(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}function Vt(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function Gr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Pt(r,t){return r<<32-t|r>>>t}var di=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Au=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function Bt(r){if(wt(r),di)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=Au[r[e]];return t}var qt={_0:48,_9:57,A:65,F:70,a:97,f:102};function li(r){if(r>=qt._0&&r<=qt._9)return r-qt._0;if(r>=qt.A&&r<=qt.F)return r-(qt.A-10);if(r>=qt.a&&r<=qt.f)return r-(qt.a-10)}function be(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(di)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=li(r.charCodeAt(s)),a=li(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 uo(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=uo(r)),wt(r),r}function ht(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];wt(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 Ke=class{};function fo(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 oe(r=32){if(ye&&typeof ye.getRandomValues=="function")return ye.getRandomValues(new Uint8Array(r));if(ye&&typeof ye.randomBytes=="function")return Uint8Array.from(ye.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function Iu(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 pi(r,t,e){return r&t^~r&e}function mi(r,t,e){return r&t^r&e^t&e}var cr=class extends Ke{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=Gr(this.buffer)}update(t){ke(this),t=ar(t),wt(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=Gr(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){ke(this),hi(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,Vt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)e[l]=0;Iu(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=Gr(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 l=0;l<u;l++)a.setUint32(4*l,d[l],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(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()}},Ft=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var st=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var jr=BigInt(4294967295),yi=BigInt(32);function Bu(r,t=!1){return t?{h:Number(r&jr),l:Number(r>>yi&jr)}:{h:Number(r>>yi&jr)|0,l:Number(r&jr)|0}}function bi(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}=Bu(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var lo=(r,t,e)=>r>>>e,ho=(r,t,e)=>r<<32-e|t>>>e,ge=(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 Rt(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var gi=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),wi=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,xi=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Ei=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,vi=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Si=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var _u=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]),se=new Uint32Array(64),Zr=class extends cr{constructor(t=32){super(64,t,8,!1),this.A=Ft[0]|0,this.B=Ft[1]|0,this.C=Ft[2]|0,this.D=Ft[3]|0,this.E=Ft[4]|0,this.F=Ft[5]|0,this.G=Ft[6]|0,this.H=Ft[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 l=0;l<16;l++,e+=4)se[l]=t.getUint32(e,!1);for(let l=16;l<64;l++){let f=se[l-15],h=se[l-2],p=Pt(f,7)^Pt(f,18)^f>>>3,E=Pt(h,17)^Pt(h,19)^h>>>10;se[l]=E+se[l-7]+p+se[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:d}=this;for(let l=0;l<64;l++){let f=Pt(a,6)^Pt(a,11)^Pt(a,25),h=d+f+pi(a,c,u)+_u[l]+se[l]|0,E=(Pt(n,2)^Pt(n,13)^Pt(n,22))+mi(n,o,s)|0;d=u,u=c,c=a,a=i+h|0,i=s,s=o,o=n,n=h+E|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(){Vt(se)}destroy(){this.set(0,0,0,0,0,0,0,0),Vt(this.buffer)}};var Ai=bi(["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))),Tu=Ai[0],Du=Ai[1],ie=new Uint32Array(80),ae=new Uint32Array(80),po=class extends cr{constructor(t=64){super(128,t,16,!1),this.Ah=st[0]|0,this.Al=st[1]|0,this.Bh=st[2]|0,this.Bl=st[3]|0,this.Ch=st[4]|0,this.Cl=st[5]|0,this.Dh=st[6]|0,this.Dl=st[7]|0,this.Eh=st[8]|0,this.El=st[9]|0,this.Fh=st[10]|0,this.Fl=st[11]|0,this.Gh=st[12]|0,this.Gl=st[13]|0,this.Hh=st[14]|0,this.Hl=st[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:l,Fl:f,Gh:h,Gl:p,Hh:E,Hl:v}=this;return[t,e,n,o,s,i,a,c,u,d,l,f,h,p,E,v]}set(t,e,n,o,s,i,a,c,u,d,l,f,h,p,E,v){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=l|0,this.Fl=f|0,this.Gh=h|0,this.Gl=p|0,this.Hh=E|0,this.Hl=v|0}process(t,e){for(let w=0;w<16;w++,e+=4)ie[w]=t.getUint32(e),ae[w]=t.getUint32(e+=4);for(let w=16;w<80;w++){let _=ie[w-15]|0,C=ae[w-15]|0,M=ge(_,C,1)^ge(_,C,8)^lo(_,C,7),U=we(_,C,1)^we(_,C,8)^ho(_,C,7),R=ie[w-2]|0,x=ae[w-2]|0,T=ge(R,x,19)^ur(R,x,61)^lo(R,x,6),K=we(R,x,19)^fr(R,x,61)^ho(R,x,6),D=xi(U,K,ae[w-7],ae[w-16]),g=Ei(D,M,T,ie[w-7],ie[w-16]);ie[w]=g|0,ae[w]=D|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:d,Eh:l,El:f,Fh:h,Fl:p,Gh:E,Gl:v,Hh:b,Hl:A}=this;for(let w=0;w<80;w++){let _=ge(l,f,14)^ge(l,f,18)^ur(l,f,41),C=we(l,f,14)^we(l,f,18)^fr(l,f,41),M=l&h^~l&E,U=f&p^~f&v,R=vi(A,C,U,Du[w],ae[w]),x=Si(R,b,_,M,Tu[w],ie[w]),T=R|0,K=ge(n,o,28)^ur(n,o,34)^ur(n,o,39),D=we(n,o,28)^fr(n,o,34)^fr(n,o,39),g=n&s^n&a^s&a,m=o&i^o&c^i&c;b=E|0,A=v|0,E=h|0,v=p|0,h=l|0,p=f|0,{h:l,l:f}=Rt(u|0,d|0,x|0,T|0),u=a|0,d=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let y=gi(T,D,m);n=wi(y,x,K,g),o=y|0}({h:n,l:o}=Rt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Rt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Rt(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:d}=Rt(this.Dh|0,this.Dl|0,u|0,d|0),{h:l,l:f}=Rt(this.Eh|0,this.El|0,l|0,f|0),{h,l:p}=Rt(this.Fh|0,this.Fl|0,h|0,p|0),{h:E,l:v}=Rt(this.Gh|0,this.Gl|0,E|0,v|0),{h:b,l:A}=Rt(this.Hh|0,this.Hl|0,b|0,A|0),this.set(n,o,s,i,a,c,u,d,l,f,h,p,E,v,b,A)}roundClean(){Vt(ie,ae)}destroy(){Vt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var $r=fo(()=>new Zr);var Ii=fo(()=>new po);var bo=BigInt(0),yo=BigInt(1);function zt(r,t=""){if(typeof r!="boolean"){let e=t&&`"${t}"`;throw new Error(e+"expected boolean, got type="+typeof r)}return r}function St(r,t,e=""){let n=Ht(r),o=r?.length,s=t!==void 0;if(!n||s&&o!==t){let i=e&&`"${e}" `,a=s?` of length ${t}`:"",c=n?`length=${o}`:`type=${typeof r}`;throw new Error(i+"expected Uint8Array"+a+", got "+c)}return r}function lr(r){let t=r.toString(16);return t.length&1?"0"+t:t}function Bi(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?bo:BigInt("0x"+r)}function Ue(r){return Bi(Bt(r))}function Gt(r){return wt(r),Bi(Bt(Uint8Array.from(r).reverse()))}function Yr(r,t){return be(r.toString(16).padStart(t*2,"0"))}function go(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(Ht(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 Li(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}function wo(r){return Uint8Array.from(r)}var mo=r=>typeof r=="bigint"&&bo<=r;function _i(r,t,e){return mo(r)&&mo(t)&&mo(e)&&t<=r&&r<e}function hr(r,t,e,n){if(!_i(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function Xr(r){let t;for(t=0;r>bo;r>>=yo,t+=1);return t}var ce=r=>(yo<<BigInt(r))-yo;function Ti(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())},l=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let h=0,p=[];for(;h<t;){s=u();let E=s.slice();p.push(E),h+=s.length}return ht(...p)};return(h,p)=>{c(),d(h);let E;for(;!(E=p(l()));)d();return c(),E}}function ue(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))}var xo=()=>{throw new Error("not implemented")};function Me(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 dt=BigInt(0),nt=BigInt(1),xe=BigInt(2),Ci=BigInt(3),Ni=BigInt(4),Ri=BigInt(5),Pu=BigInt(7),Ki=BigInt(8),Cu=BigInt(9),ki=BigInt(16);function J(r,t){let e=r%t;return e>=dt?e:t+e}function G(r,t,e){let n=r;for(;t-- >dt;)n*=n,n%=e;return n}function Di(r,t){if(r===dt)throw new Error("invert: expected non-zero number");if(t<=dt)throw new Error("invert: expected positive modulus, got "+t);let e=J(r,t),n=t,o=dt,s=nt,i=nt,a=dt;for(;e!==dt;){let u=n/e,d=n%e,l=o-i*u,f=s-a*u;n=e,e=d,o=i,s=a,i=l,a=f}if(n!==nt)throw new Error("invert: does not exist");return J(o,t)}function Eo(r,t,e){if(!r.eql(r.sqr(t),e))throw new Error("Cannot find square root")}function Ui(r,t){let e=(r.ORDER+nt)/Ni,n=r.pow(t,e);return Eo(r,n,t),n}function Nu(r,t){let e=(r.ORDER-Ri)/Ki,n=r.mul(t,xe),o=r.pow(n,e),s=r.mul(t,o),i=r.mul(r.mul(s,xe),o),a=r.mul(s,r.sub(i,r.ONE));return Eo(r,a,t),a}function Ru(r){let t=At(r),e=Mi(r),n=e(t,t.neg(t.ONE)),o=e(t,n),s=e(t,t.neg(n)),i=(r+Pu)/ki;return(a,c)=>{let u=a.pow(c,i),d=a.mul(u,n),l=a.mul(u,o),f=a.mul(u,s),h=a.eql(a.sqr(d),c),p=a.eql(a.sqr(l),c);u=a.cmov(u,d,h),d=a.cmov(f,l,p);let E=a.eql(a.sqr(d),c),v=a.cmov(u,d,E);return Eo(a,v,c),v}}function Mi(r){if(r<Ci)throw new Error("sqrt is not defined for small field");let t=r-nt,e=0;for(;t%xe===dt;)t/=xe,e++;let n=xe,o=At(r);for(;Pi(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return Ui;let s=o.pow(n,t),i=(t+nt)/xe;return function(c,u){if(c.is0(u))return u;if(Pi(c,u)!==1)throw new Error("Cannot find square root");let d=e,l=c.mul(c.ONE,s),f=c.pow(u,t),h=c.pow(u,i);for(;!c.eql(f,c.ONE);){if(c.is0(f))return c.ZERO;let p=1,E=c.sqr(f);for(;!c.eql(E,c.ONE);)if(p++,E=c.sqr(E),p===d)throw new Error("Cannot find square root");let v=nt<<BigInt(d-p-1),b=c.pow(l,v);d=p,l=c.sqr(b),f=c.mul(f,l),h=c.mul(h,b)}return h}}function Ku(r){return r%Ni===Ci?Ui:r%Ki===Ri?Nu:r%ki===Cu?Ru(r):Mi(r)}var jt=(r,t)=>(J(r,t)&nt)===nt,ku=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function vo(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},e=ku.reduce((n,o)=>(n[o]="function",n),t);return ue(r,e),r}function Uu(r,t,e){if(e<dt)throw new Error("invalid exponent, negatives unsupported");if(e===dt)return r.ONE;if(e===nt)return t;let n=r.ONE,o=t;for(;e>dt;)e&nt&&(n=r.mul(n,o)),o=r.sqr(o),e>>=nt;return n}function dr(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 Pi(r,t){let e=(r.ORDER-nt)/xe,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 Wr(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 At(r,t,e=!1,n={}){if(r<=dt)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 f=t;f.BITS&&(o=f.BITS),f.sqrt&&(s=f.sqrt),typeof f.isLE=="boolean"&&(e=f.isLE),typeof f.modFromBytes=="boolean"&&(i=f.modFromBytes),a=f.allowedLengths}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:c,nByteLength:u}=Wr(r,o);if(u>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let d,l=Object.freeze({ORDER:r,isLE:e,BITS:c,BYTES:u,MASK:ce(c),ZERO:dt,ONE:nt,allowedLengths:a,create:f=>J(f,r),isValid:f=>{if(typeof f!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof f);return dt<=f&&f<r},is0:f=>f===dt,isValidNot0:f=>!l.is0(f)&&l.isValid(f),isOdd:f=>(f&nt)===nt,neg:f=>J(-f,r),eql:(f,h)=>f===h,sqr:f=>J(f*f,r),add:(f,h)=>J(f+h,r),sub:(f,h)=>J(f-h,r),mul:(f,h)=>J(f*h,r),pow:(f,h)=>Uu(l,f,h),div:(f,h)=>J(f*Di(h,r),r),sqrN:f=>f*f,addN:(f,h)=>f+h,subN:(f,h)=>f-h,mulN:(f,h)=>f*h,inv:f=>Di(f,r),sqrt:s||(f=>(d||(d=Ku(r)),d(l,f))),toBytes:f=>e?go(f,u):Yr(f,u),fromBytes:(f,h=!0)=>{if(a){if(!a.includes(f.length)||f.length>u)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+f.length);let E=new Uint8Array(u);E.set(f,e?0:E.length-f.length),f=E}if(f.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+f.length);let p=e?Gt(f):Ue(f);if(i&&(p=J(p,r)),!h&&!l.isValid(p))throw new Error("invalid field element: outside of range 0..ORDER");return p},invertBatch:f=>dr(l,f),cmov:(f,h,p)=>p?h:f});return Object.freeze(l)}function Oi(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 So(r){let t=Oi(r);return t+Math.ceil(t/2)}function Ao(r,t,e=!1){let n=r.length,o=Oi(t),s=So(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?Gt(r):Ue(r),a=J(i,t-nt)+nt;return e?go(a,o):Yr(a,o)}var Oe=BigInt(0),Ee=BigInt(1);function pr(r,t){let e=t.negate();return r?e:t}function Zt(r,t){let e=dr(r.Fp,t.map(n=>n.Z));return t.map((n,o)=>r.fromAffine(n.toAffine(e[o])))}function Fi(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function Io(r,t){Fi(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=ce(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function qi(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+=Ee);let u=t*n,d=u+Math.abs(a)-1,l=a===0,f=a<0,h=t%2!==0;return{nextN:c,offset:d,isZero:l,isNeg:f,isNegF:h,offsetF:u}}function Mu(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 Ou(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 Bo=new WeakMap,zi=new WeakMap;function Lo(r){return zi.get(r)||1}function Hi(r){if(r!==Oe)throw new Error("invalid wNAF")}var qe=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>Oe;)e&Ee&&(n=n.add(o)),o=o.double(),e>>=Ee;return n}precomputeWindow(t,e){let{windows:n,windowSize:o}=Io(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=Io(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:u,isZero:d,isNeg:l,isNegF:f,offsetF:h}=qi(n,a,i);n=c,d?s=s.add(pr(f,e[h])):o=o.add(pr(l,e[u]))}return Hi(n),{p:o,f:s}}wNAFUnsafe(t,e,n,o=this.ZERO){let s=Io(t,this.bits);for(let i=0;i<s.windows&&n!==Oe;i++){let{nextN:a,offset:c,isZero:u,isNeg:d}=qi(n,i,s);if(n=a,!u){let l=e[c];o=o.add(d?l.negate():l)}}return Hi(n),o}getPrecomputes(t,e,n){let o=Bo.get(e);return o||(o=this.precomputeWindow(e,t),t!==1&&(typeof n=="function"&&(o=n(o)),Bo.set(e,o))),o}cached(t,e,n){let o=Lo(t);return this.wNAF(o,this.getPrecomputes(o,t,n),e)}unsafe(t,e,n,o){let s=Lo(t);return s===1?this._unsafeLadder(t,e,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),e,o)}createCache(t,e){Fi(e,this.bits),zi.set(t,e),Bo.delete(t)}hasCache(t){return Lo(t)!==1}};function Gi(r,t,e,n){let o=t,s=r.ZERO,i=r.ZERO;for(;e>Oe||n>Oe;)e&Ee&&(s=s.add(o)),n&Ee&&(i=i.add(o)),o=o.double(),e>>=Ee,n>>=Ee;return{p1:s,p2:i}}function He(r,t,e,n){Mu(e,r),Ou(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=ce(c),d=new Array(Number(u)+1).fill(i),l=Math.floor((t.BITS-1)/c)*c,f=i;for(let h=l;h>=0;h-=c){d.fill(i);for(let E=0;E<s;E++){let v=n[E],b=Number(v>>BigInt(h)&u);d[b]=d[b].add(e[E])}let p=i;for(let E=d.length-1,v=i;E>0;E--)v=v.add(d[E]),p=p.add(v);if(f=f.add(p),h!==0)for(let E=0;E<c;E++)f=f.double()}return f}function Vi(r,t,e){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return vo(t),t}else return At(r,{isLE:e})}function Jr(r,t,e={},n){if(n===void 0&&(n=r==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${r} CURVE object`);for(let c of["p","n","h"]){let u=t[c];if(!(typeof u=="bigint"&&u>Oe))throw new Error(`CURVE.${c} must be positive bigint`)}let o=Vi(t.p,e.Fp,n),s=Vi(t.n,e.Fn,n),a=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}var fe=BigInt(0),ot=BigInt(1),_o=BigInt(2),qu=BigInt(8);function Hu(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 Vu(r,t={}){let e=Jr("edwards",r,t,t.FpFnLE),{Fp:n,Fn:o}=e,s=e.CURVE,{h:i}=s;ue(t,{},{uvRatio:"function"});let a=_o<<BigInt(o.BYTES*8)-ot,c=v=>n.create(v),u=t.uvRatio||((v,b)=>{try{return{isValid:!0,value:n.sqrt(n.div(v,b))}}catch{return{isValid:!1,value:fe}}});if(!Hu(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function d(v,b,A=!1){let w=A?ot:fe;return hr("coordinate "+v,b,w,a),b}function l(v){if(!(v instanceof p))throw new Error("ExtendedPoint expected")}let f=Me((v,b)=>{let{X:A,Y:w,Z:_}=v,C=v.is0();b==null&&(b=C?qu:n.inv(_));let M=c(A*b),U=c(w*b),R=n.mul(_,b);if(C)return{x:fe,y:ot};if(R!==ot)throw new Error("invZ was invalid");return{x:M,y:U}}),h=Me(v=>{let{a:b,d:A}=s;if(v.is0())throw new Error("bad point: ZERO");let{X:w,Y:_,Z:C,T:M}=v,U=c(w*w),R=c(_*_),x=c(C*C),T=c(x*x),K=c(U*b),D=c(x*c(K+R)),g=c(T+c(A*c(U*R)));if(D!==g)throw new Error("bad point: equation left != right (1)");let m=c(w*_),y=c(C*M);if(m!==y)throw new Error("bad point: equation left != right (2)");return!0});class p{constructor(b,A,w,_){this.X=d("x",b),this.Y=d("y",A),this.Z=d("z",w,!0),this.T=d("t",_),Object.freeze(this)}static CURVE(){return s}static fromAffine(b){if(b instanceof p)throw new Error("extended point not allowed");let{x:A,y:w}=b||{};return d("x",A),d("y",w),new p(A,w,ot,c(A*w))}static fromBytes(b,A=!1){let w=n.BYTES,{a:_,d:C}=s;b=wo(St(b,w,"point")),zt(A,"zip215");let M=wo(b),U=b[w-1];M[w-1]=U&-129;let R=Gt(M),x=A?a:n.ORDER;hr("point.y",R,fe,x);let T=c(R*R),K=c(T-ot),D=c(C*T-_),{isValid:g,value:m}=u(K,D);if(!g)throw new Error("bad point: invalid y coordinate");let y=(m&ot)===ot,S=(U&128)!==0;if(!A&&m===fe&&S)throw new Error("bad point: x=0 and x_0=1");return S!==y&&(m=c(-m)),p.fromAffine({x:m,y:R})}static fromHex(b,A=!1){return p.fromBytes(V("point",b),A)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=8,A=!0){return E.createCache(this,b),A||this.multiply(_o),this}assertValidity(){h(this)}equals(b){l(b);let{X:A,Y:w,Z:_}=this,{X:C,Y:M,Z:U}=b,R=c(A*U),x=c(C*_),T=c(w*U),K=c(M*_);return R===x&&T===K}is0(){return this.equals(p.ZERO)}negate(){return new p(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:b}=s,{X:A,Y:w,Z:_}=this,C=c(A*A),M=c(w*w),U=c(_o*c(_*_)),R=c(b*C),x=A+w,T=c(c(x*x)-C-M),K=R+M,D=K-U,g=R-M,m=c(T*D),y=c(K*g),S=c(T*g),I=c(D*K);return new p(m,y,I,S)}add(b){l(b);let{a:A,d:w}=s,{X:_,Y:C,Z:M,T:U}=this,{X:R,Y:x,Z:T,T:K}=b,D=c(_*R),g=c(C*x),m=c(U*w*K),y=c(M*T),S=c((_+C)*(R+x)-D-g),I=y-m,P=y+m,B=c(g-A*D),L=c(S*I),N=c(P*B),k=c(S*B),$=c(I*P);return new p(L,N,$,k)}subtract(b){return this.add(b.negate())}multiply(b){if(!o.isValidNot0(b))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:A,f:w}=E.cached(this,b,_=>Zt(p,_));return Zt(p,[A,w])[0]}multiplyUnsafe(b,A=p.ZERO){if(!o.isValid(b))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return b===fe?p.ZERO:this.is0()||b===ot?this:E.unsafe(this,b,w=>Zt(p,w),A)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return E.unsafe(this,s.n).is0()}toAffine(b){return f(this,b)}clearCofactor(){return i===ot?this:this.multiplyUnsafe(i)}toBytes(){let{x:b,y:A}=this.toAffine(),w=n.toBytes(A);return w[w.length-1]|=b&ot?128:0,w}toHex(){return Bt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(b){return Zt(p,b)}static msm(b,A){return He(p,o,b,A)}_setWindowSize(b){this.precompute(b)}toRawBytes(){return this.toBytes()}}p.BASE=new p(s.Gx,s.Gy,ot,c(s.Gx*s.Gy)),p.ZERO=new p(fe,ot,ot,fe),p.Fp=n,p.Fn=o;let E=new qe(p,o.BITS);return p.BASE.precompute(8),p}var Qr=class{constructor(t){this.ep=t}static fromBytes(t){xo()}static fromHex(t){xo()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(t){return this.ep.toAffine(t)}toHex(){return Bt(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))}toRawBytes(){return this.toBytes()}};function Fu(r,t,e={}){if(typeof t!="function")throw new Error('"hash" function param is required');ue(e,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=e,{BASE:o,Fp:s,Fn:i}=r,a=e.randomBytes||oe,c=e.adjustScalarBytes||(x=>x),u=e.domain||((x,T,K)=>{if(zt(K,"phflag"),T.length||K)throw new Error("Contexts/pre-hash are not supported");return x});function d(x){return i.create(Gt(x))}function l(x){let T=w.secretKey;x=V("private key",x,T);let K=V("hashed private key",t(x),2*T),D=c(K.slice(0,T)),g=K.slice(T,2*T),m=d(D);return{head:D,prefix:g,scalar:m}}function f(x){let{head:T,prefix:K,scalar:D}=l(x),g=o.multiply(D),m=g.toBytes();return{head:T,prefix:K,scalar:D,point:g,pointBytes:m}}function h(x){return f(x).pointBytes}function p(x=Uint8Array.of(),...T){let K=ht(...T);return d(t(u(K,V("context",x),!!n)))}function E(x,T,K={}){x=V("message",x),n&&(x=n(x));let{prefix:D,scalar:g,pointBytes:m}=f(T),y=p(K.context,D,x),S=o.multiply(y).toBytes(),I=p(K.context,S,m,x),P=i.create(y+I*g);if(!i.isValid(P))throw new Error("sign failed: invalid s");let B=ht(S,i.toBytes(P));return St(B,w.signature,"result")}let v={zip215:!0};function b(x,T,K,D=v){let{context:g,zip215:m}=D,y=w.signature;x=V("signature",x,y),T=V("message",T),K=V("publicKey",K,w.publicKey),m!==void 0&&zt(m,"zip215"),n&&(T=n(T));let S=y/2,I=x.subarray(0,S),P=Gt(x.subarray(S,y)),B,L,N;try{B=r.fromBytes(K,m),L=r.fromBytes(I,m),N=o.multiplyUnsafe(P)}catch{return!1}if(!m&&B.isSmallOrder())return!1;let k=p(g,L.toBytes(),B.toBytes(),T);return L.add(B.multiplyUnsafe(k)).subtract(N).clearCofactor().is0()}let A=s.BYTES,w={secretKey:A,publicKey:A,signature:2*A,seed:A};function _(x=a(w.seed)){return St(x,w.seed,"seed")}function C(x){let T=R.randomSecretKey(x);return{secretKey:T,publicKey:h(T)}}function M(x){return Ht(x)&&x.length===i.BYTES}function U(x,T){try{return!!r.fromBytes(x,T)}catch{return!1}}let R={getExtendedPublicKey:f,randomSecretKey:_,isValidSecretKey:M,isValidPublicKey:U,toMontgomery(x){let{y:T}=r.fromBytes(x),K=w.publicKey,D=K===32;if(!D&&K!==57)throw new Error("only defined for 25519 and 448");let g=D?s.div(ot+T,ot-T):s.div(T-ot,T+ot);return s.toBytes(g)},toMontgomerySecret(x){let T=w.secretKey;St(x,T);let K=t(x.subarray(0,T));return c(K).subarray(0,T)},randomPrivateKey:_,precompute(x=8,T=r.BASE){return T.precompute(x,!1)}};return Object.freeze({keygen:C,getPublicKey:h,sign:E,verify:b,utils:R,Point:r,lengths:w})}function zu(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=At(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 Gu(r,t){let e=t.Point;return Object.assign({},t,{ExtendedPoint:e,CURVE:r,nBitLength:e.Fn.BITS,nByteLength:e.Fn.BYTES})}function ji(r){let{CURVE:t,curveOpts:e,hash:n,eddsaOpts:o}=zu(r),s=Vu(t,e),i=Fu(s,n,o);return Gu(r,i)}var ju=BigInt(0),$t=BigInt(1),Zi=BigInt(2),Xd=BigInt(3),Zu=BigInt(5),$u=BigInt(8),Ve=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),mr={p:Ve,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:$u,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Yu(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=Ve,a=r*r%s*r%s,c=G(a,Zi,s)*a%s,u=G(c,$t,s)*r%s,d=G(u,Zu,s)*u%s,l=G(d,t,s)*d%s,f=G(l,e,s)*l%s,h=G(f,n,s)*f%s,p=G(h,o,s)*h%s,E=G(p,o,s)*h%s,v=G(E,t,s)*d%s;return{pow_p_5_8:G(v,Zi,s)*r%s,b2:a}}function Xu(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var To=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Co(r,t){let e=Ve,n=J(t*t*t,e),o=J(n*n*t,e),s=Yu(r*o).pow_p_5_8,i=J(r*n*s,e),a=J(t*i*i,e),c=i,u=J(i*To,e),d=a===r,l=a===J(-r,e),f=a===J(-r*To,e);return d&&(i=c),(l||f)&&(i=u),jt(i,e)&&(i=J(-i,e)),{isValid:d||l,value:i}}var le=At(mr.p,{isLE:!0}),Wu=At(mr.n,{isLE:!0}),Ju={...mr,Fp:le,hash:Ii,adjustScalarBytes:Xu,uvRatio:Co},Yt=ji(Ju);var Do=To,Qu=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),tf=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),ef=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),rf=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),$i=r=>Co($t,r),nf=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Po=r=>Yt.Point.Fp.create(Gt(r)&nf);function Yi(r){let{d:t}=mr,e=Ve,n=b=>le.create(b),o=n(Do*r*r),s=n((o+$t)*ef),i=BigInt(-1),a=n((i-t*o)*n(o+t)),{isValid:c,value:u}=Co(s,a),d=n(u*r);jt(d,e)||(d=n(-d)),c||(u=d),c||(i=o);let l=n(i*(o-$t)*rf-a),f=u*u,h=n((u+u)*a),p=n(l*Qu),E=n($t-f),v=n($t+f);return new Yt.Point(n(h*v),n(E*p),n(p*v),n(h*E))}function of(r){wt(r,64);let t=Po(r.subarray(0,32)),e=Yi(t),n=Po(r.subarray(32,64)),o=Yi(n);return new Xt(e.add(o))}var Xt=class r extends Qr{constructor(t){super(t)}static fromAffine(t){return new r(Yt.Point.fromAffine(t))}assertSame(t){if(!(t instanceof r))throw new Error("RistrettoPoint expected")}init(t){return new r(t)}static hashToCurve(t){return of(V("ristrettoHash",t,64))}static fromBytes(t){wt(t,32);let{a:e,d:n}=mr,o=Ve,s=_=>le.create(_),i=Po(t);if(!Li(le.toBytes(i),t)||jt(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),c=s($t+e*a),u=s($t-e*a),d=s(c*c),l=s(u*u),f=s(e*n*d-l),{isValid:h,value:p}=$i(s(f*l)),E=s(p*u),v=s(p*E*f),b=s((i+i)*E);jt(b,o)&&(b=s(-b));let A=s(c*v),w=s(b*A);if(!h||jt(w,o)||A===ju)throw new Error("invalid ristretto255 encoding 2");return new r(new Yt.Point(b,A,$t,w))}static fromHex(t){return r.fromBytes(V("ristrettoHex",t,32))}static msm(t,e){return He(r,Yt.Point.Fn,t,e)}toBytes(){let{X:t,Y:e,Z:n,T:o}=this.ep,s=Ve,i=v=>le.create(v),a=i(i(n+e)*i(n-e)),c=i(t*e),u=i(c*c),{value:d}=$i(i(a*u)),l=i(d*a),f=i(d*c),h=i(l*f*o),p;if(jt(o*h,s)){let v=i(e*Do),b=i(t*Do);t=v,e=b,p=i(l*tf)}else p=f;jt(t*h,s)&&(e=i(-e));let E=i((n-e)*p);return jt(E,s)&&(E=i(-E)),le.toBytes(E)}equals(t){this.assertSame(t);let{X:e,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=u=>le.create(u),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(Yt.Point.BASE);Xt.ZERO=new Xt(Yt.Point.ZERO);Xt.Fp=le;Xt.Fn=Wu;var yr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},tn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Xi={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new tn("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 Lt=Xi;var en=32;var No,sf=(async()=>{try{return await Lt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function af(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await Lt.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await Lt.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 cf(r,t,e){return Yt.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function Wi(r,t,e){return No==null&&(No=await sf),No?af(r,t,e):cf(r,t,e)}function rn(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var nn=class{type="Ed25519";raw;constructor(t){this.raw=Ro(t,en)}toMultihash(){return Dt.digest(Ot(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return Z.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let o=Wi(this.raw,e,t);return rn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Ko(r){return r=Ro(r,en),new nn(r)}function Ro(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new j(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var ff=Math.pow(2,7),lf=Math.pow(2,14),hf=Math.pow(2,21),ko=Math.pow(2,28),Uo=Math.pow(2,35),Mo=Math.pow(2,42),Oo=Math.pow(2,49),q=128,ut=127;function _t(r){if(r<ff)return 1;if(r<lf)return 2;if(r<hf)return 3;if(r<ko)return 4;if(r<Uo)return 5;if(r<Mo)return 6;if(r<Oo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function qo(r,t,e=0){switch(_t(r)){case 8:t[e++]=r&255|q,r/=128;case 7:t[e++]=r&255|q,r/=128;case 6:t[e++]=r&255|q,r/=128;case 5:t[e++]=r&255|q,r/=128;case 4:t[e++]=r&255|q,r>>>=7;case 3:t[e++]=r&255|q,r>>>=7;case 2:t[e++]=r&255|q,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function df(r,t,e=0){switch(_t(r)){case 8:t.set(e++,r&255|q),r/=128;case 7:t.set(e++,r&255|q),r/=128;case 6:t.set(e++,r&255|q),r/=128;case 5:t.set(e++,r&255|q),r/=128;case 4:t.set(e++,r&255|q),r>>>=7;case 3:t.set(e++,r&255|q),r>>>=7;case 2:t.set(e++,r&255|q),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function Ho(r,t){let e=r[t],n=0;if(n+=e&ut,e<q||(e=r[t+1],n+=(e&ut)<<7,e<q)||(e=r[t+2],n+=(e&ut)<<14,e<q)||(e=r[t+3],n+=(e&ut)<<21,e<q)||(e=r[t+4],n+=(e&ut)*ko,e<q)||(e=r[t+5],n+=(e&ut)*Uo,e<q)||(e=r[t+6],n+=(e&ut)*Mo,e<q)||(e=r[t+7],n+=(e&ut)*Oo,e<q))return n;throw new RangeError("Could not decode varint")}function pf(r,t){let e=r.get(t),n=0;if(n+=e&ut,e<q||(e=r.get(t+1),n+=(e&ut)<<7,e<q)||(e=r.get(t+2),n+=(e&ut)<<14,e<q)||(e=r.get(t+3),n+=(e&ut)<<21,e<q)||(e=r.get(t+4),n+=(e&ut)*ko,e<q)||(e=r.get(t+5),n+=(e&ut)*Uo,e<q)||(e=r.get(t+6),n+=(e&ut)*Mo,e<q)||(e=r.get(t+7),n+=(e&ut)*Oo,e<q))return n;throw new RangeError("Could not decode varint")}function Vo(r,t,e=0){return t==null&&(t=ct(_t(r))),t instanceof Uint8Array?qo(r,t,e):df(r,t,e)}function Fo(r,t=0){return r instanceof Uint8Array?Ho(r,t):pf(r,t)}var Go=new Float32Array([-0]),he=new Uint8Array(Go.buffer);function Qi(r,t,e){Go[0]=r,t[e]=he[0],t[e+1]=he[1],t[e+2]=he[2],t[e+3]=he[3]}function ta(r,t){return he[0]=r[t],he[1]=r[t+1],he[2]=r[t+2],he[3]=r[t+3],Go[0]}var jo=new Float64Array([-0]),ft=new Uint8Array(jo.buffer);function ea(r,t,e){jo[0]=r,t[e]=ft[0],t[e+1]=ft[1],t[e+2]=ft[2],t[e+3]=ft[3],t[e+4]=ft[4],t[e+5]=ft[5],t[e+6]=ft[6],t[e+7]=ft[7]}function ra(r,t){return ft[0]=r[t],ft[1]=r[t+1],ft[2]=r[t+2],ft[3]=r[t+3],ft[4]=r[t+4],ft[5]=r[t+5],ft[6]=r[t+6],ft[7]=r[t+7],jo[0]}var mf=BigInt(Number.MAX_SAFE_INTEGER),yf=BigInt(Number.MIN_SAFE_INTEGER),It=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 ve;if(t<mf&&t>yf)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>na&&(o=0n,++n>na&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return ve;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):ve}},ve=new It(0,0);ve.toBigInt=function(){return 0n};ve.zzEncode=ve.zzDecode=function(){return this};ve.length=function(){return 1};var na=4294967296n;function oa(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 sa(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 Zo(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 Ct(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function on(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var $o=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,Ct(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 Ct(this,4);return on(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ct(this,4);return on(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ct(this,4);let t=ta(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Ct(this,4);let t=ra(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 Ct(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return sa(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Ct(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Ct(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 It(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 Ct(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 Ct(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 Ct(this,8);let t=on(this.buf,this.pos+=4),e=on(this.buf,this.pos+=4);return new It(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=Ho(this.buf,this.pos);return this.pos+=_t(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 Yo(r){return new $o(r instanceof Uint8Array?r:r.subarray())}function xt(r,t,e){let n=Yo(r);return t.decode(n,void 0,e)}function Xo(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return ct(i);o+i>t&&(n=ct(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Se=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Wo(){}var Qo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},bf=Xo();function gf(r){return globalThis.Buffer!=null?ct(r):bf(r)}var gr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Se(Wo,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new Se(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new ts((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(sn,10,It.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=It.fromBigInt(t);return this._push(sn,e.length(),e)}uint64Number(t){return this._push(qo,_t(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=It.fromBigInt(t).zzEncode();return this._push(sn,e.length(),e)}sint64Number(t){let e=It.fromNumber(t).zzEncode();return this._push(sn,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Jo,1,t?1:0)}fixed32(t){return this._push(br,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=It.fromBigInt(t);return this._push(br,4,e.lo)._push(br,4,e.hi)}fixed64Number(t){let e=It.fromNumber(t);return this._push(br,4,e.lo)._push(br,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(Qi,4,t)}double(t){return this._push(ea,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Jo,1,0):this.uint32(e)._push(xf,e,t)}string(t){let e=oa(t);return e!==0?this.uint32(e)._push(Zo,e,t):this._push(Jo,1,0)}fork(){return this.states=new Qo(this),this.head=this.tail=new Se(Wo,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 Se(Wo,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=gf(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Jo(r,t,e){t[e]=r&255}function wf(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var ts=class extends Se{next;constructor(t,e){super(wf,t,e),this.next=void 0}};function sn(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 br(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 xf(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(gr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Ef,t,r),this},gr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(vf,t,r),this});function Ef(r,t,e){t.set(r,e)}function vf(r,t,e){r.length<40?Zo(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(z(r),e)}function es(){return new gr}function Et(r,t){let e=es();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var Fe;(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"})(Fe||(Fe={}));function an(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function rs(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 an("enum",Fe.VARINT,e,n)}function vt(r,t){return an("message",Fe.LENGTH_DELIMITED,r,t)}var Tt=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var tt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(tt||(tt={}));var ns;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(ns||(ns={}));(function(r){r.codec=()=>rs(ns)})(tt||(tt={}));var Kt;(function(r){let t;r.codec=()=>(t==null&&(t=vt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),tt.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=tt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>Et(e,r.codec()),r.decode=(e,n)=>xt(e,r.codec(),n)})(Kt||(Kt={}));var os;(function(r){let t;r.codec=()=>(t==null&&(t=vt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),tt.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=tt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>Et(e,r.codec()),r.decode=(e,n)=>xt(e,r.codec(),n)})(os||(os={}));function cn(r){if(isNaN(r)||r<=0)throw new j("random bytes length must be a Number bigger than 0");return oe(r)}var xr={};yt(xr,{MAX_RSA_KEY_SIZE:()=>ss,generateRSAKeyPair:()=>la,jwkToJWKKeyPair:()=>ha,jwkToPkcs1:()=>Bf,jwkToPkix:()=>us,jwkToRSAPrivateKey:()=>ds,pkcs1MessageToJwk:()=>as,pkcs1MessageToRSAPrivateKey:()=>fs,pkcs1ToJwk:()=>If,pkcs1ToRSAPrivateKey:()=>fa,pkixMessageToJwk:()=>cs,pkixMessageToRSAPublicKey:()=>hs,pkixToJwk:()=>Lf,pkixToRSAPublicKey:()=>ls});var un=$r;var ze=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 at.createV1(114,this._multihash)}toString(){return Z.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}verify(t,e,n){return ua(this.jwk,e,t,n)}},wr=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:bt(this.raw,t.raw)}sign(t,e){return ca(this.jwk,t,e)}};var ss=8192,is=18,Sf=1062,Af=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function If(r){let t=Mt(r);return as(t)}function as(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 Bf(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 j("JWK was missing components");return ne([gt(Uint8Array.from([0])),gt(z(r.n,"base64url")),gt(z(r.e,"base64url")),gt(z(r.d,"base64url")),gt(z(r.p,"base64url")),gt(z(r.q,"base64url")),gt(z(r.dp,"base64url")),gt(z(r.dq,"base64url")),gt(z(r.qi,"base64url"))]).subarray()}function Lf(r){let t=Mt(r,{offset:0});return cs(t)}function cs(r){let t=Mt(r[1],{offset:0});return{kty:"RSA",n:H(t[0],"base64url"),e:H(t[1],"base64url")}}function us(r){if(r.n==null||r.e==null)throw new j("JWK was missing components");return ne([Af,Fr(ne([gt(z(r.n,"base64url")),gt(z(r.e,"base64url"))]))]).subarray()}function fa(r){let t=Mt(r);return fs(t)}function fs(r){let t=as(r);return ds(t)}function ls(r,t){if(r.byteLength>=Sf)throw new Le("Key size is too large");let e=Mt(r,{offset:0});return hs(e,r,t)}function hs(r,t,e){let n=cs(r);if(e==null){let o=un(Kt.encode({Type:tt.RSA,Data:t}));e=Nt(is,o)}return new ze(n,e)}function ds(r){if(pa(r)>ss)throw new j("Key size is too large");let t=ha(r),e=un(Kt.encode({Type:tt.RSA,Data:us(t.publicKey)})),n=Nt(is,e);return new wr(t.privateKey,new ze(t.publicKey,n))}async function la(r){if(r>ss)throw new j("Key size is too large");let t=await da(r),e=un(Kt.encode({Type:tt.RSA,Data:us(t.publicKey)})),n=Nt(is,e);return new wr(t.privateKey,new ze(t.publicKey,n))}function ha(r){if(r==null)throw new j("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function da(r,t){let e=await Lt.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 _f(e,t);return{privateKey:n[0],publicKey:n[1]}}async function ca(r,t,e){let n=await Lt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);e?.signal?.throwIfAborted();let o=await Lt.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 ua(r,t,e,n){let o=await Lt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await Lt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,e instanceof Uint8Array?e:e.subarray());return n?.signal?.throwIfAborted(),s}async function _f(r,t){if(r.privateKey==null||r.publicKey==null)throw new j("Private and public key are required");let e=await Promise.all([Lt.get().subtle.exportKey("jwk",r.privateKey),Lt.get().subtle.exportKey("jwk",r.publicKey)]);return t?.signal?.throwIfAborted(),e}function pa(r){if(r.kty!=="RSA")throw new j("invalid key type");if(r.n==null)throw new j("invalid key modulus");return z(r.n,"base64url").length*8}var fn=class extends Ke{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,zr(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),Vt(s)}update(t){return ke(this),this.iHash.update(t),this}digestInto(t){ke(this),wt(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()}},ps=(r,t,e)=>new fn(r,t).update(e).digest();ps.create=(r,t)=>new fn(r,t);var ma=(r,t)=>(r+(r>=0?t:-t)/ya)/t;function Tf(r,t,e){let[[n,o],[s,i]]=t,a=ma(i*r,e),c=ma(-o*r,e),u=r-a*n-c*s,d=-a*o-c*i,l=u<Jt,f=d<Jt;l&&(u=-u),f&&(d=-d);let h=ce(Math.ceil(Xr(e)/2))+je;if(u<Jt||u>=h||d<Jt||d>=h)throw new Error("splitScalar (endomorphism): failed, k="+r);return{k1neg:l,k1:u,k2neg:f,k2:d}}function ys(r){if(!["compact","recovered","der"].includes(r))throw new Error('Signature format must be "compact", "recovered", or "der"');return r}function ms(r,t){let e={};for(let n of Object.keys(t))e[n]=r[n]===void 0?t[n]:r[n];return zt(e.lowS,"lowS"),zt(e.prehash,"prehash"),e.format!==void 0&&ys(e.format),e}var bs=class extends Error{constructor(t=""){super(t)}},Wt={Err:bs,_tlv:{encode:(r,t)=>{let{Err:e}=Wt;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}=Wt,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}=Wt;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}=Wt;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 Ue(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Wt,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}=Wt,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),je=BigInt(1),ya=BigInt(2),ln=BigInt(3),Df=BigInt(4);function Ge(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 Pf(r,t={}){let e=Jr("weierstrass",r,t),{Fp:n,Fn:o}=e,s=e.CURVE,{h:i,n:a}=s;ue(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:c}=t;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=ga(n,o);function d(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(D,g,m){let{x:y,y:S}=g.toAffine(),I=n.toBytes(y);if(zt(m,"isCompressed"),m){d();let P=!n.isOdd(S);return ht(ba(P),I)}else return ht(Uint8Array.of(4),I,n.toBytes(S))}function f(D){St(D,void 0,"Point");let{publicKey:g,publicKeyUncompressed:m}=u,y=D.length,S=D[0],I=D.subarray(1);if(y===g&&(S===2||S===3)){let P=n.fromBytes(I);if(!n.isValid(P))throw new Error("bad point: is not on curve, wrong x");let B=E(P),L;try{L=n.sqrt(B)}catch($){let F=$ instanceof Error?": "+$.message:"";throw new Error("bad point: is not on curve, sqrt error"+F)}d();let N=n.isOdd(L);return(S&1)===1!==N&&(L=n.neg(L)),{x:P,y:L}}else if(y===m&&S===4){let P=n.BYTES,B=n.fromBytes(I.subarray(0,P)),L=n.fromBytes(I.subarray(P,P*2));if(!v(B,L))throw new Error("bad point: is not on curve");return{x:B,y:L}}else throw new Error(`bad point: got length ${y}, expected compressed=${g} or uncompressed=${m}`)}let h=t.toBytes||l,p=t.fromBytes||f;function E(D){let g=n.sqr(D),m=n.mul(g,D);return n.add(n.add(m,n.mul(D,s.a)),s.b)}function v(D,g){let m=n.sqr(g),y=E(D);return n.eql(m,y)}if(!v(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let b=n.mul(n.pow(s.a,ln),Df),A=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(b,A)))throw new Error("bad curve params: a or b");function w(D,g,m=!1){if(!n.isValid(g)||m&&n.is0(g))throw new Error(`bad point coordinate ${D}`);return g}function _(D){if(!(D instanceof x))throw new Error("ProjectivePoint expected")}function C(D){if(!c||!c.basises)throw new Error("no endo");return Tf(D,c.basises,o.ORDER)}let M=Me((D,g)=>{let{X:m,Y:y,Z:S}=D;if(n.eql(S,n.ONE))return{x:m,y};let I=D.is0();g==null&&(g=I?n.ONE:n.inv(S));let P=n.mul(m,g),B=n.mul(y,g),L=n.mul(S,g);if(I)return{x:n.ZERO,y:n.ZERO};if(!n.eql(L,n.ONE))throw new Error("invZ was invalid");return{x:P,y:B}}),U=Me(D=>{if(D.is0()){if(t.allowInfinityPoint&&!n.is0(D.Y))return;throw new Error("bad point: ZERO")}let{x:g,y:m}=D.toAffine();if(!n.isValid(g)||!n.isValid(m))throw new Error("bad point: x or y not field elements");if(!v(g,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 R(D,g,m,y,S){return m=new x(n.mul(m.X,D),m.Y,m.Z),g=pr(y,g),m=pr(S,m),g.add(m)}class x{constructor(g,m,y){this.X=w("x",g),this.Y=w("y",m,!0),this.Z=w("z",y),Object.freeze(this)}static CURVE(){return s}static fromAffine(g){let{x:m,y}=g||{};if(!g||!n.isValid(m)||!n.isValid(y))throw new Error("invalid affine point");if(g instanceof x)throw new Error("projective point not allowed");return n.is0(m)&&n.is0(y)?x.ZERO:new x(m,y,n.ONE)}static fromBytes(g){let m=x.fromAffine(p(St(g,void 0,"point")));return m.assertValidity(),m}static fromHex(g){return x.fromBytes(V("pointHex",g))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=8,m=!0){return K.createCache(this,g),m||this.multiply(ln),this}assertValidity(){U(this)}hasEvenY(){let{y:g}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(g)}equals(g){_(g);let{X:m,Y:y,Z:S}=this,{X:I,Y:P,Z:B}=g,L=n.eql(n.mul(m,B),n.mul(I,S)),N=n.eql(n.mul(y,B),n.mul(P,S));return L&&N}negate(){return new x(this.X,n.neg(this.Y),this.Z)}double(){let{a:g,b:m}=s,y=n.mul(m,ln),{X:S,Y:I,Z:P}=this,B=n.ZERO,L=n.ZERO,N=n.ZERO,k=n.mul(S,S),$=n.mul(I,I),F=n.mul(P,P),O=n.mul(S,I);return O=n.add(O,O),N=n.mul(S,P),N=n.add(N,N),B=n.mul(g,N),L=n.mul(y,F),L=n.add(B,L),B=n.sub($,L),L=n.add($,L),L=n.mul(B,L),B=n.mul(O,B),N=n.mul(y,N),F=n.mul(g,F),O=n.sub(k,F),O=n.mul(g,O),O=n.add(O,N),N=n.add(k,k),k=n.add(N,k),k=n.add(k,F),k=n.mul(k,O),L=n.add(L,k),F=n.mul(I,P),F=n.add(F,F),k=n.mul(F,O),B=n.sub(B,k),N=n.mul(F,$),N=n.add(N,N),N=n.add(N,N),new x(B,L,N)}add(g){_(g);let{X:m,Y:y,Z:S}=this,{X:I,Y:P,Z:B}=g,L=n.ZERO,N=n.ZERO,k=n.ZERO,$=s.a,F=n.mul(s.b,ln),O=n.mul(m,I),Y=n.mul(y,P),rt=n.mul(S,B),mt=n.add(m,y),X=n.add(I,P);mt=n.mul(mt,X),X=n.add(O,Y),mt=n.sub(mt,X),X=n.add(m,S);let it=n.add(I,B);return X=n.mul(X,it),it=n.add(O,rt),X=n.sub(X,it),it=n.add(y,S),L=n.add(P,B),it=n.mul(it,L),L=n.add(Y,rt),it=n.sub(it,L),k=n.mul($,X),L=n.mul(F,rt),k=n.add(L,k),L=n.sub(Y,k),k=n.add(Y,k),N=n.mul(L,k),Y=n.add(O,O),Y=n.add(Y,O),rt=n.mul($,rt),X=n.mul(F,X),Y=n.add(Y,rt),rt=n.sub(O,rt),rt=n.mul($,rt),X=n.add(X,rt),O=n.mul(Y,X),N=n.add(N,O),O=n.mul(it,X),L=n.mul(mt,L),L=n.sub(L,O),O=n.mul(mt,Y),k=n.mul(it,k),k=n.add(k,O),new x(L,N,k)}subtract(g){return this.add(g.negate())}is0(){return this.equals(x.ZERO)}multiply(g){let{endo:m}=t;if(!o.isValidNot0(g))throw new Error("invalid scalar: out of range");let y,S,I=P=>K.cached(this,P,B=>Zt(x,B));if(m){let{k1neg:P,k1:B,k2neg:L,k2:N}=C(g),{p:k,f:$}=I(B),{p:F,f:O}=I(N);S=$.add(O),y=R(m.beta,k,F,P,L)}else{let{p:P,f:B}=I(g);y=P,S=B}return Zt(x,[y,S])[0]}multiplyUnsafe(g){let{endo:m}=t,y=this;if(!o.isValid(g))throw new Error("invalid scalar: out of range");if(g===Jt||y.is0())return x.ZERO;if(g===je)return y;if(K.hasCache(this))return this.multiply(g);if(m){let{k1neg:S,k1:I,k2neg:P,k2:B}=C(g),{p1:L,p2:N}=Gi(x,y,I,B);return R(m.beta,L,N,S,P)}else return K.unsafe(y,g)}multiplyAndAddUnsafe(g,m,y){let S=this.multiplyUnsafe(m).add(g.multiplyUnsafe(y));return S.is0()?void 0:S}toAffine(g){return M(this,g)}isTorsionFree(){let{isTorsionFree:g}=t;return i===je?!0:g?g(x,this):K.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:g}=t;return i===je?this:g?g(x,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(g=!0){return zt(g,"isCompressed"),this.assertValidity(),h(x,this,g)}toHex(g=!0){return Bt(this.toBytes(g))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(g=!0){return this.toBytes(g)}_setWindowSize(g){this.precompute(g)}static normalizeZ(g){return Zt(x,g)}static msm(g,m){return He(x,o,g,m)}static fromPrivateKey(g){return x.BASE.multiply(Ge(o,g))}}x.BASE=new x(s.Gx,s.Gy,n.ONE),x.ZERO=new x(n.ZERO,n.ONE,n.ZERO),x.Fp=n,x.Fn=o;let T=o.BITS,K=new qe(x,t.endo?Math.ceil(T/2):T);return x.BASE.precompute(8),x}function ba(r){return Uint8Array.of(r?2:3)}function ga(r,t){return{secretKey:t.BYTES,publicKey:1+r.BYTES,publicKeyUncompressed:1+2*r.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Cf(r,t={}){let{Fn:e}=r,n=t.randomBytes||oe,o=Object.assign(ga(r.Fp,e),{seed:So(e.ORDER)});function s(h){try{return!!Ge(e,h)}catch{return!1}}function i(h,p){let{publicKey:E,publicKeyUncompressed:v}=o;try{let b=h.length;return p===!0&&b!==E||p===!1&&b!==v?!1:!!r.fromBytes(h)}catch{return!1}}function a(h=n(o.seed)){return Ao(St(h,o.seed,"seed"),e.ORDER)}function c(h,p=!0){return r.BASE.multiply(Ge(e,h)).toBytes(p)}function u(h){let p=a(h);return{secretKey:p,publicKey:c(p)}}function d(h){if(typeof h=="bigint")return!1;if(h instanceof r)return!0;let{secretKey:p,publicKey:E,publicKeyUncompressed:v}=o;if(e.allowedLengths||p===E)return;let b=V("key",h).length;return b===E||b===v}function l(h,p,E=!0){if(d(h)===!0)throw new Error("first arg must be private key");if(d(p)===!1)throw new Error("second arg must be public key");let v=Ge(e,h);return r.fromHex(p).multiply(v).toBytes(E)}return Object.freeze({getPublicKey:c,getSharedSecret:l,keygen:u,Point:r,utils:{isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a,isValidPrivateKey:s,randomPrivateKey:a,normPrivateKeyToScalar:h=>Ge(e,h),precompute(h=8,p=r.BASE){return p.precompute(h,!1)}},lengths:o})}function Nf(r,t,e={}){zr(t),ue(e,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=e.randomBytes||oe,o=e.hmac||((m,...y)=>ps(t,m,ht(...y))),{Fp:s,Fn:i}=r,{ORDER:a,BITS:c}=i,{keygen:u,getPublicKey:d,getSharedSecret:l,utils:f,lengths:h}=Cf(r,e),p={prehash:!1,lowS:typeof e.lowS=="boolean"?e.lowS:!1,format:void 0,extraEntropy:!1},E="compact";function v(m){let y=a>>je;return m>y}function b(m,y){if(!i.isValidNot0(y))throw new Error(`invalid signature ${m}: out of range 1..Point.Fn.ORDER`);return y}function A(m,y){ys(y);let S=h.signature,I=y==="compact"?S:y==="recovered"?S+1:void 0;return St(m,I,`${y} signature`)}class w{constructor(y,S,I){this.r=b("r",y),this.s=b("s",S),I!=null&&(this.recovery=I),Object.freeze(this)}static fromBytes(y,S=E){A(y,S);let I;if(S==="der"){let{r:N,s:k}=Wt.toSig(St(y));return new w(N,k)}S==="recovered"&&(I=y[0],S="compact",y=y.subarray(1));let P=i.BYTES,B=y.subarray(0,P),L=y.subarray(P,P*2);return new w(i.fromBytes(B),i.fromBytes(L),I)}static fromHex(y,S){return this.fromBytes(be(y),S)}addRecoveryBit(y){return new w(this.r,this.s,y)}recoverPublicKey(y){let S=s.ORDER,{r:I,s:P,recovery:B}=this;if(B==null||![0,1,2,3].includes(B))throw new Error("recovery id invalid");if(a*ya<S&&B>1)throw new Error("recovery id is ambiguous for h>1 curve");let N=B===2||B===3?I+a:I;if(!s.isValid(N))throw new Error("recovery id 2 or 3 invalid");let k=s.toBytes(N),$=r.fromBytes(ht(ba((B&1)===0),k)),F=i.inv(N),O=C(V("msgHash",y)),Y=i.create(-O*F),rt=i.create(P*F),mt=r.BASE.multiplyUnsafe(Y).add($.multiplyUnsafe(rt));if(mt.is0())throw new Error("point at infinify");return mt.assertValidity(),mt}hasHighS(){return v(this.s)}toBytes(y=E){if(ys(y),y==="der")return be(Wt.hexFromSig(this));let S=i.toBytes(this.r),I=i.toBytes(this.s);if(y==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return ht(Uint8Array.of(this.recovery),S,I)}return ht(S,I)}toHex(y){return Bt(this.toBytes(y))}assertValidity(){}static fromCompact(y){return w.fromBytes(V("sig",y),"compact")}static fromDER(y){return w.fromBytes(V("sig",y),"der")}normalizeS(){return this.hasHighS()?new w(this.r,i.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return Bt(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return Bt(this.toBytes("compact"))}}let _=e.bits2int||function(y){if(y.length>8192)throw new Error("input is too large");let S=Ue(y),I=y.length*8-c;return I>0?S>>BigInt(I):S},C=e.bits2int_modN||function(y){return i.create(_(y))},M=ce(c);function U(m){return hr("num < 2^"+c,m,Jt,M),i.toBytes(m)}function R(m,y){return St(m,void 0,"message"),y?St(t(m),void 0,"prehashed message"):m}function x(m,y,S){if(["recovered","canonical"].some(Y=>Y in S))throw new Error("sign() legacy options not supported");let{lowS:I,prehash:P,extraEntropy:B}=ms(S,p);m=R(m,P);let L=C(m),N=Ge(i,y),k=[U(N),U(L)];if(B!=null&&B!==!1){let Y=B===!0?n(h.secretKey):B;k.push(V("extraEntropy",Y))}let $=ht(...k),F=L;function O(Y){let rt=_(Y);if(!i.isValidNot0(rt))return;let mt=i.inv(rt),X=r.BASE.multiply(rt).toAffine(),it=i.create(X.x);if(it===Jt)return;let Kr=i.create(mt*i.create(F+it*N));if(Kr===Jt)return;let Ns=(X.x===it?0:2)|Number(X.y&je),Rs=Kr;return I&&v(Kr)&&(Rs=i.neg(Kr),Ns^=1),new w(it,Rs,Ns)}return{seed:$,k2sig:O}}function T(m,y,S={}){m=V("message",m);let{seed:I,k2sig:P}=x(m,y,S);return Ti(t.outputLen,i.BYTES,o)(I,P)}function K(m){let y,S=typeof m=="string"||Ht(m),I=!S&&m!==null&&typeof m=="object"&&typeof m.r=="bigint"&&typeof m.s=="bigint";if(!S&&!I)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(I)y=new w(m.r,m.s);else if(S){try{y=w.fromBytes(V("sig",m),"der")}catch(P){if(!(P instanceof Wt.Err))throw P}if(!y)try{y=w.fromBytes(V("sig",m),"compact")}catch{return!1}}return y||!1}function D(m,y,S,I={}){let{lowS:P,prehash:B,format:L}=ms(I,p);if(S=V("publicKey",S),y=R(V("message",y),B),"strict"in I)throw new Error("options.strict was renamed to lowS");let N=L===void 0?K(m):w.fromBytes(V("sig",m),L);if(N===!1)return!1;try{let k=r.fromBytes(S);if(P&&N.hasHighS())return!1;let{r:$,s:F}=N,O=C(y),Y=i.inv(F),rt=i.create(O*Y),mt=i.create($*Y),X=r.BASE.multiplyUnsafe(rt).add(k.multiplyUnsafe(mt));return X.is0()?!1:i.create(X.x)===$}catch{return!1}}function g(m,y,S={}){let{prehash:I}=ms(S,p);return y=R(y,I),w.fromBytes(m,"recovered").recoverPublicKey(y).toBytes()}return Object.freeze({keygen:u,getPublicKey:d,getSharedSecret:l,utils:f,lengths:h,Point:r,sign:T,verify:D,recoverPublicKey:g,Signature:w,hash:t})}function Rf(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=At(t.n,{BITS:r.nBitLength,allowedLengths:n,modFromBytes: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 Kf(r){let{CURVE:t,curveOpts:e}=Rf(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 kf(r,t){let e=t.Point;return Object.assign({},t,{ProjectivePoint:e,CURVE:Object.assign({},r,Wr(e.Fn.ORDER,e.Fn.BITS))})}function wa(r){let{CURVE:t,curveOpts:e,hash:n,ecdsaOpts:o}=Kf(r),s=Pf(t,e),i=Nf(s,n,o);return kf(r,i)}function xa(r,t){let e=n=>wa({...r,hash:n});return{...e(t),create:e}}var ws={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Uf={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Ea=BigInt(2);function Mf(r){let t=ws.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,l=G(d,e,t)*d%t,f=G(l,e,t)*d%t,h=G(f,Ea,t)*u%t,p=G(h,o,t)*h%t,E=G(p,s,t)*p%t,v=G(E,a,t)*E%t,b=G(v,c,t)*v%t,A=G(b,a,t)*E%t,w=G(A,e,t)*d%t,_=G(w,i,t)*p%t,C=G(_,n,t)*u%t,M=G(C,Ea,t);if(!gs.eql(gs.sqr(M),r))throw new Error("Cannot find square root");return M}var gs=At(ws.p,{sqrt:Mf}),Ze=xa({...ws,Fp:gs,lowS:!0,endo:Uf},$r);function va(r,t,e,n){let o=me.digest(e instanceof Uint8Array?e:e.subarray());if(rn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Ze.verify(t,s,r))).catch(s=>{throw s.name==="AbortError"?s:new yr(String(s))});try{return n?.signal?.throwIfAborted(),Ze.verify(t,o.digest,r)}catch(s){throw new yr(String(s))}}var hn=class{type="secp256k1";raw;_key;constructor(t){this._key=Aa(t),this.raw=Sa(this._key)}toMultihash(){return Dt.digest(Ot(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return Z.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}verify(t,e,n){return va(this._key,e,t,n)}};function xs(r){return new hn(r)}function Sa(r){return Ze.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Aa(r){try{return Ze.ProjectivePoint.fromHex(r),r}catch(t){throw new Le(String(t))}}function Es(r,t){let{Type:e,Data:n}=Kt.decode(r),o=n??new Uint8Array;switch(e){case tt.RSA:return ls(o,t);case tt.Ed25519:return Ko(o);case tt.secp256k1:return xs(o);case tt.ECDSA:return co(o);default:throw new de}}function Ia(r){let{Type:t,Data:e}=Kt.decode(r.digest),n=e??new Uint8Array;switch(t){case tt.Ed25519:return Ko(n);case tt.secp256k1:return xs(n);case tt.ECDSA:return co(n);default:throw new de}}function Ot(r){return Kt.encode({Type:tt[r.type],Data:r.raw})}var Ba=Symbol.for("nodejs.util.inspect.custom"),Of=114,Er=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()})`}[Rn]=!0;toString(){return this.string==null&&(this.string=Z.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return at.createV1(Of,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return bt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return bt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Ba](){return`PeerId(${this.toString()})`}},vr=class extends Er{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Sr=class extends Er{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Ar=class extends Er{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},qf=2336,dn=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Dt.digest(z(this.url))}[Ba](){return`PeerId(${this.url})`}[Rn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return at.createV1(qf,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=H(t)),t.toString()===this.toString())}};function vs(r){if(r.type==="Ed25519")return new Sr({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new Ar({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new vr({multihash:r.toCID().multihash,publicKey:r});throw new de}function La(r){return vs(r.publicKey)}function Ir(r){if(Vf(r))return new vr({multihash:r});if(Hf(r))try{let t=Ia(r);if(t.type==="Ed25519")return new Sr({multihash:r,publicKey:t});if(t.type==="secp256k1")return new Ar({multihash:r,publicKey:t})}catch{let e=H(r.digest);return new dn(new URL(e))}throw new Mr("Supplied PeerID Multihash is invalid")}function Hf(r){return r.code===Dt.code}function Vf(r){return r.code===me.code}function Ae(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 pn(r){let t=ee(Z.decode(`z${r}`));return Ir(t)}var Br=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 Ae(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 Ae(this.map.values(),t=>t.key)}values(){return Ae(this.map.values(),t=>t.value)}get size(){return this.map.size}};var Lr=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 Ae(this.set.entries(),t=>{let e=pn(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=pn(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return Ae(this.set.values(),t=>pn(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 Qt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var mn=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 mn(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 mn(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 Ss=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function Ye(r={}){return Ff(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 Ff(r,t){t=t??{};let e=t.onEnd,n=new $e,o,s,i,a=Qt(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((v,b)=>{s=A=>{s=null,n.push(A);try{v(r(n))}catch(w){b(w)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Qt()})}},u=v=>s!=null?s(v):(n.push(v),o),d=v=>(n=new $e,s!=null?s({error:v}):(n.push({error:v}),o)),l=v=>{if(i)return o;if(t?.objectMode!==!0&&v?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:v})},f=v=>i?o:(i=!0,v!=null?d(v):u({done:!0})),h=()=>(n=new $e,f(),{done:!0}),p=v=>(f(v),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:h,throw:p,push:l,end:f,get readableLength(){return n.size},onEmpty:async v=>{let b=v?.signal;if(b?.throwIfAborted(),n.isEmpty())return;let A,w;b!=null&&(A=new Promise((_,C)=>{w=()=>{C(new Ss)},b.addEventListener("abort",w)}));try{await Promise.race([a.promise,A])}finally{w!=null&&b!=null&&b?.removeEventListener("abort",w)}}},e==null)return o;let E=o;return o={[Symbol.asyncIterator](){return this},next(){return E.next()},throw(v){return E.throw(v),e!=null&&(e(v),e=void 0),{done:!0}},return(){return E.return(),e!=null&&(e(),e=void 0),{done:!0}},push:l,end(v){return E.end(v),e!=null&&(e(v),e=void 0),o},get readableLength(){return E.readableLength},onEmpty:v=>E.onEmpty(v)},o}var _r=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},As=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},_a=r=>globalThis.DOMException===void 0?new As(r):new DOMException(r),Ta=r=>{let t=r.reason===void 0?_a("This operation was aborted."):r.reason;return t instanceof Error?t:_a(t)};function Ie(r,t){let{milliseconds:e,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=t,i,a,u=new Promise((d,l)=>{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&&l(Ta(h)),a=()=>{l(Ta(h))},h.addEventListener("abort",a,{once:!0})}if(e===Number.POSITIVE_INFINITY){r.then(d,l);return}let f=new _r;i=s.setTimeout.call(void 0,()=>{if(n){try{d(n())}catch(h){l(h)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?d():o instanceof Error?l(o):(f.message=o??`Promise timed out after ${e} milliseconds`,l(f))},e),(async()=>{try{d(await r)}catch(h){l(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}var zf=r=>{let t=r.addEventListener||r.on||r.addListener,e=r.removeEventListener||r.off||r.removeListener;if(!t||!e)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(r),removeListener:e.bind(r)}};function Gf(r,t,e){let n,o=new Promise((s,i)=>{if(e={rejectionEvents:["error"],multiArgs:!1,resolveImmediately:!1,...e},!(e.count>=0&&(e.count===Number.POSITIVE_INFINITY||Number.isInteger(e.count))))throw new TypeError("The `count` option should be at least 0 or more");e.signal?.throwIfAborted();let a=[t].flat(),c=[],{addListener:u,removeListener:d}=zf(r),l=(...h)=>{let p=e.multiArgs?h:h[0];e.filter&&!e.filter(p)||(c.push(p),e.count===c.length&&(n(),s(c)))},f=h=>{n(),i(h)};n=()=>{for(let h of a)d(h,l);for(let h of e.rejectionEvents)d(h,f)};for(let h of a)u(h,l);for(let h of e.rejectionEvents)u(h,f);e.signal&&e.signal.addEventListener("abort",()=>{f(e.signal.reason)},{once:!0}),e.resolveImmediately&&s(c)});if(o.cancel=n,typeof e.timeout=="number"){let s=Ie(o,{milliseconds:e.timeout});return s.cancel=n,s}return o}function Da(r,t,e){typeof e=="function"&&(e={filter:e}),e={...e,count:1,resolveImmediately:!1};let n=Gf(r,t,e),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}var yn=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 Pa(r,t,e){if(t==null)return r;if(t.aborted)return r.catch(()=>{}),Promise.reject(new yn(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new yn(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 Is=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=Qt(),this.haveNext=Qt()}[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=Qt(),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=Qt(),await Pa(this.readNext.promise,e?.signal,e)}};function Ca(){return new Is}function jf(r){return r[Symbol.asyncIterator]!=null}async function Zf(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*$f(r){let t=new AbortController,e=Ca();Zf(r,e,t.signal).catch(()=>{});try{yield*e}finally{t.abort()}}function*Yf(r){for(let t of r)yield*t}function Xf(...r){let t=[];for(let e of r)jf(e)||t.push(e);return t.length===r.length?Yf(t):$f(r)}var Na=Xf;function bn(r,...t){if(r==null)throw new Error("Empty pipeline");if(Bs(r)){let n=r;r=()=>n.source}else if(Ka(r)||Ra(r)){let n=r;r=()=>n}let e=[r,...t];if(e.length>1&&Bs(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++)Bs(e[n])&&(e[n]=Jf(e[n]));return Wf(...e)}var Wf=(...r)=>{let t;for(;r.length>0;)t=r.shift()(t);return t},Ra=r=>r?.[Symbol.asyncIterator]!=null,Ka=r=>r?.[Symbol.iterator]!=null,Bs=r=>r==null?!1:r.sink!=null&&r.source!=null,Jf=r=>t=>{let e=r.sink(t);if(e?.then!=null){let n=Ye({objectMode:!0});e.then(()=>{n.end()},i=>{n.end(i)});let o,s=r.source;if(Ra(s))o=async function*(){yield*s,n.end()};else if(Ka(s))o=function*(){yield*s,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return Na(n,o())}return r.source};function Qf(r){return r?.addEventListener!=null}function tl(r){let t=Ye(),e,n=i=>{t.push(i.data)},o=()=>{t.end(),r.removeEventListener("message",n),r.removeEventListener("close",s),r.removeEventListener("remoteCloseWrite",o)},s=i=>{t.end(i.error),i.error!=null&&e?.reject(i.error),r.removeEventListener("message",n),r.removeEventListener("close",s),r.removeEventListener("remoteCloseWrite",o)};return r.addEventListener("message",n),r.addEventListener("close",s,{once:!0}),r.addEventListener("remoteCloseWrite",o,{once:!0}),{source:t,async sink(i){async function*a(){yield*i}let c=a();for(;;){e=Promise.withResolvers();let{done:u,value:d}=await Promise.race([c.next(),e.promise]);if(r.writeStatus==="closing"||r.writeStatus==="closed"||(d!=null&&(r.send(d)||await Promise.race([Da(r,"drain",{rejectionEvents:["close"]})])),u===!0))break}await r.close()}}}function Ls(...r){let t=r.map(e=>Qf(e)?tl(e):e);return bn(...t)}var gn=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Xe=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},wn=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},Tr=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function xn(r){return r[Symbol.asyncIterator]!=null}function ka(r,t){if(r.byteLength>t)throw new Xe("Message length too long")}var vn=r=>{let t=_t(r),e=ct(t);return Vo(r,e),vn.bytes=t,e};vn.bytes=0;function Sn(r,t){t=t??{};let e=t.lengthEncoder??vn,n=t?.maxDataLength??4194304;function*o(s){ka(s,n);let i=e(s.byteLength);i instanceof Uint8Array?yield i:yield*i,s instanceof Uint8Array?yield s:yield*s}return xn(r)?(async function*(){for await(let s of r)yield*o(s)})():(function*(){for(let s of r)yield*o(s)})()}Sn.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??vn,n=t?.maxDataLength??4194304;return ka(r,n),new et(e(r.byteLength),r)};var Be;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(Be||(Be={}));var _s=r=>{let t=Fo(r);return _s.bytes=_t(t),t};_s.bytes=0;function Dr(r,t){let e=new et,n=Be.LENGTH,o=-1,s=t?.lengthDecoder??_s,i=t?.maxLengthLength??8,a=t?.maxDataLength??4194304;function*c(){for(;e.byteLength>0;){if(n===Be.LENGTH)try{if(o=s(e),o<0)throw new gn("Invalid message length");if(o>a)throw new Xe("Message length too long");let u=s.bytes;e.consume(u),t?.onLength!=null&&t.onLength(o),n=Be.DATA}catch(u){if(u instanceof RangeError){if(e.byteLength>i)throw new wn("Message length length too long");break}throw u}if(n===Be.DATA){if(e.byteLength<o)break;let u=e.sublist(0,o);e.consume(o),t?.onData!=null&&t.onData(u),yield u,n=Be.LENGTH}}}return xn(r)?(async function*(){for await(let u of r)e.append(u),yield*c();if(e.byteLength>0)throw new Tr("Unexpected end of input")})():(function*(){for(let u of r)e.append(u),yield*c();if(e.byteLength>0)throw new Tr("Unexpected end of input")})()}Dr.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 Dr(n,{...t??{},onLength:s=>{e=s}})};var Ds=tc(Ma(),1);function Ps(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 Cr=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=Ps(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 Nr=class extends Ds.default{#t;#i;#s=0;#d;#a;#p=0;#r;#c;#e;#m;#n=0;#u;#o;#y;#w=1n;timeout;constructor(t){if(super(),t={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Cr,...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#x(){return this.#i||this.#s<this.#d}get#E(){return this.#n<this.#u}#v(){this.#n--,this.#f(),this.emit("next")}#S(){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.#S()},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.#x&&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.#w++).toString(),e={timeout:this.timeout,throwOnTimeout:this.#y,...e},new Promise((n,o)=>{this.#e.enqueue(async()=>{this.#n++;try{e.signal?.throwIfAborted(),this.#s++;let s=t({signal:e.signal});e.timeout&&(s=Ie(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 _r&&!e.throwOnTimeout){n();return}o(s),this.emit("error",s)}finally{this.#v()}},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}};var In=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 We;(function(r){let t;(function(o){let s;o.codec=()=>(s==null&&(s=vt((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 l=i.uint32();switch(l>>>3){case 1:{u.subscribe=i.bool();break}case 2:{u.topic=i.string();break}default:{i.skipType(l&7);break}}}return u})),s),o.encode=i=>Et(i,o.codec()),o.decode=(i,a)=>xt(i,o.codec(),a)})(t=r.SubOpts||(r.SubOpts={}));let e;(function(o){let s;o.codec=()=>(s==null&&(s=vt((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 l=i.uint32();switch(l>>>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(l&7);break}}}return u})),s),o.encode=i=>Et(i,o.codec()),o.decode=(i,a)=>xt(i,o.codec(),a)})(e=r.Message||(r.Message={}));let n;r.codec=()=>(n==null&&(n=vt((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),Bn.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 Tt('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 Tt('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=Bn.codec().decode(o,o.uint32(),{limits:i.limits?.control});break}default:{o.skipType(u&7);break}}}return a})),n),r.encode=o=>Et(o,r.codec()),r.decode=(o,s)=>xt(o,r.codec(),s)})(We||(We={}));var Bn;(function(r){let t;r.codec=()=>(t==null&&(t=vt((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.ihave!=null)for(let s of e.ihave)n.uint32(10),Ln.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),Tn.codec().encode(s,n);if(e.prune!=null)for(let s of e.prune)n.uint32(34),Dn.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 Tt('Decode error - map field "ihave" had too many elements');s.ihave.push(Ln.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 Tt('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 Tt('Decode error - map field "graft" had too many elements');s.graft.push(Tn.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 Tt('Decode error - map field "prune" had too many elements');s.prune.push(Dn.codec().decode(e,e.uint32(),{limits:o.limits?.prune$}));break}default:{e.skipType(a&7);break}}}return s})),t),r.encode=e=>Et(e,r.codec()),r.decode=(e,n)=>xt(e,r.codec(),n)})(Bn||(Bn={}));var Ln;(function(r){let t;r.codec=()=>(t==null&&(t=vt((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 Tt('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=>Et(e,r.codec()),r.decode=(e,n)=>xt(e,r.codec(),n)})(Ln||(Ln={}));var _n;(function(r){let t;r.codec=()=>(t==null&&(t=vt((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 Tt('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=>Et(e,r.codec()),r.decode=(e,n)=>xt(e,r.codec(),n)})(_n||(_n={}));var Tn;(function(r){let t;r.codec=()=>(t==null&&(t=vt((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=>Et(e,r.codec()),r.decode=(e,n)=>xt(e,r.codec(),n)})(Tn||(Tn={}));var Dn;(function(r){let t;r.codec=()=>(t==null&&(t=vt((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),Pn.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 Tt('Decode error - map field "peers" had too many elements');s.peers.push(Pn.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=>Et(e,r.codec()),r.decode=(e,n)=>xt(e,r.codec(),n)})(Dn||(Dn={}));var Pn;(function(r){let t;r.codec=()=>(t==null&&(t=vt((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=>Et(e,r.codec()),r.decode=(e,n)=>xt(e,r.codec(),n)})(Pn||(Pn={}));var sl=r=>{let t=r.addEventListener||r.on||r.addListener,e=r.removeEventListener||r.off||r.removeListener;if(!t||!e)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(r),removeListener:e.bind(r)}};function il(r,t,e){let n,o=new Promise((s,i)=>{if(e={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...e},!(e.count>=0&&(e.count===Number.POSITIVE_INFINITY||Number.isInteger(e.count))))throw new TypeError("The `count` option should be at least 0 or more");e.signal?.throwIfAborted();let a=[t].flat(),c=[],{addListener:u,removeListener:d}=sl(r),l=async(...h)=>{let p=e.multiArgs?h:h[0];if(e.filter)try{if(!await e.filter(p))return}catch(E){n(),i(E);return}c.push(p),e.count===c.length&&(n(),s(c))},f=(...h)=>{n(),i(e.rejectionMultiArgs?h:h[0])};n=()=>{for(let h of a)d(h,l);for(let h of e.rejectionEvents)a.includes(h)||d(h,f)};for(let h of a)u(h,l);for(let h of e.rejectionEvents)a.includes(h)||u(h,f);e.signal&&e.signal.addEventListener("abort",()=>{f(e.signal.reason)},{once:!0}),e.resolveImmediately&&s(c)});if(o.cancel=n,typeof e.timeout=="number"){let s=Ie(o,{milliseconds:e.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function Oa(r,t,e){typeof e=="function"&&(e={filter:e}),e={...e,count:1,resolveImmediately:!1};let n=il(r,t,e),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}var Cn=class extends _e{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=()=>{t.abort(new Ur)};return this._inboundAbortController.signal.addEventListener("abort",n,{once:!0}),this._rawInboundStream=t,this.inboundStream=Ls(this._rawInboundStream,o=>Dr(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=Ye({onEnd:n=>{this._rawOutboundStream?.close().catch(o=>{this.log("error closing outbound stream",o)}),this._rawOutboundStream=void 0,this.outboundStream=void 0,n!=null&&this.dispatchEvent(new CustomEvent("close"))}}),Ls(this.outboundStream,n=>Sn(n),async n=>{for await(let o of n)t.send(o)===!1&&await Oa(t,"drain",{rejectionEvents:["close"]})}).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 qa(){return BigInt(`0x${H(cn(8),"base16")}`)}var Ha=(r,t)=>{let e=z(t.toString(16).padStart(16,"0"),"base16"),n=Ot(r),o=new Uint8Array(n.byteLength+e.length);return o.set(n,0),o.set(e,n.byteLength),o},Va=r=>me.encode(r);var Fa=function(r){return Array.isArray(r)?r:[r]},al=async r=>{if(r.sequenceNumber==null||r.from==null||r.signature==null)return!1;let t=Ir(ee(r.from));if(t.publicKey!=null)return!0;if(r.key!=null){let e=r.key;return vs(Es(e)).equals(t)}return!1},za=async r=>{if(r.from==null)throw new Q("RPC message was missing from");if(!await al(r))return{type:"unsigned",topic:r.topic??"",data:r.data??new Uint8Array(0)};let t=Ir(ee(r.from)),e=r.key??t.publicKey;if(e==null)throw new Q("RPC message was missing public key");return{type:"signed",from:t,topic:r.topic??"",sequenceNumber:ul(r.sequenceNumber??new Uint8Array(0)),data:r.data??new Uint8Array(0),signature:r.signature??new Uint8Array(0),key:e instanceof Uint8Array?Es(e):e}},Rr=r=>r.type==="signed"?{from:r.from.toMultihash().bytes,data:r.data,sequenceNumber:cl(r.sequenceNumber),topic:r.topic,signature:r.signature,key:r.key?Ot(r.key):void 0}:{data:r.data,topic:r.topic},cl=r=>{let t=r.toString(16);return t.length%2!==0&&(t=`0${t}`),z(t,"base16")},ul=r=>BigInt(`0x${H(r,"base16")}`);var Ga=z("libp2p-pubsub:");async function ja(r,t,e){let n={type:"signed",topic:t.topic,data:t.data,sequenceNumber:t.sequenceNumber,from:La(r)},o=pe([Ga,e(Rr(n)).subarray()]);return n.signature=await r.sign(o),n.key=r.publicKey,n}async function Za(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=pe([Ga,t({...Rr(r),signature:void 0,key:void 0}).subarray()]);return fl(r).verify(e,r.signature)}function fl(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 Nn=class extends _e{log;started;topics;subscriptions;peers;globalSignaturePolicy;canRelayMessage;emitSelf;topicValidators;queue;protocols;components;_registrarTopologyIds;maxInboundStreams;maxOutboundStreams;seenCache;constructor(t,e){super(),this.log=t.logger.forComponent("libp2p:floodsub"),this.components=t,this.protocols=Fa(e.protocols??Cs),this.started=!1,this.topics=new Map,this.subscriptions=new Set,this.peers=new Br,this.globalSignaturePolicy=e.globalSignaturePolicy==="StrictNoSign"?"StrictNoSign":"StrictSign",this.canRelayMessage=e.canRelayMessage??!0,this.emitSelf=e.emitSelf??!1,this.topicValidators=new Map,this.queue=new Nr({concurrency:e.messageProcessingConcurrency??10}),this.maxInboundStreams=e.maxInboundStreams??1,this.maxOutboundStreams=e.maxOutboundStreams??1,this.seenCache=new In({validityMs:e?.seenTTL??3e4}),this._onIncomingStream=this._onIncomingStream.bind(this),this._onPeerConnected=this._onPeerConnected.bind(this),this._onPeerDisconnected=this._onPeerDisconnected.bind(this)}[Qe]=!0;[Symbol.toStringTag]="@libp2p/floodsub";[ks]=["@libp2p/pubsub"];[Us]=["@libp2p/identify"];async start(){if(this.started)return;this.log("starting");let t=this.components.registrar;await Promise.all(this.protocols.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.protocols.map(async n=>t.register(n,e))),this.log("started"),this.started=!0}async stop(){if(!this.started)return;let t=this.components.registrar;this._registrarTopologyIds!=null&&this._registrarTopologyIds?.forEach(e=>{t.unregister(e)}),await Promise.all(this.protocols.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,e){let n=e.remotePeer;if(t.protocol==null){t.abort(new Error("Stream was not multiplexed"));return}let o=this.addPeer(n,t.protocol),s=o.attachInboundStream(t);this.processMessages(n,s,o).catch(i=>{this.log(i)})}async _onPeerConnected(t,e){if(this.log("connected %p",t),e.streams.find(s=>s.direction==="outbound"&&s.protocol!=null&&this.protocols.includes(s.protocol))!=null){this.log("outbound pubsub streams already present on connection from %p",t);return}let n=await e.newStream(this.protocols);if(n.protocol==null){n.abort(new Error("Stream was not multiplexed"));return}await this.addPeer(t,n.protocol).attachOutboundStream(n),this.send(t,{subscriptions:Array.from(this.subscriptions).map(s=>s.toString()),subscribe:!0})}_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 Cn(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 bn(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 za(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 Lr,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)return;let n=await this.getMsgId(e),o=H(n,"base64");if(!this.seenCache.has(o)){this.seenCache.put(o,!0);try{await this.validate(t,e)}catch(s){this.log("Message is invalid, dropping it. %O",s);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 Q('Message type should be "signed" when signature policy is StrictSign but it was not');if(t.sequenceNumber==null)throw new Q("Need sequence number when signature policy is StrictSign but it was missing");if(t.key==null)throw new Q("Need key when signature policy is StrictSign but it was missing");return Ha(t.key,t.sequenceNumber);case"StrictNoSign":return Va(t.data);default:throw new Q("Cannot get message id: unhandled signature policy")}}acceptFrom(t){return!0}decodeRpc(t){return We.decode(t)}encodeRpc(t){return We.encode(t)}encodeMessage(t){return We.Message.encode(t)}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(Rr)})}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 Q('Message type should be "unsigned" when signature policy is StrictNoSign but it was not');if(e.signature!=null)throw new Q("StrictNoSigning: signature should not be present");if(e.key!=null)throw new Q("StrictNoSigning: key should not be present");if(e.sequenceNumber!=null)throw new Q("StrictNoSigning: seqno should not be present");break;case"StrictSign":if(e.type!=="signed")throw new Q('Message type should be "signed" when signature policy is StrictSign but it was not');if(e.signature==null)throw new Q("StrictSigning: Signing required and no signature was present");if(e.sequenceNumber==null)throw new Q("StrictSigning: Signing required and no sequenceNumber was present");if(!await Za(e,this.encodeMessage.bind(this)))throw new Q("StrictSigning: Invalid message signature");break;default:throw new Q("Cannot validate message: unhandled signature policy")}let o=this.topicValidators.get(e.topic);if(o!=null){let s=await o(t,e);if(s===Je.Reject||s===Je.Ignore)throw new Q("Message validation failed")}}async buildMessage(t){switch(this.globalSignaturePolicy){case"StrictSign":return ja(this.components.privateKey,t,this.encodeMessage.bind(this));case"StrictNoSign":return Promise.resolve({type:"unsigned",...t});default:throw new Q("Cannot build message: unhandled signature policy")}}getSubscribers(t){if(!this.started)throw new Or("not started yet");if(t==null)throw new j("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:qa()};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}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})}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");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 Cs="/floodsub/1.0.0",ll="StrictSign",hl="StrictNoSign",Je;(function(r){r.Accept="accept",r.Ignore="ignore",r.Reject="reject"})(Je||(Je={}));function dl(r){return!!r?.[Qe]}function pl(r={}){return t=>new Nn(t,r)}return ec(ml);})();
2
+ "use strict";var Libp2PFloodsub=(()=>{var ua=Object.create;var yr=Object.defineProperty;var fa=Object.getOwnPropertyDescriptor;var la=Object.getOwnPropertyNames;var ha=Object.getPrototypeOf,da=Object.prototype.hasOwnProperty;var pa=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),dt=(r,t)=>{for(var e in t)yr(r,e,{get:t[e],enumerable:!0})},Qs=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of la(t))!da.call(r,s)&&s!==e&&yr(r,s,{get:()=>t[s],enumerable:!(n=fa(t,s))||n.enumerable});return r};var ma=(r,t,e)=>(e=r!=null?ua(ha(r)):{},Qs(t||!r||!r.__esModule?yr(e,"default",{value:r,enumerable:!0}):e,r)),ba=r=>Qs(yr({},"__esModule",{value:!0}),r);var ea=pa((gm,Gs)=>{"use strict";var ef=Object.prototype.hasOwnProperty,ht="~";function hr(){}Object.create&&(hr.prototype=Object.create(null),new hr().__proto__||(ht=!1));function rf(r,t,e){this.fn=r,this.context=t,this.once=e||!1}function ta(r,t,e,n,s){if(typeof e!="function")throw new TypeError("The listener must be a function");var o=new rf(e,n||r,s),i=ht?ht+t:t;return r._events[i]?r._events[i].fn?r._events[i]=[r._events[i],o]:r._events[i].push(o):(r._events[i]=o,r._eventsCount++),r}function $r(r,t){--r._eventsCount===0?r._events=new hr:delete r._events[t]}function ft(){this._events=new hr,this._eventsCount=0}ft.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(ht?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(e)):t};ft.prototype.listeners=function(t){var e=ht?ht+t:t,n=this._events[e];if(!n)return[];if(n.fn)return[n.fn];for(var s=0,o=n.length,i=new Array(o);s<o;s++)i[s]=n[s].fn;return i};ft.prototype.listenerCount=function(t){var e=ht?ht+t:t,n=this._events[e];return n?n.fn?1:n.length:0};ft.prototype.emit=function(t,e,n,s,o,i){var a=ht?ht+t:t;if(!this._events[a])return!1;var c=this._events[a],f=arguments.length,l,u;if(c.fn){switch(c.once&&this.removeListener(t,c.fn,void 0,!0),f){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,s),!0;case 5:return c.fn.call(c.context,e,n,s,o),!0;case 6:return c.fn.call(c.context,e,n,s,o,i),!0}for(u=1,l=new Array(f-1);u<f;u++)l[u-1]=arguments[u];c.fn.apply(c.context,l)}else{var g=c.length,d;for(u=0;u<g;u++)switch(c[u].once&&this.removeListener(t,c[u].fn,void 0,!0),f){case 1:c[u].fn.call(c[u].context);break;case 2:c[u].fn.call(c[u].context,e);break;case 3:c[u].fn.call(c[u].context,e,n);break;case 4:c[u].fn.call(c[u].context,e,n,s);break;default:if(!l)for(d=1,l=new Array(f-1);d<f;d++)l[d-1]=arguments[d];c[u].fn.apply(c[u].context,l)}}return!0};ft.prototype.on=function(t,e,n){return ta(this,t,e,n,!1)};ft.prototype.once=function(t,e,n){return ta(this,t,e,n,!0)};ft.prototype.removeListener=function(t,e,n,s){var o=ht?ht+t:t;if(!this._events[o])return this;if(!e)return $r(this,o),this;var i=this._events[o];if(i.fn)i.fn===e&&(!s||i.once)&&(!n||i.context===n)&&$r(this,o);else{for(var a=0,c=[],f=i.length;a<f;a++)(i[a].fn!==e||s&&!i[a].once||n&&i[a].context!==n)&&c.push(i[a]);c.length?this._events[o]=c.length===1?c[0]:c:$r(this,o)}return this};ft.prototype.removeAllListeners=function(t){var e;return t?(e=ht?ht+t:t,this._events[e]&&$r(this,e)):(this._events=new hr,this._eventsCount=0),this};ft.prototype.off=ft.prototype.removeListener;ft.prototype.addListener=ft.prototype.on;ft.prefixed=ht;ft.EventEmitter=ft;typeof Gs<"u"&&(Gs.exports=ft)});var hf={};dt(hf,{StrictNoSign:()=>uf,StrictSign:()=>cf,TopicValidatorResult:()=>Ce,floodsub:()=>lf,isPubSub:()=>ff,protocol:()=>Xs,pubSubSymbol:()=>Ue});var Ue=Symbol.for("@libp2p/pubsub");var z=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},ye=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var gr=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 wr=class extends Error{static name="NotStartedError";constructor(t="Not started"){super(t),this.name="NotStartedError"}};var re=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var rn=Symbol.for("@libp2p/peer-id");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 s=this.#t.get(t);s==null&&(s=[],this.#t.set(t,s)),s.push({callback:e,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,e,n){super.removeEventListener(t.toString(),e??null,n);let s=this.#t.get(t);s!=null&&(s=s.filter(({callback:o})=>o!==e),this.#t.set(t,s))}dispatchEvent(t){let e=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:s})=>!s),this.#t.set(t.type,n)),e}safeDispatchEvent(t,e={}){return this.dispatchEvent(new CustomEvent(t,e))}};var to=Symbol.for("@libp2p/service-capabilities"),eo=Symbol.for("@libp2p/service-dependencies");var cn={};dt(cn,{base58btc:()=>G,base58flickr:()=>va});var Ff=new Uint8Array(0);function ro(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 Pt(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 no(r){return new TextEncoder().encode(r)}function so(r){return new TextDecoder().decode(r)}function ya(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 s=0;s<r.length;s++){var o=r.charAt(s),i=o.charCodeAt(0);if(e[i]!==255)throw new TypeError(o+" is ambiguous");e[i]=s}var a=r.length,c=r.charAt(0),f=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function u(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var I=0,v=0,y=0,A=p.length;y!==A&&p[y]===0;)y++,I++;for(var w=(A-y)*l+1>>>0,B=new Uint8Array(w);y!==A;){for(var k=p[y],U=0,M=w-1;(k!==0||U<v)&&M!==-1;M--,U++)k+=256*B[M]>>>0,B[M]=k%a>>>0,k=k/a>>>0;if(k!==0)throw new Error("Non-zero carry");v=U,y++}for(var E=w-v;E!==w&&B[E]===0;)E++;for(var x=c.repeat(I);E<w;++E)x+=r.charAt(B[E]);return x}function g(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var I=0;if(p[I]!==" "){for(var v=0,y=0;p[I]===c;)v++,I++;for(var A=(p.length-I)*f+1>>>0,w=new Uint8Array(A);p[I];){var B=e[p.charCodeAt(I)];if(B===255)return;for(var k=0,U=A-1;(B!==0||k<y)&&U!==-1;U--,k++)B+=a*w[U]>>>0,w[U]=B%256>>>0,B=B/256>>>0;if(B!==0)throw new Error("Non-zero carry");y=k,I++}if(p[I]!==" "){for(var M=A-y;M!==A&&w[M]===0;)M++;for(var E=new Uint8Array(v+(A-M)),x=v;M!==A;)E[x++]=w[M++];return E}}}function d(p){var I=g(p);if(I)return I;throw new Error(`Non-${t} character`)}return{encode:u,decodeUnsafe:g,decode:d}}var ga=ya,wa=ga,io=wa;var nn=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")}},sn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let s=e.codePointAt(0);if(s===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=s,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return ao(this,t)}},on=class{decoders;constructor(t){this.decoders=t}or(t){return ao(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function ao(r,t){return new on({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var an=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,s){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=s,this.encoder=new nn(t,e,n),this.decoder=new sn(t,e,s)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function we({name:r,prefix:t,encode:e,decode:n}){return new an(r,t,e,n)}function zt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:s}=io(e,r);return we({prefix:t,name:r,encode:n,decode:o=>Pt(s(o))})}function xa(r,t,e,n){let s=r.length;for(;r[s-1]==="=";)--s;let o=new Uint8Array(s*e/8|0),i=0,a=0,c=0;for(let f=0;f<s;++f){let l=t[r[f]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|l,i+=e,i>=8&&(i-=8,o[c++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return o}function Ea(r,t,e){let n=t[t.length-1]==="=",s=(1<<e)-1,o="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,o+=t[s&a>>i];if(i!==0&&(o+=t[s&a<<e-i]),n)for(;(o.length*e&7)!==0;)o+="=";return o}function Sa(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function W({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let s=Sa(n);return we({prefix:t,name:r,encode(o){return Ea(o,n,e)},decode(o){return xa(o,s,e,r)}})}var G=zt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),va=zt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var un={};dt(un,{base32:()=>xe,base32hex:()=>La,base32hexpad:()=>Da,base32hexpadupper:()=>Ta,base32hexupper:()=>_a,base32pad:()=>Ia,base32padupper:()=>Ba,base32upper:()=>Aa,base32z:()=>Ra});var xe=W({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Aa=W({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ia=W({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ba=W({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),La=W({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),_a=W({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Da=W({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Ta=W({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ra=W({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var fn={};dt(fn,{base36:()=>Me,base36upper:()=>Pa});var Me=zt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Pa=zt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ka=fo,co=128,Na=127,Ka=~Na,Ca=Math.pow(2,31);function fo(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Ca;)t[e++]=r&255|co,r/=128;for(;r&Ka;)t[e++]=r&255|co,r>>>=7;return t[e]=r|0,fo.bytes=e-n+1,t}var Ua=ln,Ma=128,uo=127;function ln(r,n){var e=0,n=n||0,s=0,o=n,i,a=r.length;do{if(o>=a)throw ln.bytes=0,new RangeError("Could not decode varint");i=r[o++],e+=s<28?(i&uo)<<s:(i&uo)*Math.pow(2,s),s+=7}while(i>=Ma);return ln.bytes=o-n,e}var Oa=Math.pow(2,7),qa=Math.pow(2,14),Va=Math.pow(2,21),Ha=Math.pow(2,28),Fa=Math.pow(2,35),za=Math.pow(2,42),Za=Math.pow(2,49),$a=Math.pow(2,56),Ga=Math.pow(2,63),Ya=function(r){return r<Oa?1:r<qa?2:r<Va?3:r<Ha?4:r<Fa?5:r<za?6:r<Za?7:r<$a?8:r<Ga?9:10},ja={encode:ka,decode:Ua,encodingLength:Ya},Xa=ja,Oe=Xa;function qe(r,t=0){return[Oe.decode(r,t),Oe.decode.bytes]}function Ee(r,t,e=0){return Oe.encode(r,t,e),t}function Se(r){return Oe.encodingLength(r)}function _t(r,t){let e=t.byteLength,n=Se(r),s=n+Se(e),o=new Uint8Array(s+e);return Ee(r,o,0),Ee(e,o,n),o.set(t,s),new ve(r,e,t,o)}function Zt(r){let t=Pt(r),[e,n]=qe(t),[s,o]=qe(t.subarray(n)),i=t.subarray(n+o);if(i.byteLength!==s)throw new Error("Incorrect length");return new ve(e,s,i,t)}function lo(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&ro(r.bytes,e.bytes)}}var ve=class{code;size;digest;bytes;constructor(t,e,n,s){this.code=t,this.size=e,this.digest=n,this.bytes=s}};function ho(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Ja(e,hn(r),t??G.encoder);default:return Qa(e,hn(r),t??xe.encoder)}}var po=new WeakMap;function hn(r){let t=po.get(r);if(t==null){let e=new Map;return po.set(r,e),e}return t}var at=class r{code;version;multihash;bytes;"/";constructor(t,e,n,s){this.code=e,this.version=t,this.multihash=n,this.bytes=s,this["/"]=s}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==Ve)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==tc)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&&lo(t.multihash,n.multihash)}toString(t){return ho(this,t)}toJSON(){return{"/":ho(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:s,multihash:o,bytes:i}=e;return new r(n,s,o,i??mo(n,s,o.bytes))}else if(e[ec]===!0){let{version:n,multihash:s,code:o}=e,i=Zt(s);return r.create(n,o,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!==Ve)throw new Error(`Version 0 CID must use dag-pb (code: ${Ve}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let s=mo(t,e,n.bytes);return new r(t,e,n,s)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Ve,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,s=Pt(t.subarray(n,n+e.multihashSize));if(s.byteLength!==e.multihashSize)throw new Error("Incorrect length");let o=s.subarray(e.multihashSize-e.digestSize),i=new ve(e.multihashCode,e.digestSize,o,s);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[u,g]=qe(t.subarray(e));return e+=g,u},s=n(),o=Ve;if(s===18?(s=0,e=0):o=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let i=e,a=n(),c=n(),f=e+c,l=f-i;return{version:s,codec:o,multihashCode:a,digestSize:c,multihashSize:l,size:f}}static parse(t,e){let[n,s]=Wa(t,e),o=r.decode(s);if(o.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return hn(o).set(n,t),o}};function Wa(r,t){switch(r[0]){case"Q":{let e=t??G;return[G.prefix,e.decode(`${G.prefix}${r}`)]}case G.prefix:{let e=t??G;return[G.prefix,e.decode(r)]}case xe.prefix:{let e=t??xe;return[xe.prefix,e.decode(r)]}case Me.prefix:{let e=t??Me;return[Me.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 Ja(r,t,e){let{prefix:n}=e;if(n!==G.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let s=t.get(n);if(s==null){let o=e.encode(r).slice(1);return t.set(n,o),o}else return s}function Qa(r,t,e){let{prefix:n}=e,s=t.get(n);if(s==null){let o=e.encode(r);return t.set(n,o),o}else return s}var Ve=112,tc=18;function mo(r,t,e){let n=Se(r),s=n+Se(t),o=new Uint8Array(s+e.byteLength);return Ee(r,o,0),Ee(t,o,n),o.set(e,s),o}var ec=Symbol.for("@ipld/js-cid/CID");var dn={};dt(dn,{identity:()=>At});var bo=0,rc="identity",yo=Pt;function nc(r,t){if(t?.truncate!=null&&t.truncate!==r.byteLength){if(t.truncate<0||t.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t.truncate)}return _t(bo,yo(r))}var At={code:bo,name:rc,encode:yo,digest:nc};function pt(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=0){return new Uint8Array(r)}function mt(r=0){return new Uint8Array(r)}function ne(r,t){t==null&&(t=r.reduce((s,o)=>s+o.length,0));let e=mt(t),n=0;for(let s of r)e.set(s,n),n+=s.length;return e}var wo=Symbol.for("@achingbrain/uint8arraylist");function go(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let s=e+n.byteLength;if(t<s)return{buf:n,index:t-e};e=s}throw new RangeError("index is out of bounds")}function Er(r){return!!r?.[wo]}var et=class r{bufs;length;[wo]=!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(Er(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(Er(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=go(this.bufs,t);return e.buf[e.index]}set(t,e){let n=go(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(Er(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:s}=this._subList(t,e);return ne(n,s)}subarray(t,e){let{bufs:n,length:s}=this._subList(t,e);return n.length===1?n[0]:ne(n,s)}sublist(t,e){let{bufs:n,length:s}=this._subList(t,e),o=new r;return o.length=s,o.bufs=[...n],o}_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=[],s=0;for(let o=0;o<this.bufs.length;o++){let i=this.bufs[o],a=s,c=a+i.byteLength;if(s=c,t>=c)continue;let f=t>=a&&t<c,l=e>a&&e<=c;if(f&&l){if(t===a&&e===c){n.push(i);break}let u=t-a;n.push(i.subarray(u,u+(e-t)));break}if(f){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(l){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(!Er(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 s=n.byteLength;if(s===0)throw new TypeError("search must be at least 1 byte long");let o=256,i=new Int32Array(o);for(let u=0;u<o;u++)i[u]=-1;for(let u=0;u<s;u++)i[n[u]]=u;let a=i,c=this.byteLength-n.byteLength,f=n.byteLength-1,l;for(let u=e;u<=c;u+=l){l=0;for(let g=f;g>=0;g--){let d=this.get(u+g);if(n[g]!==d){l=Math.max(1,g-a[d]);break}}if(l===0)return u}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=mt(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 s=kt(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,e,n),this.write(s,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 s=kt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,e,n),this.write(s,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 s=kt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,e,n),this.write(s,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=mt(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 s=kt(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,e,n),this.write(s,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 s=kt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,e,n),this.write(s,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 s=kt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,e,n),this.write(s,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 s=kt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,e,n),this.write(s,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 s=kt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,e,n),this.write(s,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(!pt(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((s,o)=>s+o.byteLength,0)),n.length=e,n}};var pn={};dt(pn,{base10:()=>sc});var sc=zt({prefix:"9",name:"base10",alphabet:"0123456789"});var mn={};dt(mn,{base16:()=>oc,base16upper:()=>ic});var oc=W({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),ic=W({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var bn={};dt(bn,{base2:()=>ac});var ac=W({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var yn={};dt(yn,{base256emoji:()=>hc});var xo=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}"),cc=xo.reduce((r,t,e)=>(r[e]=t,r),[]),uc=xo.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function fc(r){return r.reduce((t,e)=>(t+=cc[e],t),"")}function lc(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let s=uc[n];if(s==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(s)}return new Uint8Array(t)}var hc=we({prefix:"\u{1F680}",name:"base256emoji",encode:fc,decode:lc});var gn={};dt(gn,{base64:()=>dc,base64pad:()=>pc,base64url:()=>mc,base64urlpad:()=>bc});var dc=W({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),pc=W({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),mc=W({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),bc=W({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var wn={};dt(wn,{base8:()=>yc});var yc=W({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var xn={};dt(xn,{identity:()=>gc});var gc=we({prefix:"\0",name:"identity",encode:r=>so(r),decode:r=>no(r)});var Bl=new TextEncoder,Ll=new TextDecoder;var vn={};dt(vn,{sha256:()=>se,sha512:()=>Sc});var Ec=20;function Sn({name:r,code:t,encode:e,minDigestLength:n,maxDigestLength:s}){return new En(r,t,e,n,s)}var En=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,e,n,s,o){this.name=t,this.code=e,this.encode=n,this.minDigestLength=s??Ec,this.maxDigestLength=o}digest(t,e){if(e?.truncate!=null){if(e.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&e.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?Eo(n,this.code,e?.truncate):n.then(s=>Eo(s,this.code,e?.truncate))}else throw Error("Unknown type, must be binary type")}};function Eo(r,t,e){if(e!=null&&e!==r.byteLength){if(e>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e)}return _t(t,r)}function vo(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var se=Sn({name:"sha2-256",code:18,encode:vo("SHA-256")}),Sc=Sn({name:"sha2-512",code:19,encode:vo("SHA-512")});var An={...xn,...bn,...wn,...pn,...mn,...un,...fn,...cn,...gn,...yn},Ol={...vn,...dn};function Io(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Ao=Io("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),In=Io("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=mt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),vc={utf8:Ao,"utf-8":Ao,hex:An.base16,latin1:In,ascii:In,binary:In,...An},Sr=vc;function F(r,t="utf8"){let e=Sr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function H(r,t="utf8"){let e=Sr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Ac=parseInt("11111",2),Bn=parseInt("10000000",2),Ic=parseInt("01111111",2),Bo={0:He,1:He,2:Bc,3:Dc,4:Tc,5:_c,6:Lc,16:He,22:He,48:He};function Nt(r,t={offset:0}){let e=r[t.offset]&Ac;if(t.offset++,Bo[e]!=null)return Bo[e](r,t);throw new Error("No decoder for tag "+e)}function Fe(r,t){let e=0;if((r[t.offset]&Bn)===Bn){let n=r[t.offset]&Ic,s="0x";t.offset++;for(let o=0;o<n;o++,t.offset++)s+=r[t.offset].toString(16).padStart(2,"0");e=parseInt(s,16)}else e=r[t.offset],t.offset++;return e}function He(r,t){Fe(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=Nt(r,t);if(n===null)break;e.push(n)}return e}function Bc(r,t){let e=Fe(r,t),n=t.offset,s=t.offset+e,o=[];for(let i=n;i<s;i++)i===n&&r[i]===0||o.push(r[i]);return t.offset+=e,Uint8Array.from(o)}function Lc(r,t){let e=Fe(r,t),n=t.offset+e,s=r[t.offset];t.offset++;let o=0,i=0;s<40?(o=0,i=s):s<80?(o=1,i=s-40):(o=2,i=s-80);let a=`${o}.${i}`,c=[];for(;t.offset<n;){let f=r[t.offset];if(t.offset++,c.push(f&127),f<128){c.reverse();let l=0;for(let u=0;u<c.length;u++)l+=c[u]<<u*7;a+=`.${l}`,c=[]}}return a}function _c(r,t){return t.offset++,null}function Dc(r,t){let e=Fe(r,t),n=r[t.offset];t.offset++;let s=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 s}function Tc(r,t){let e=Fe(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function Rc(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 Ln(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=Rc(r.byteLength);return new et(Uint8Array.from([t.byteLength|Bn]),t)}function bt(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]),Ln(t),t)}function vr(r){let t=Uint8Array.from([0]),e=new et(t,r);return new et(Uint8Array.from([3]),Ln(e),e)}function Gt(r,t=48){let e=new et;for(let n of r)e.append(n);return new et(Uint8Array.from([t]),Ln(e),e)}async function Lo(r,t,e,n){let s=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let o=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},s,t,e.subarray());return n?.signal?.throwIfAborted(),o}var Pc=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),kc=Uint8Array.from([6,5,43,129,4,0,34]),Nc=Uint8Array.from([6,5,43,129,4,0,35]),Kc={ext:!0,kty:"EC",crv:"P-256"},Cc={ext:!0,kty:"EC",crv:"P-384"},Uc={ext:!0,kty:"EC",crv:"P-521"},_n=32,Dn=48,Tn=66;function Rn(r){let t=Nt(r);return _o(t)}function _o(r){let t=r[1][1][0],e=1,n,s;if(t.byteLength===_n*2+1)return n=H(t.subarray(e,e+_n),"base64url"),s=H(t.subarray(e+_n),"base64url"),new Ae({...Kc,key_ops:["verify"],x:n,y:s});if(t.byteLength===Dn*2+1)return n=H(t.subarray(e,e+Dn),"base64url"),s=H(t.subarray(e+Dn),"base64url"),new Ae({...Cc,key_ops:["verify"],x:n,y:s});if(t.byteLength===Tn*2+1)return n=H(t.subarray(e,e+Tn),"base64url"),s=H(t.subarray(e+Tn),"base64url"),new Ae({...Uc,key_ops:["verify"],x:n,y:s});throw new z(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Do(r){return Gt([bt(Uint8Array.from([1])),Gt([Mc(r.crv)],160),Gt([vr(new et(Uint8Array.from([4]),F(r.x??"","base64url"),F(r.y??"","base64url")))],161)]).subarray()}function Mc(r){if(r==="P-256")return Pc;if(r==="P-384")return kc;if(r==="P-521")return Nc;throw new z(`Invalid curve ${r}`)}var Ae=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Do(this.jwk)),this._raw}toMultihash(){return At.digest(Kt(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:pt(this.raw,t.raw)}async verify(t,e,n){return Lo(this.jwk,e,t,n)}};function oe(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Dt(r,t=""){if(!Number.isSafeInteger(r)||r<0){let e=t&&`"${t}" `;throw new Error(`${e}expected integer >= 0, got ${r}`)}}function C(r,t,e=""){let n=oe(r),s=r?.length,o=t!==void 0;if(!n||o&&s!==t){let i=e&&`"${e}" `,a=o?` of length ${t}`:"",c=n?`length=${s}`:`type=${typeof r}`;throw new Error(i+"expected Uint8Array"+a+", got "+c)}return r}function Ar(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash must wrapped by utils.createHasher");Dt(r.outputLen),Dt(r.blockLen)}function Ie(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 Ro(r,t){C(r,void 0,"digestInto() output");let e=t.outputLen;if(r.length<e)throw new Error('"digestInto() output" expected to be of length >='+e)}function Ut(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function Ir(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function It(r,t){return r<<32-t|r>>>t}var Po=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Oc=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function Mt(r){if(C(r),Po)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=Oc[r[e]];return t}var Ct={_0:48,_9:57,A:65,F:70,a:97,f:102};function To(r){if(r>=Ct._0&&r<=Ct._9)return r-Ct._0;if(r>=Ct.A&&r<=Ct.F)return r-(Ct.A-10);if(r>=Ct.a&&r<=Ct.f)return r-(Ct.a-10)}function Ot(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(Po)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 s=0,o=0;s<e;s++,o+=2){let i=To(r.charCodeAt(o)),a=To(r.charCodeAt(o+1));if(i===void 0||a===void 0){let c=r[o]+r[o+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+o)}n[s]=i*16+a}return n}function yt(...r){let t=0;for(let n=0;n<r.length;n++){let s=r[n];C(s),t+=s.length}let e=new Uint8Array(t);for(let n=0,s=0;n<r.length;n++){let o=r[n];e.set(o,s),s+=o.length}return e}function Pn(r,t={}){let e=(s,o)=>r(o).update(s).digest(),n=r(void 0);return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=s=>r(s),Object.assign(e,t),Object.freeze(e)}function Yt(r=32){let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return t.getRandomValues(new Uint8Array(r))}var kn=r=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,r])});function ko(r,t,e){return r&t^~r&e}function No(r,t,e){return r&t^r&e^t&e}var ze=class{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,e,n,s){this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=s,this.buffer=new Uint8Array(t),this.view=Ir(this.buffer)}update(t){Ie(this),C(t);let{view:e,buffer:n,blockLen:s}=this,o=t.length;for(let i=0;i<o;){let a=Math.min(s-this.pos,o-i);if(a===s){let c=Ir(t);for(;s<=o-i;i+=s)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===s&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Ie(this),Ro(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:s,isLE:o}=this,{pos:i}=this;e[i++]=128,Ut(this.buffer.subarray(i)),this.padOffset>s-i&&(this.process(n,0),i=0);for(let u=i;u<s;u++)e[u]=0;n.setBigUint64(s-8,BigInt(this.length*8),o),this.process(n,0);let a=Ir(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let f=c/4,l=this.get();if(f>l.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<f;u++)a.setUint32(4*u,l[u],o)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:e,buffer:n,length:s,finished:o,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=o,t.length=s,t.pos=a,s%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},qt=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 Br=BigInt(4294967295),Ko=BigInt(32);function qc(r,t=!1){return t?{h:Number(r&Br),l:Number(r>>Ko&Br)}:{h:Number(r>>Ko&Br)|0,l:Number(r&Br)|0}}function Co(r,t=!1){let e=r.length,n=new Uint32Array(e),s=new Uint32Array(e);for(let o=0;o<e;o++){let{h:i,l:a}=qc(r[o],t);[n[o],s[o]]=[i,a]}return[n,s]}var Nn=(r,t,e)=>r>>>e,Kn=(r,t,e)=>r<<32-e|t>>>e,ie=(r,t,e)=>r>>>e|t<<32-e,ae=(r,t,e)=>r<<32-e|t>>>e,Ze=(r,t,e)=>r<<64-e|t>>>e-32,$e=(r,t,e)=>r>>>e-32|t<<64-e;function Tt(r,t,e,n){let s=(t>>>0)+(n>>>0);return{h:r+e+(s/2**32|0)|0,l:s|0}}var Uo=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Mo=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Oo=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),qo=(r,t,e,n,s)=>t+e+n+s+(r/2**32|0)|0,Vo=(r,t,e,n,s)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(s>>>0),Ho=(r,t,e,n,s,o)=>t+e+n+s+o+(r/2**32|0)|0;var Hc=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]),jt=new Uint32Array(64),Cn=class extends ze{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:e,C:n,D:s,E:o,F:i,G:a,H:c}=this;return[t,e,n,s,o,i,a,c]}set(t,e,n,s,o,i,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=s|0,this.E=o|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,e){for(let u=0;u<16;u++,e+=4)jt[u]=t.getUint32(e,!1);for(let u=16;u<64;u++){let g=jt[u-15],d=jt[u-2],p=It(g,7)^It(g,18)^g>>>3,I=It(d,17)^It(d,19)^d>>>10;jt[u]=I+jt[u-7]+p+jt[u-16]|0}let{A:n,B:s,C:o,D:i,E:a,F:c,G:f,H:l}=this;for(let u=0;u<64;u++){let g=It(a,6)^It(a,11)^It(a,25),d=l+g+ko(a,c,f)+Hc[u]+jt[u]|0,I=(It(n,2)^It(n,13)^It(n,22))+No(n,s,o)|0;l=f,f=c,c=a,a=i+d|0,i=o,o=s,s=n,n=d+I|0}n=n+this.A|0,s=s+this.B|0,o=o+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,l=l+this.H|0,this.set(n,s,o,i,a,c,f,l)}roundClean(){Ut(jt)}destroy(){this.set(0,0,0,0,0,0,0,0),Ut(this.buffer)}},Un=class extends Cn{A=qt[0]|0;B=qt[1]|0;C=qt[2]|0;D=qt[3]|0;E=qt[4]|0;F=qt[5]|0;G=qt[6]|0;H=qt[7]|0;constructor(){super(32)}};var Fo=Co(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),Fc=Fo[0],zc=Fo[1],Xt=new Uint32Array(80),Wt=new Uint32Array(80),Mn=class extends ze{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:e,Bh:n,Bl:s,Ch:o,Cl:i,Dh:a,Dl:c,Eh:f,El:l,Fh:u,Fl:g,Gh:d,Gl:p,Hh:I,Hl:v}=this;return[t,e,n,s,o,i,a,c,f,l,u,g,d,p,I,v]}set(t,e,n,s,o,i,a,c,f,l,u,g,d,p,I,v){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=s|0,this.Ch=o|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=l|0,this.Fh=u|0,this.Fl=g|0,this.Gh=d|0,this.Gl=p|0,this.Hh=I|0,this.Hl=v|0}process(t,e){for(let w=0;w<16;w++,e+=4)Xt[w]=t.getUint32(e),Wt[w]=t.getUint32(e+=4);for(let w=16;w<80;w++){let B=Xt[w-15]|0,k=Wt[w-15]|0,U=ie(B,k,1)^ie(B,k,8)^Nn(B,k,7),M=ae(B,k,1)^ae(B,k,8)^Kn(B,k,7),E=Xt[w-2]|0,x=Wt[w-2]|0,N=ie(E,x,19)^Ze(E,x,61)^Nn(E,x,6),O=ae(E,x,19)^$e(E,x,61)^Kn(E,x,6),T=Oo(M,O,Wt[w-7],Wt[w-16]),m=qo(T,U,N,Xt[w-7],Xt[w-16]);Xt[w]=m|0,Wt[w]=T|0}let{Ah:n,Al:s,Bh:o,Bl:i,Ch:a,Cl:c,Dh:f,Dl:l,Eh:u,El:g,Fh:d,Fl:p,Gh:I,Gl:v,Hh:y,Hl:A}=this;for(let w=0;w<80;w++){let B=ie(u,g,14)^ie(u,g,18)^Ze(u,g,41),k=ae(u,g,14)^ae(u,g,18)^$e(u,g,41),U=u&d^~u&I,M=g&p^~g&v,E=Vo(A,k,M,zc[w],Wt[w]),x=Ho(E,y,B,U,Fc[w],Xt[w]),N=E|0,O=ie(n,s,28)^Ze(n,s,34)^Ze(n,s,39),T=ae(n,s,28)^$e(n,s,34)^$e(n,s,39),m=n&o^n&a^o&a,b=s&i^s&c^i&c;y=I|0,A=v|0,I=d|0,v=p|0,d=u|0,p=g|0,{h:u,l:g}=Tt(f|0,l|0,x|0,N|0),f=a|0,l=c|0,a=o|0,c=i|0,o=n|0,i=s|0;let h=Uo(N,T,b);n=Mo(h,x,O,m),s=h|0}({h:n,l:s}=Tt(this.Ah|0,this.Al|0,n|0,s|0)),{h:o,l:i}=Tt(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=Tt(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l}=Tt(this.Dh|0,this.Dl|0,f|0,l|0),{h:u,l:g}=Tt(this.Eh|0,this.El|0,u|0,g|0),{h:d,l:p}=Tt(this.Fh|0,this.Fl|0,d|0,p|0),{h:I,l:v}=Tt(this.Gh|0,this.Gl|0,I|0,v|0),{h:y,l:A}=Tt(this.Hh|0,this.Hl|0,y|0,A|0),this.set(n,s,o,i,a,c,f,l,u,g,d,p,I,v,y,A)}roundClean(){Ut(Xt,Wt)}destroy(){Ut(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},On=class extends Mn{Ah=ot[0]|0;Al=ot[1]|0;Bh=ot[2]|0;Bl=ot[3]|0;Ch=ot[4]|0;Cl=ot[5]|0;Dh=ot[6]|0;Dl=ot[7]|0;Eh=ot[8]|0;El=ot[9]|0;Fh=ot[10]|0;Fl=ot[11]|0;Gh=ot[12]|0;Gl=ot[13]|0;Hh=ot[14]|0;Hl=ot[15]|0;constructor(){super(64)}};var Be=Pn(()=>new Un,kn(1));var zo=Pn(()=>new On,kn(3));var Vn=BigInt(0),qn=BigInt(1);function Vt(r,t=""){if(typeof r!="boolean"){let e=t&&`"${t}" `;throw new Error(e+"expected boolean, got type="+typeof r)}return r}function Zo(r){if(typeof r=="bigint"){if(!Lr(r))throw new Error("positive bigint expected, got "+r)}else Dt(r);return r}function Ge(r){let t=Zo(r).toString(16);return t.length&1?"0"+t:t}function $o(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?Vn:BigInt("0x"+r)}function Le(r){return $o(Mt(r))}function ce(r){return $o(Mt(Dr(C(r)).reverse()))}function _r(r,t){Dt(t),r=Zo(r);let e=Ot(r.toString(16).padStart(t*2,"0"));if(e.length!==t)throw new Error("number too large");return e}function Hn(r,t){return _r(r,t).reverse()}function Dr(r){return Uint8Array.from(r)}var Lr=r=>typeof r=="bigint"&&Vn<=r;function Zc(r,t,e){return Lr(r)&&Lr(t)&&Lr(e)&&t<=r&&r<e}function Ye(r,t,e,n){if(!Zc(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function Fn(r){let t;for(t=0;r>Vn;r>>=qn,t+=1);return t}var je=r=>(qn<<BigInt(r))-qn;function Go(r,t,e){if(Dt(r,"hashLen"),Dt(t,"qByteLen"),typeof e!="function")throw new Error("hmacFn must be a function");let n=v=>new Uint8Array(v),s=Uint8Array.of(),o=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(r),f=n(r),l=0,u=()=>{c.fill(1),f.fill(0),l=0},g=(...v)=>e(f,yt(c,...v)),d=(v=s)=>{f=g(o,v),c=g(),v.length!==0&&(f=g(i,v),c=g())},p=()=>{if(l++>=a)throw new Error("drbg: tried max amount of iterations");let v=0,y=[];for(;v<t;){c=g();let A=c.slice();y.push(A),v+=c.length}return yt(...y)};return(v,y)=>{u(),d(v);let A;for(;!(A=y(p()));)d();return u(),A}}function Jt(r,t={},e={}){if(!r||typeof r!="object")throw new Error("expected valid options object");function n(o,i,a){let c=r[o];if(a&&c===void 0)return;let f=typeof c;if(f!==i||c===null)throw new Error(`param "${o}" is invalid: expected ${i}, got ${f}`)}let s=(o,i)=>Object.entries(o).forEach(([a,c])=>n(a,c,i));s(t,!1),s(e,!0)}function _e(r){let t=new WeakMap;return(e,...n)=>{let s=t.get(e);if(s!==void 0)return s;let o=r(e,...n);return t.set(e,o),o}}var lt=BigInt(0),rt=BigInt(1),ue=BigInt(2),Xo=BigInt(3),Wo=BigInt(4),Jo=BigInt(5),$c=BigInt(7),Qo=BigInt(8),Gc=BigInt(9),ti=BigInt(16);function Q(r,t){let e=r%t;return e>=lt?e:t+e}function $(r,t,e){let n=r;for(;t-- >lt;)n*=n,n%=e;return n}function Yo(r,t){if(r===lt)throw new Error("invert: expected non-zero number");if(t<=lt)throw new Error("invert: expected positive modulus, got "+t);let e=Q(r,t),n=t,s=lt,o=rt,i=rt,a=lt;for(;e!==lt;){let f=n/e,l=n%e,u=s-i*f,g=o-a*f;n=e,e=l,s=i,o=a,i=u,a=g}if(n!==rt)throw new Error("invert: does not exist");return Q(s,t)}function Zn(r,t,e){if(!r.eql(r.sqr(t),e))throw new Error("Cannot find square root")}function ei(r,t){let e=(r.ORDER+rt)/Wo,n=r.pow(t,e);return Zn(r,n,t),n}function Yc(r,t){let e=(r.ORDER-Jo)/Qo,n=r.mul(t,ue),s=r.pow(n,e),o=r.mul(t,s),i=r.mul(r.mul(o,ue),s),a=r.mul(o,r.sub(i,r.ONE));return Zn(r,a,t),a}function jc(r){let t=De(r),e=ri(r),n=e(t,t.neg(t.ONE)),s=e(t,n),o=e(t,t.neg(n)),i=(r+$c)/ti;return(a,c)=>{let f=a.pow(c,i),l=a.mul(f,n),u=a.mul(f,s),g=a.mul(f,o),d=a.eql(a.sqr(l),c),p=a.eql(a.sqr(u),c);f=a.cmov(f,l,d),l=a.cmov(g,u,p);let I=a.eql(a.sqr(l),c),v=a.cmov(f,l,I);return Zn(a,v,c),v}}function ri(r){if(r<Xo)throw new Error("sqrt is not defined for small field");let t=r-rt,e=0;for(;t%ue===lt;)t/=ue,e++;let n=ue,s=De(r);for(;jo(s,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return ei;let o=s.pow(n,t),i=(t+rt)/ue;return function(c,f){if(c.is0(f))return f;if(jo(c,f)!==1)throw new Error("Cannot find square root");let l=e,u=c.mul(c.ONE,o),g=c.pow(f,t),d=c.pow(f,i);for(;!c.eql(g,c.ONE);){if(c.is0(g))return c.ZERO;let p=1,I=c.sqr(g);for(;!c.eql(I,c.ONE);)if(p++,I=c.sqr(I),p===l)throw new Error("Cannot find square root");let v=rt<<BigInt(l-p-1),y=c.pow(u,v);l=p,u=c.sqr(y),g=c.mul(g,u),d=c.mul(d,y)}return d}}function Xc(r){return r%Wo===Xo?ei:r%Qo===Jo?Yc:r%ti===Gc?jc(r):ri(r)}var ni=(r,t)=>(Q(r,t)&rt)===rt,Wc=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function $n(r){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},e=Wc.reduce((n,s)=>(n[s]="function",n),t);return Jt(r,e),r}function Jc(r,t,e){if(e<lt)throw new Error("invalid exponent, negatives unsupported");if(e===lt)return r.ONE;if(e===rt)return t;let n=r.ONE,s=t;for(;e>lt;)e&rt&&(n=r.mul(n,s)),s=r.sqr(s),e>>=rt;return n}function Xe(r,t,e=!1){let n=new Array(t.length).fill(e?r.ZERO:void 0),s=t.reduce((i,a,c)=>r.is0(a)?i:(n[c]=i,r.mul(i,a)),r.ONE),o=r.inv(s);return t.reduceRight((i,a,c)=>r.is0(a)?i:(n[c]=r.mul(i,n[c]),r.mul(i,a)),o),n}function jo(r,t){let e=(r.ORDER-rt)/ue,n=r.pow(t,e),s=r.eql(n,r.ONE),o=r.eql(n,r.ZERO),i=r.eql(n,r.neg(r.ONE));if(!s&&!o&&!i)throw new Error("invalid Legendre symbol result");return s?1:o?0:-1}function Qc(r,t){t!==void 0&&Dt(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}var zn=class{ORDER;BITS;BYTES;isLE;ZERO=lt;ONE=rt;_lengths;_sqrt;_mod;constructor(t,e={}){if(t<=lt)throw new Error("invalid field: expected ORDER > 0, got "+t);let n;this.isLE=!1,e!=null&&typeof e=="object"&&(typeof e.BITS=="number"&&(n=e.BITS),typeof e.sqrt=="function"&&(this.sqrt=e.sqrt),typeof e.isLE=="boolean"&&(this.isLE=e.isLE),e.allowedLengths&&(this._lengths=e.allowedLengths?.slice()),typeof e.modFromBytes=="boolean"&&(this._mod=e.modFromBytes));let{nBitLength:s,nByteLength:o}=Qc(t,n);if(o>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=s,this.BYTES=o,this._sqrt=void 0,Object.preventExtensions(this)}create(t){return Q(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof t);return lt<=t&&t<this.ORDER}is0(t){return t===lt}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&rt)===rt}neg(t){return Q(-t,this.ORDER)}eql(t,e){return t===e}sqr(t){return Q(t*t,this.ORDER)}add(t,e){return Q(t+e,this.ORDER)}sub(t,e){return Q(t-e,this.ORDER)}mul(t,e){return Q(t*e,this.ORDER)}pow(t,e){return Jc(this,t,e)}div(t,e){return Q(t*Yo(e,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,e){return t+e}subN(t,e){return t-e}mulN(t,e){return t*e}inv(t){return Yo(t,this.ORDER)}sqrt(t){return this._sqrt||(this._sqrt=Xc(this.ORDER)),this._sqrt(this,t)}toBytes(t){return this.isLE?Hn(t,this.BYTES):_r(t,this.BYTES)}fromBytes(t,e=!1){C(t);let{_lengths:n,BYTES:s,isLE:o,ORDER:i,_mod:a}=this;if(n){if(!n.includes(t.length)||t.length>s)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let f=new Uint8Array(s);f.set(t,o?0:f.length-t.length),t=f}if(t.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+t.length);let c=o?ce(t):Le(t);if(a&&(c=Q(c,i)),!e&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return Xe(this,t)}cmov(t,e,n){return n?e:t}};function De(r,t={}){return new zn(r,t)}function si(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 Gn(r){let t=si(r);return t+Math.ceil(t/2)}function Yn(r,t,e=!1){C(r);let n=r.length,s=si(t),o=Gn(t);if(n<16||n<o||n>1024)throw new Error("expected "+o+"-1024 bytes of input, got "+n);let i=e?ce(r):Le(r),a=Q(i,t-rt)+rt;return e?Hn(a,s):_r(a,s)}var Te=BigInt(0),fe=BigInt(1);function We(r,t){let e=t.negate();return r?e:t}function le(r,t){let e=Xe(r.Fp,t.map(n=>n.Z));return t.map((n,s)=>r.fromAffine(n.toAffine(e[s])))}function ci(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function jn(r,t){ci(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),s=2**r,o=je(r),i=BigInt(r);return{windows:e,windowSize:n,mask:o,maxNumber:s,shiftBy:i}}function oi(r,t,e){let{windowSize:n,mask:s,maxNumber:o,shiftBy:i}=e,a=Number(r&s),c=r>>i;a>n&&(a-=o,c+=fe);let f=t*n,l=f+Math.abs(a)-1,u=a===0,g=a<0,d=t%2!==0;return{nextN:c,offset:l,isZero:u,isNeg:g,isNegF:d,offsetF:f}}var Xn=new WeakMap,ui=new WeakMap;function Wn(r){return ui.get(r)||1}function ii(r){if(r!==Te)throw new Error("invalid wNAF")}var Re=class{BASE;ZERO;Fn;bits;constructor(t,e){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=e}_unsafeLadder(t,e,n=this.ZERO){let s=t;for(;e>Te;)e&fe&&(n=n.add(s)),s=s.double(),e>>=fe;return n}precomputeWindow(t,e){let{windows:n,windowSize:s}=jn(e,this.bits),o=[],i=t,a=i;for(let c=0;c<n;c++){a=i,o.push(a);for(let f=1;f<s;f++)a=a.add(i),o.push(a);i=a.double()}return o}wNAF(t,e,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let s=this.ZERO,o=this.BASE,i=jn(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:f,isZero:l,isNeg:u,isNegF:g,offsetF:d}=oi(n,a,i);n=c,l?o=o.add(We(g,e[d])):s=s.add(We(u,e[f]))}return ii(n),{p:s,f:o}}wNAFUnsafe(t,e,n,s=this.ZERO){let o=jn(t,this.bits);for(let i=0;i<o.windows&&n!==Te;i++){let{nextN:a,offset:c,isZero:f,isNeg:l}=oi(n,i,o);if(n=a,!f){let u=e[c];s=s.add(l?u.negate():u)}}return ii(n),s}getPrecomputes(t,e,n){let s=Xn.get(e);return s||(s=this.precomputeWindow(e,t),t!==1&&(typeof n=="function"&&(s=n(s)),Xn.set(e,s))),s}cached(t,e,n){let s=Wn(t);return this.wNAF(s,this.getPrecomputes(s,t,n),e)}unsafe(t,e,n,s){let o=Wn(t);return o===1?this._unsafeLadder(t,e,s):this.wNAFUnsafe(o,this.getPrecomputes(o,t,n),e,s)}createCache(t,e){ci(e,this.bits),ui.set(t,e),Xn.delete(t)}hasCache(t){return Wn(t)!==1}};function fi(r,t,e,n){let s=t,o=r.ZERO,i=r.ZERO;for(;e>Te||n>Te;)e&fe&&(o=o.add(s)),n&fe&&(i=i.add(s)),s=s.double(),e>>=fe,n>>=fe;return{p1:o,p2:i}}function ai(r,t,e){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return $n(t),t}else return De(r,{isLE:e})}function Tr(r,t,e={},n){if(n===void 0&&(n=r==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${r} CURVE object`);for(let c of["p","n","h"]){let f=t[c];if(!(typeof f=="bigint"&&f>Te))throw new Error(`CURVE.${c} must be positive bigint`)}let s=ai(t.p,e.Fp,n),o=ai(t.n,e.Fn,n),a=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let c of a)if(!s.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:s,Fn:o}}function Rr(r,t){return function(n){let s=r(n);return{secretKey:s,publicKey:t(s)}}}var Qt=BigInt(0),nt=BigInt(1),Jn=BigInt(2),tu=BigInt(8);function eu(r,t,e,n){let s=r.sqr(e),o=r.sqr(n),i=r.add(r.mul(t.a,s),o),a=r.add(r.ONE,r.mul(t.d,r.mul(s,o)));return r.eql(i,a)}function li(r,t={}){let e=Tr("edwards",r,t,t.FpFnLE),{Fp:n,Fn:s}=e,o=e.CURVE,{h:i}=o;Jt(t,{},{uvRatio:"function"});let a=Jn<<BigInt(s.BYTES*8)-nt,c=v=>n.create(v),f=t.uvRatio||((v,y)=>{try{return{isValid:!0,value:n.sqrt(n.div(v,y))}}catch{return{isValid:!1,value:Qt}}});if(!eu(n,o,o.Gx,o.Gy))throw new Error("bad curve params: generator point");function l(v,y,A=!1){let w=A?nt:Qt;return Ye("coordinate "+v,y,w,a),y}function u(v){if(!(v instanceof p))throw new Error("EdwardsPoint expected")}let g=_e((v,y)=>{let{X:A,Y:w,Z:B}=v,k=v.is0();y==null&&(y=k?tu:n.inv(B));let U=c(A*y),M=c(w*y),E=n.mul(B,y);if(k)return{x:Qt,y:nt};if(E!==nt)throw new Error("invZ was invalid");return{x:U,y:M}}),d=_e(v=>{let{a:y,d:A}=o;if(v.is0())throw new Error("bad point: ZERO");let{X:w,Y:B,Z:k,T:U}=v,M=c(w*w),E=c(B*B),x=c(k*k),N=c(x*x),O=c(M*y),T=c(x*c(O+E)),m=c(N+c(A*c(M*E)));if(T!==m)throw new Error("bad point: equation left != right (1)");let b=c(w*B),h=c(k*U);if(b!==h)throw new Error("bad point: equation left != right (2)");return!0});class p{static BASE=new p(o.Gx,o.Gy,nt,c(o.Gx*o.Gy));static ZERO=new p(Qt,nt,nt,Qt);static Fp=n;static Fn=s;X;Y;Z;T;constructor(y,A,w,B){this.X=l("x",y),this.Y=l("y",A),this.Z=l("z",w,!0),this.T=l("t",B),Object.freeze(this)}static CURVE(){return o}static fromAffine(y){if(y instanceof p)throw new Error("extended point not allowed");let{x:A,y:w}=y||{};return l("x",A),l("y",w),new p(A,w,nt,c(A*w))}static fromBytes(y,A=!1){let w=n.BYTES,{a:B,d:k}=o;y=Dr(C(y,w,"point")),Vt(A,"zip215");let U=Dr(y),M=y[w-1];U[w-1]=M&-129;let E=ce(U),x=A?a:n.ORDER;Ye("point.y",E,Qt,x);let N=c(E*E),O=c(N-nt),T=c(k*N-B),{isValid:m,value:b}=f(O,T);if(!m)throw new Error("bad point: invalid y coordinate");let h=(b&nt)===nt,S=(M&128)!==0;if(!A&&b===Qt&&S)throw new Error("bad point: x=0 and x_0=1");return S!==h&&(b=c(-b)),p.fromAffine({x:b,y:E})}static fromHex(y,A=!1){return p.fromBytes(Ot(y),A)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=8,A=!0){return I.createCache(this,y),A||this.multiply(Jn),this}assertValidity(){d(this)}equals(y){u(y);let{X:A,Y:w,Z:B}=this,{X:k,Y:U,Z:M}=y,E=c(A*M),x=c(k*B),N=c(w*M),O=c(U*B);return E===x&&N===O}is0(){return this.equals(p.ZERO)}negate(){return new p(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:y}=o,{X:A,Y:w,Z:B}=this,k=c(A*A),U=c(w*w),M=c(Jn*c(B*B)),E=c(y*k),x=A+w,N=c(c(x*x)-k-U),O=E+U,T=O-M,m=E-U,b=c(N*T),h=c(O*m),S=c(N*m),L=c(T*O);return new p(b,h,L,S)}add(y){u(y);let{a:A,d:w}=o,{X:B,Y:k,Z:U,T:M}=this,{X:E,Y:x,Z:N,T:O}=y,T=c(B*E),m=c(k*x),b=c(M*w*O),h=c(U*N),S=c((B+k)*(E+x)-T-m),L=h-b,D=h+b,R=c(m-A*T),_=c(S*L),P=c(D*R),K=c(S*R),Y=c(L*D);return new p(_,P,Y,K)}subtract(y){return this.add(y.negate())}multiply(y){if(!s.isValidNot0(y))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:A,f:w}=I.cached(this,y,B=>le(p,B));return le(p,[A,w])[0]}multiplyUnsafe(y,A=p.ZERO){if(!s.isValid(y))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return y===Qt?p.ZERO:this.is0()||y===nt?this:I.unsafe(this,y,w=>le(p,w),A)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return I.unsafe(this,o.n).is0()}toAffine(y){return g(this,y)}clearCofactor(){return i===nt?this:this.multiplyUnsafe(i)}toBytes(){let{x:y,y:A}=this.toAffine(),w=n.toBytes(A);return w[w.length-1]|=y&nt?128:0,w}toHex(){return Mt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let I=new Re(p,s.BITS);return p.BASE.precompute(8),p}function hi(r,t,e={}){if(typeof t!="function")throw new Error('"hash" function param is required');Jt(e,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=e,{BASE:s,Fp:o,Fn:i}=r,a=e.randomBytes||Yt,c=e.adjustScalarBytes||(E=>E),f=e.domain||((E,x,N)=>{if(Vt(N,"phflag"),x.length||N)throw new Error("Contexts/pre-hash are not supported");return E});function l(E){return i.create(ce(E))}function u(E){let x=w.secretKey;C(E,w.secretKey,"secretKey");let N=C(t(E),2*x,"hashedSecretKey"),O=c(N.slice(0,x)),T=N.slice(x,2*x),m=l(O);return{head:O,prefix:T,scalar:m}}function g(E){let{head:x,prefix:N,scalar:O}=u(E),T=s.multiply(O),m=T.toBytes();return{head:x,prefix:N,scalar:O,point:T,pointBytes:m}}function d(E){return g(E).pointBytes}function p(E=Uint8Array.of(),...x){let N=yt(...x);return l(t(f(N,C(E,void 0,"context"),!!n)))}function I(E,x,N={}){E=C(E,void 0,"message"),n&&(E=n(E));let{prefix:O,scalar:T,pointBytes:m}=g(x),b=p(N.context,O,E),h=s.multiply(b).toBytes(),S=p(N.context,h,m,E),L=i.create(b+S*T);if(!i.isValid(L))throw new Error("sign failed: invalid s");let D=yt(h,i.toBytes(L));return C(D,w.signature,"result")}let v={zip215:!0};function y(E,x,N,O=v){let{context:T,zip215:m}=O,b=w.signature;E=C(E,b,"signature"),x=C(x,void 0,"message"),N=C(N,w.publicKey,"publicKey"),m!==void 0&&Vt(m,"zip215"),n&&(x=n(x));let h=b/2,S=E.subarray(0,h),L=ce(E.subarray(h,b)),D,R,_;try{D=r.fromBytes(N,m),R=r.fromBytes(S,m),_=s.multiplyUnsafe(L)}catch{return!1}if(!m&&D.isSmallOrder())return!1;let P=p(T,R.toBytes(),D.toBytes(),x);return R.add(D.multiplyUnsafe(P)).subtract(_).clearCofactor().is0()}let A=o.BYTES,w={secretKey:A,publicKey:A,signature:2*A,seed:A};function B(E=a(w.seed)){return C(E,w.seed,"seed")}function k(E){return oe(E)&&E.length===i.BYTES}function U(E,x){try{return!!r.fromBytes(E,x)}catch{return!1}}let M={getExtendedPublicKey:g,randomSecretKey:B,isValidSecretKey:k,isValidPublicKey:U,toMontgomery(E){let{y:x}=r.fromBytes(E),N=w.publicKey,O=N===32;if(!O&&N!==57)throw new Error("only defined for 25519 and 448");let T=O?o.div(nt+x,nt-x):o.div(x-nt,x+nt);return o.toBytes(T)},toMontgomerySecret(E){let x=w.secretKey;C(E,x);let N=t(E.subarray(0,x));return c(N).subarray(0,x)}};return Object.freeze({keygen:Rr(B,d),getPublicKey:d,sign:I,verify:y,utils:M,Point:r,lengths:w})}var ru=BigInt(1),di=BigInt(2);var nu=BigInt(5),su=BigInt(8),Qn=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),ou={p:Qn,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:su,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function iu(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),s=BigInt(80),o=Qn,a=r*r%o*r%o,c=$(a,di,o)*a%o,f=$(c,ru,o)*r%o,l=$(f,nu,o)*f%o,u=$(l,t,o)*l%o,g=$(u,e,o)*u%o,d=$(g,n,o)*g%o,p=$(d,s,o)*d%o,I=$(p,s,o)*d%o,v=$(I,t,o)*l%o;return{pow_p_5_8:$(v,di,o)*r%o,b2:a}}function au(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var pi=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function cu(r,t){let e=Qn,n=Q(t*t*t,e),s=Q(n*n*t,e),o=iu(r*s).pow_p_5_8,i=Q(r*n*o,e),a=Q(t*i*i,e),c=i,f=Q(i*pi,e),l=a===r,u=a===Q(-r,e),g=a===Q(-r*pi,e);return l&&(i=c),(u||g)&&(i=f),ni(i,e)&&(i=Q(-i,e)),{isValid:l||u,value:i}}var uu=li(ou,{uvRatio:cu});function fu(r){return hi(uu,zo,Object.assign({adjustScalarBytes:au},r))}var mi=fu({});var Je=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Pr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var bi={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new Pr("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 St=bi;var kr=32;var ts,lu=(async()=>{try{return await St.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function hu(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await St.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await St.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 du(r,t,e){return mi.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function yi(r,t,e){return ts==null&&(ts=await lu),ts?hu(r,t,e):du(r,t,e)}function Nr(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Kr=class{type="Ed25519";raw;constructor(t){this.raw=es(t,kr)}toMultihash(){return At.digest(Kt(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:pt(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let s=yi(this.raw,e,t);return Nr(s)?s.then(o=>(n?.signal?.throwIfAborted(),o)):s}};function rs(r){return r=es(r,kr),new Kr(r)}function es(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new z(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var mu=Math.pow(2,7),bu=Math.pow(2,14),yu=Math.pow(2,21),ns=Math.pow(2,28),ss=Math.pow(2,35),os=Math.pow(2,42),is=Math.pow(2,49),V=128,ct=127;function Ht(r){if(r<mu)return 1;if(r<bu)return 2;if(r<yu)return 3;if(r<ns)return 4;if(r<ss)return 5;if(r<os)return 6;if(r<is)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function as(r,t,e=0){switch(Ht(r)){case 8:t[e++]=r&255|V,r/=128;case 7:t[e++]=r&255|V,r/=128;case 6:t[e++]=r&255|V,r/=128;case 5:t[e++]=r&255|V,r/=128;case 4:t[e++]=r&255|V,r>>>=7;case 3:t[e++]=r&255|V,r>>>=7;case 2:t[e++]=r&255|V,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function gu(r,t,e=0){switch(Ht(r)){case 8:t.set(e++,r&255|V),r/=128;case 7:t.set(e++,r&255|V),r/=128;case 6:t.set(e++,r&255|V),r/=128;case 5:t.set(e++,r&255|V),r/=128;case 4:t.set(e++,r&255|V),r>>>=7;case 3:t.set(e++,r&255|V),r>>>=7;case 2:t.set(e++,r&255|V),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function cs(r,t){let e=r[t],n=0;if(n+=e&ct,e<V||(e=r[t+1],n+=(e&ct)<<7,e<V)||(e=r[t+2],n+=(e&ct)<<14,e<V)||(e=r[t+3],n+=(e&ct)<<21,e<V)||(e=r[t+4],n+=(e&ct)*ns,e<V)||(e=r[t+5],n+=(e&ct)*ss,e<V)||(e=r[t+6],n+=(e&ct)*os,e<V)||(e=r[t+7],n+=(e&ct)*is,e<V))return n;throw new RangeError("Could not decode varint")}function wu(r,t){let e=r.get(t),n=0;if(n+=e&ct,e<V||(e=r.get(t+1),n+=(e&ct)<<7,e<V)||(e=r.get(t+2),n+=(e&ct)<<14,e<V)||(e=r.get(t+3),n+=(e&ct)<<21,e<V)||(e=r.get(t+4),n+=(e&ct)*ns,e<V)||(e=r.get(t+5),n+=(e&ct)*ss,e<V)||(e=r.get(t+6),n+=(e&ct)*os,e<V)||(e=r.get(t+7),n+=(e&ct)*is,e<V))return n;throw new RangeError("Could not decode varint")}function wi(r,t,e=0){return t==null&&(t=mt(Ht(r))),t instanceof Uint8Array?as(r,t,e):gu(r,t,e)}function xi(r,t=0){return r instanceof Uint8Array?cs(r,t):wu(r,t)}var us=new Float32Array([-0]),te=new Uint8Array(us.buffer);function Ei(r,t,e){us[0]=r,t[e]=te[0],t[e+1]=te[1],t[e+2]=te[2],t[e+3]=te[3]}function Si(r,t){return te[0]=r[t],te[1]=r[t+1],te[2]=r[t+2],te[3]=r[t+3],us[0]}var fs=new Float64Array([-0]),ut=new Uint8Array(fs.buffer);function vi(r,t,e){fs[0]=r,t[e]=ut[0],t[e+1]=ut[1],t[e+2]=ut[2],t[e+3]=ut[3],t[e+4]=ut[4],t[e+5]=ut[5],t[e+6]=ut[6],t[e+7]=ut[7]}function Ai(r,t){return ut[0]=r[t],ut[1]=r[t+1],ut[2]=r[t+2],ut[3]=r[t+3],ut[4]=r[t+4],ut[5]=r[t+5],ut[6]=r[t+6],ut[7]=r[t+7],fs[0]}var Eu=BigInt(Number.MAX_SAFE_INTEGER),Su=BigInt(Number.MIN_SAFE_INTEGER),Et=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 he;if(t<Eu&&t>Su)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,s=t-(n<<32n);return e&&(n=~n|0n,s=~s|0n,++s>Ii&&(s=0n,++n>Ii&&(n=0n))),new r(Number(s),Number(n))}static fromNumber(t){if(t===0)return he;let e=t<0;e&&(t=-t);let n=t>>>0,s=(t-n)/4294967296>>>0;return e&&(s=~s>>>0,n=~n>>>0,++n>4294967295&&(n=0,++s>4294967295&&(s=0))),new r(n,s)}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):he}},he=new Et(0,0);he.toBigInt=function(){return 0n};he.zzEncode=he.zzDecode=function(){return this};he.length=function(){return 1};var Ii=4294967296n;function Bi(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 Li(r,t,e){if(e-t<1)return"";let s,o=[],i=0,a;for(;t<e;)a=r[t++],a<128?o[i++]=a:a>191&&a<224?o[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,o[i++]=55296+(a>>10),o[i++]=56320+(a&1023)):o[i++]=(a&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((s??(s=[])).push(String.fromCharCode.apply(String,o)),i=0);return s!=null?(i>0&&s.push(String.fromCharCode.apply(String,o.slice(0,i))),s.join("")):String.fromCharCode.apply(String,o.slice(0,i))}function ls(r,t,e){let n=e,s,o;for(let i=0;i<r.length;++i)s=r.charCodeAt(i),s<128?t[e++]=s:s<2048?(t[e++]=s>>6|192,t[e++]=s&63|128):(s&64512)===55296&&((o=r.charCodeAt(i+1))&64512)===56320?(s=65536+((s&1023)<<10)+(o&1023),++i,t[e++]=s>>18|240,t[e++]=s>>12&63|128,t[e++]=s>>6&63|128,t[e++]=s&63|128):(t[e++]=s>>12|224,t[e++]=s>>6&63|128,t[e++]=s&63|128);return e-n}function Bt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Cr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var hs=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,Bt(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 Bt(this,4);return Cr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Bt(this,4);return Cr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Bt(this,4);let t=Si(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Bt(this,4);let t=Ai(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 Bt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Li(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Bt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Bt(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 Et(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 Bt(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 Bt(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 Bt(this,8);let t=Cr(this.buf,this.pos+=4),e=Cr(this.buf,this.pos+=4);return new Et(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=cs(this.buf,this.pos);return this.pos+=Ht(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 ds(r){return new hs(r instanceof Uint8Array?r:r.subarray())}function gt(r,t,e){let n=ds(r);return t.decode(n,void 0,e)}function ps(r){let t=r??8192,e=t>>>1,n,s=t;return function(i){if(i<1||i>e)return mt(i);s+i>t&&(n=mt(t),s=0);let a=n.subarray(s,s+=i);return(s&7)!==0&&(s=(s|7)+1),a}}var de=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function ms(){}var ys=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},vu=ps();function Au(r){return globalThis.Buffer!=null?mt(r):vu(r)}var tr=class{len;head;tail;states;constructor(){this.len=0,this.head=new de(ms,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new de(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new gs((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(Ur,10,Et.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=Et.fromBigInt(t);return this._push(Ur,e.length(),e)}uint64Number(t){return this._push(as,Ht(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=Et.fromBigInt(t).zzEncode();return this._push(Ur,e.length(),e)}sint64Number(t){let e=Et.fromNumber(t).zzEncode();return this._push(Ur,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(bs,1,t?1:0)}fixed32(t){return this._push(Qe,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=Et.fromBigInt(t);return this._push(Qe,4,e.lo)._push(Qe,4,e.hi)}fixed64Number(t){let e=Et.fromNumber(t);return this._push(Qe,4,e.lo)._push(Qe,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(Ei,4,t)}double(t){return this._push(vi,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(bs,1,0):this.uint32(e)._push(Bu,e,t)}string(t){let e=Bi(t);return e!==0?this.uint32(e)._push(ls,e,t):this._push(bs,1,0)}fork(){return this.states=new ys(this),this.head=this.tail=new de(ms,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 de(ms,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=Au(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function bs(r,t,e){t[e]=r&255}function Iu(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var gs=class extends de{next;constructor(t,e){super(Iu,t,e),this.next=void 0}};function Ur(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 Qe(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 Bu(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(tr.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Lu,t,r),this},tr.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(_u,t,r),this});function Lu(r,t,e){t.set(r,e)}function _u(r,t,e){r.length<40?ls(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(F(r),e)}function ws(){return new tr}function wt(r,t){let e=ws();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var Pe;(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"})(Pe||(Pe={}));function Mr(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function xs(r){function t(s){if(r[s.toString()]==null)throw new Error("Invalid enum value");return r[s]}let e=function(o,i){let a=t(o);i.int32(a)},n=function(o){let i=o.int32();return t(i)};return Mr("enum",Pe.VARINT,e,n)}function xt(r,t){return Mr("message",Pe.LENGTH_DELIMITED,r,t)}var vt=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var tt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(tt||(tt={}));var Es;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(Es||(Es={}));(function(r){r.codec=()=>xs(Es)})(tt||(tt={}));var Rt;(function(r){let t;r.codec=()=>(t==null&&(t=xt((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),tt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let o={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{o.Type=tt.codec().decode(e);break}case 2:{o.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return o})),t),r.encode=e=>wt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(Rt||(Rt={}));var Ss;(function(r){let t;r.codec=()=>(t==null&&(t=xt((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),tt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let o={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{o.Type=tt.codec().decode(e);break}case 2:{o.Data=e.bytes();break}default:{e.skipType(a&7);break}}}return o})),t),r.encode=e=>wt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(Ss||(Ss={}));function Or(r){if(isNaN(r)||r<=0)throw new z("random bytes length must be a Number bigger than 0");return Yt(r)}var rr={};dt(rr,{MAX_RSA_KEY_SIZE:()=>vs,generateRSAKeyPair:()=>ki,jwkToJWKKeyPair:()=>Ni,jwkToPkcs1:()=>Pu,jwkToPkix:()=>Ls,jwkToRSAPrivateKey:()=>Rs,pkcs1MessageToJwk:()=>Is,pkcs1MessageToRSAPrivateKey:()=>_s,pkcs1ToJwk:()=>Ru,pkcs1ToRSAPrivateKey:()=>Pi,pkixMessageToJwk:()=>Bs,pkixMessageToRSAPublicKey:()=>Ts,pkixToJwk:()=>ku,pkixToRSAPublicKey:()=>Ds});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=rr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return at.createV1(114,this._multihash)}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:pt(this.raw,t.raw)}verify(t,e,n){return Ri(this.jwk,e,t,n)}},er=class{type="RSA";jwk;_raw;publicKey;constructor(t,e){this.jwk=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=rr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:pt(this.raw,t.raw)}sign(t,e){return Ti(this.jwk,t,e)}};var vs=8192,As=18,Du=1062,Tu=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Ru(r){let t=Nt(r);return Is(t)}function Is(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 Pu(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 z("JWK was missing components");return Gt([bt(Uint8Array.from([0])),bt(F(r.n,"base64url")),bt(F(r.e,"base64url")),bt(F(r.d,"base64url")),bt(F(r.p,"base64url")),bt(F(r.q,"base64url")),bt(F(r.dp,"base64url")),bt(F(r.dq,"base64url")),bt(F(r.qi,"base64url"))]).subarray()}function ku(r){let t=Nt(r,{offset:0});return Bs(t)}function Bs(r){let t=Nt(r[1],{offset:0});return{kty:"RSA",n:H(t[0],"base64url"),e:H(t[1],"base64url")}}function Ls(r){if(r.n==null||r.e==null)throw new z("JWK was missing components");return Gt([Tu,vr(Gt([bt(F(r.n,"base64url")),bt(F(r.e,"base64url"))]))]).subarray()}function Pi(r){let t=Nt(r);return _s(t)}function _s(r){let t=Is(r);return Rs(t)}function Ds(r,t){if(r.byteLength>=Du)throw new ye("Key size is too large");let e=Nt(r,{offset:0});return Ts(e,r,t)}function Ts(r,t,e){let n=Bs(r);if(e==null){let s=Be(Rt.encode({Type:tt.RSA,Data:t}));e=_t(As,s)}return new ke(n,e)}function Rs(r){if(Ci(r)>vs)throw new z("Key size is too large");let t=Ni(r),e=Be(Rt.encode({Type:tt.RSA,Data:Ls(t.publicKey)})),n=_t(As,e);return new er(t.privateKey,new ke(t.publicKey,n))}async function ki(r){if(r>vs)throw new z("Key size is too large");let t=await Ki(r),e=Be(Rt.encode({Type:tt.RSA,Data:Ls(t.publicKey)})),n=_t(As,e);return new er(t.privateKey,new ke(t.publicKey,n))}function Ni(r){if(r==null)throw new z("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function Ki(r,t){let e=await St.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 Nu(e,t);return{privateKey:n[0],publicKey:n[1]}}async function Ti(r,t,e){let n=await St.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);e?.signal?.throwIfAborted();let s=await St.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return e?.signal?.throwIfAborted(),new Uint8Array(s,0,s.byteLength)}async function Ri(r,t,e,n){let s=await St.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let o=await St.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},s,t,e instanceof Uint8Array?e:e.subarray());return n?.signal?.throwIfAborted(),o}async function Nu(r,t){if(r.privateKey==null||r.publicKey==null)throw new z("Private and public key are required");let e=await Promise.all([St.get().subtle.exportKey("jwk",r.privateKey),St.get().subtle.exportKey("jwk",r.publicKey)]);return t?.signal?.throwIfAborted(),e}function Ci(r){if(r.kty!=="RSA")throw new z("invalid key type");if(r.n==null)throw new z("invalid key modulus");return F(r.n,"base64url").length*8}var qr=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(t,e){if(Ar(t),C(e,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,s=new Uint8Array(n);s.set(e.length>n?t.create().update(e).digest():e);for(let o=0;o<s.length;o++)s[o]^=54;this.iHash.update(s),this.oHash=t.create();for(let o=0;o<s.length;o++)s[o]^=106;this.oHash.update(s),Ut(s)}update(t){return Ie(this),this.iHash.update(t),this}digestInto(t){Ie(this),C(t,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:e,iHash:n,finished:s,destroyed:o,blockLen:i,outputLen:a}=this;return t=t,t.finished=s,t.destroyed=o,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()}},Ps=(r,t,e)=>new qr(r,t).update(e).digest();Ps.create=(r,t)=>new qr(r,t);var Ui=(r,t)=>(r+(r>=0?t:-t)/Mi)/t;function Ku(r,t,e){let[[n,s],[o,i]]=t,a=Ui(i*r,e),c=Ui(-s*r,e),f=r-a*n-c*o,l=-a*s-c*i,u=f<Ft,g=l<Ft;u&&(f=-f),g&&(l=-l);let d=je(Math.ceil(Fn(e)/2))+Ne;if(f<Ft||f>=d||l<Ft||l>=d)throw new Error("splitScalar (endomorphism): failed, k="+r);return{k1neg:u,k1:f,k2neg:g,k2:l}}function Ns(r){if(!["compact","recovered","der"].includes(r))throw new Error('Signature format must be "compact", "recovered", or "der"');return r}function ks(r,t){let e={};for(let n of Object.keys(t))e[n]=r[n]===void 0?t[n]:r[n];return Vt(e.lowS,"lowS"),Vt(e.prehash,"prehash"),e.format!==void 0&&Ns(e.format),e}var Ks=class extends Error{constructor(t=""){super(t)}},ee={Err:Ks,_tlv:{encode:(r,t)=>{let{Err:e}=ee;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,s=Ge(n);if(s.length/2&128)throw new e("tlv.encode: long form length too big");let o=n>127?Ge(s.length/2|128):"";return Ge(r)+o+s+t},decode(r,t){let{Err:e}=ee,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 s=t[n++],o=!!(s&128),i=0;if(!o)i=s;else{let c=s&127;if(!c)throw new e("tlv.decode(long): indefinite length not supported");if(c>4)throw new e("tlv.decode(long): byte length is too big");let f=t.subarray(n,n+c);if(f.length!==c)throw new e("tlv.decode: length bytes not complete");if(f[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let l of f)i=i<<8|l;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}=ee;if(r<Ft)throw new t("integer: negative integers are not allowed");let e=Ge(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}=ee;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 Le(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=ee,s=C(r,void 0,"signature"),{v:o,l:i}=n.decode(48,s);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,o),{v:f,l}=n.decode(2,c);if(l.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(f)}},hexFromSig(r){let{_tlv:t,_int:e}=ee,n=t.encode(2,e.encode(r.r)),s=t.encode(2,e.encode(r.s)),o=n+s;return t.encode(48,o)}},Ft=BigInt(0),Ne=BigInt(1),Mi=BigInt(2),Vr=BigInt(3),Cu=BigInt(4);function Oi(r,t={}){let e=Tr("weierstrass",r,t),{Fp:n,Fn:s}=e,o=e.CURVE,{h:i,n:a}=o;Jt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c}=t;if(c&&(!n.is0(o.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let f=Vi(n,s);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function u(T,m,b){let{x:h,y:S}=m.toAffine(),L=n.toBytes(h);if(Vt(b,"isCompressed"),b){l();let D=!n.isOdd(S);return yt(qi(D),L)}else return yt(Uint8Array.of(4),L,n.toBytes(S))}function g(T){C(T,void 0,"Point");let{publicKey:m,publicKeyUncompressed:b}=f,h=T.length,S=T[0],L=T.subarray(1);if(h===m&&(S===2||S===3)){let D=n.fromBytes(L);if(!n.isValid(D))throw new Error("bad point: is not on curve, wrong x");let R=I(D),_;try{_=n.sqrt(R)}catch(Y){let Z=Y instanceof Error?": "+Y.message:"";throw new Error("bad point: is not on curve, sqrt error"+Z)}l();let P=n.isOdd(_);return(S&1)===1!==P&&(_=n.neg(_)),{x:D,y:_}}else if(h===b&&S===4){let D=n.BYTES,R=n.fromBytes(L.subarray(0,D)),_=n.fromBytes(L.subarray(D,D*2));if(!v(R,_))throw new Error("bad point: is not on curve");return{x:R,y:_}}else throw new Error(`bad point: got length ${h}, expected compressed=${m} or uncompressed=${b}`)}let d=t.toBytes||u,p=t.fromBytes||g;function I(T){let m=n.sqr(T),b=n.mul(m,T);return n.add(n.add(b,n.mul(T,o.a)),o.b)}function v(T,m){let b=n.sqr(m),h=I(T);return n.eql(b,h)}if(!v(o.Gx,o.Gy))throw new Error("bad curve params: generator point");let y=n.mul(n.pow(o.a,Vr),Cu),A=n.mul(n.sqr(o.b),BigInt(27));if(n.is0(n.add(y,A)))throw new Error("bad curve params: a or b");function w(T,m,b=!1){if(!n.isValid(m)||b&&n.is0(m))throw new Error(`bad point coordinate ${T}`);return m}function B(T){if(!(T instanceof x))throw new Error("Weierstrass Point expected")}function k(T){if(!c||!c.basises)throw new Error("no endo");return Ku(T,c.basises,s.ORDER)}let U=_e((T,m)=>{let{X:b,Y:h,Z:S}=T;if(n.eql(S,n.ONE))return{x:b,y:h};let L=T.is0();m==null&&(m=L?n.ONE:n.inv(S));let D=n.mul(b,m),R=n.mul(h,m),_=n.mul(S,m);if(L)return{x:n.ZERO,y:n.ZERO};if(!n.eql(_,n.ONE))throw new Error("invZ was invalid");return{x:D,y:R}}),M=_e(T=>{if(T.is0()){if(t.allowInfinityPoint&&!n.is0(T.Y))return;throw new Error("bad point: ZERO")}let{x:m,y:b}=T.toAffine();if(!n.isValid(m)||!n.isValid(b))throw new Error("bad point: x or y not field elements");if(!v(m,b))throw new Error("bad point: equation left != right");if(!T.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function E(T,m,b,h,S){return b=new x(n.mul(b.X,T),b.Y,b.Z),m=We(h,m),b=We(S,b),m.add(b)}class x{static BASE=new x(o.Gx,o.Gy,n.ONE);static ZERO=new x(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=s;X;Y;Z;constructor(m,b,h){this.X=w("x",m),this.Y=w("y",b,!0),this.Z=w("z",h),Object.freeze(this)}static CURVE(){return o}static fromAffine(m){let{x:b,y:h}=m||{};if(!m||!n.isValid(b)||!n.isValid(h))throw new Error("invalid affine point");if(m instanceof x)throw new Error("projective point not allowed");return n.is0(b)&&n.is0(h)?x.ZERO:new x(b,h,n.ONE)}static fromBytes(m){let b=x.fromAffine(p(C(m,void 0,"point")));return b.assertValidity(),b}static fromHex(m){return x.fromBytes(Ot(m))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=8,b=!0){return O.createCache(this,m),b||this.multiply(Vr),this}assertValidity(){M(this)}hasEvenY(){let{y:m}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(m)}equals(m){B(m);let{X:b,Y:h,Z:S}=this,{X:L,Y:D,Z:R}=m,_=n.eql(n.mul(b,R),n.mul(L,S)),P=n.eql(n.mul(h,R),n.mul(D,S));return _&&P}negate(){return new x(this.X,n.neg(this.Y),this.Z)}double(){let{a:m,b}=o,h=n.mul(b,Vr),{X:S,Y:L,Z:D}=this,R=n.ZERO,_=n.ZERO,P=n.ZERO,K=n.mul(S,S),Y=n.mul(L,L),Z=n.mul(D,D),q=n.mul(S,L);return q=n.add(q,q),P=n.mul(S,D),P=n.add(P,P),R=n.mul(m,P),_=n.mul(h,Z),_=n.add(R,_),R=n.sub(Y,_),_=n.add(Y,_),_=n.mul(R,_),R=n.mul(q,R),P=n.mul(h,P),Z=n.mul(m,Z),q=n.sub(K,Z),q=n.mul(m,q),q=n.add(q,P),P=n.add(K,K),K=n.add(P,K),K=n.add(K,Z),K=n.mul(K,q),_=n.add(_,K),Z=n.mul(L,D),Z=n.add(Z,Z),K=n.mul(Z,q),R=n.sub(R,K),P=n.mul(Z,Y),P=n.add(P,P),P=n.add(P,P),new x(R,_,P)}add(m){B(m);let{X:b,Y:h,Z:S}=this,{X:L,Y:D,Z:R}=m,_=n.ZERO,P=n.ZERO,K=n.ZERO,Y=o.a,Z=n.mul(o.b,Vr),q=n.mul(b,L),j=n.mul(h,D),st=n.mul(S,R),Lt=n.add(b,h),X=n.add(L,D);Lt=n.mul(Lt,X),X=n.add(q,j),Lt=n.sub(Lt,X),X=n.add(b,S);let it=n.add(L,R);return X=n.mul(X,it),it=n.add(q,st),X=n.sub(X,it),it=n.add(h,S),_=n.add(D,R),it=n.mul(it,_),_=n.add(j,st),it=n.sub(it,_),K=n.mul(Y,X),_=n.mul(Z,st),K=n.add(_,K),_=n.sub(j,K),K=n.add(j,K),P=n.mul(_,K),j=n.add(q,q),j=n.add(j,q),st=n.mul(Y,st),X=n.mul(Z,X),j=n.add(j,st),st=n.sub(q,st),st=n.mul(Y,st),X=n.add(X,st),q=n.mul(j,X),P=n.add(P,q),q=n.mul(it,X),_=n.mul(Lt,_),_=n.sub(_,q),q=n.mul(Lt,j),K=n.mul(it,K),K=n.add(K,q),new x(_,P,K)}subtract(m){return this.add(m.negate())}is0(){return this.equals(x.ZERO)}multiply(m){let{endo:b}=t;if(!s.isValidNot0(m))throw new Error("invalid scalar: out of range");let h,S,L=D=>O.cached(this,D,R=>le(x,R));if(b){let{k1neg:D,k1:R,k2neg:_,k2:P}=k(m),{p:K,f:Y}=L(R),{p:Z,f:q}=L(P);S=Y.add(q),h=E(b.beta,K,Z,D,_)}else{let{p:D,f:R}=L(m);h=D,S=R}return le(x,[h,S])[0]}multiplyUnsafe(m){let{endo:b}=t,h=this;if(!s.isValid(m))throw new Error("invalid scalar: out of range");if(m===Ft||h.is0())return x.ZERO;if(m===Ne)return h;if(O.hasCache(this))return this.multiply(m);if(b){let{k1neg:S,k1:L,k2neg:D,k2:R}=k(m),{p1:_,p2:P}=fi(x,h,L,R);return E(b.beta,_,P,S,D)}else return O.unsafe(h,m)}toAffine(m){return U(this,m)}isTorsionFree(){let{isTorsionFree:m}=t;return i===Ne?!0:m?m(x,this):O.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:m}=t;return i===Ne?this:m?m(x,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(m=!0){return Vt(m,"isCompressed"),this.assertValidity(),d(x,this,m)}toHex(m=!0){return Mt(this.toBytes(m))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let N=s.BITS,O=new Re(x,t.endo?Math.ceil(N/2):N);return x.BASE.precompute(8),x}function qi(r){return Uint8Array.of(r?2:3)}function Vi(r,t){return{secretKey:t.BYTES,publicKey:1+r.BYTES,publicKeyUncompressed:1+2*r.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Uu(r,t={}){let{Fn:e}=r,n=t.randomBytes||Yt,s=Object.assign(Vi(r.Fp,e),{seed:Gn(e.ORDER)});function o(d){try{let p=e.fromBytes(d);return e.isValidNot0(p)}catch{return!1}}function i(d,p){let{publicKey:I,publicKeyUncompressed:v}=s;try{let y=d.length;return p===!0&&y!==I||p===!1&&y!==v?!1:!!r.fromBytes(d)}catch{return!1}}function a(d=n(s.seed)){return Yn(C(d,s.seed,"seed"),e.ORDER)}function c(d,p=!0){return r.BASE.multiply(e.fromBytes(d)).toBytes(p)}function f(d){let{secretKey:p,publicKey:I,publicKeyUncompressed:v}=s;if(!oe(d)||"_lengths"in e&&e._lengths||p===I)return;let y=C(d,void 0,"key").length;return y===I||y===v}function l(d,p,I=!0){if(f(d)===!0)throw new Error("first arg must be private key");if(f(p)===!1)throw new Error("second arg must be public key");let v=e.fromBytes(d);return r.fromBytes(p).multiply(v).toBytes(I)}let u={isValidSecretKey:o,isValidPublicKey:i,randomSecretKey:a},g=Rr(a,c);return Object.freeze({getPublicKey:c,getSharedSecret:l,keygen:g,Point:r,utils:u,lengths:s})}function Hi(r,t,e={}){Ar(t),Jt(e,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),e=Object.assign({},e);let n=e.randomBytes||Yt,s=e.hmac||((b,h)=>Ps(t,b,h)),{Fp:o,Fn:i}=r,{ORDER:a,BITS:c}=i,{keygen:f,getPublicKey:l,getSharedSecret:u,utils:g,lengths:d}=Uu(r,e),p={prehash:!0,lowS:typeof e.lowS=="boolean"?e.lowS:!0,format:"compact",extraEntropy:!1},I=a*Mi<o.ORDER;function v(b){let h=a>>Ne;return b>h}function y(b,h){if(!i.isValidNot0(h))throw new Error(`invalid signature ${b}: out of range 1..Point.Fn.ORDER`);return h}function A(){if(I)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function w(b,h){Ns(h);let S=d.signature,L=h==="compact"?S:h==="recovered"?S+1:void 0;return C(b,L)}class B{r;s;recovery;constructor(h,S,L){if(this.r=y("r",h),this.s=y("s",S),L!=null){if(A(),![0,1,2,3].includes(L))throw new Error("invalid recovery id");this.recovery=L}Object.freeze(this)}static fromBytes(h,S=p.format){w(h,S);let L;if(S==="der"){let{r:P,s:K}=ee.toSig(C(h));return new B(P,K)}S==="recovered"&&(L=h[0],S="compact",h=h.subarray(1));let D=d.signature/2,R=h.subarray(0,D),_=h.subarray(D,D*2);return new B(i.fromBytes(R),i.fromBytes(_),L)}static fromHex(h,S){return this.fromBytes(Ot(h),S)}assertRecovery(){let{recovery:h}=this;if(h==null)throw new Error("invalid recovery id: must be present");return h}addRecoveryBit(h){return new B(this.r,this.s,h)}recoverPublicKey(h){let{r:S,s:L}=this,D=this.assertRecovery(),R=D===2||D===3?S+a:S;if(!o.isValid(R))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let _=o.toBytes(R),P=r.fromBytes(yt(qi((D&1)===0),_)),K=i.inv(R),Y=U(C(h,void 0,"msgHash")),Z=i.create(-Y*K),q=i.create(L*K),j=r.BASE.multiplyUnsafe(Z).add(P.multiplyUnsafe(q));if(j.is0())throw new Error("invalid recovery: point at infinify");return j.assertValidity(),j}hasHighS(){return v(this.s)}toBytes(h=p.format){if(Ns(h),h==="der")return Ot(ee.hexFromSig(this));let{r:S,s:L}=this,D=i.toBytes(S),R=i.toBytes(L);return h==="recovered"?(A(),yt(Uint8Array.of(this.assertRecovery()),D,R)):yt(D,R)}toHex(h){return Mt(this.toBytes(h))}}let k=e.bits2int||function(h){if(h.length>8192)throw new Error("input is too large");let S=Le(h),L=h.length*8-c;return L>0?S>>BigInt(L):S},U=e.bits2int_modN||function(h){return i.create(k(h))},M=je(c);function E(b){return Ye("num < 2^"+c,b,Ft,M),i.toBytes(b)}function x(b,h){return C(b,void 0,"message"),h?C(t(b),void 0,"prehashed message"):b}function N(b,h,S){let{lowS:L,prehash:D,extraEntropy:R}=ks(S,p);b=x(b,D);let _=U(b),P=i.fromBytes(h);if(!i.isValidNot0(P))throw new Error("invalid private key");let K=[E(P),E(_)];if(R!=null&&R!==!1){let j=R===!0?n(d.secretKey):R;K.push(C(j,void 0,"extraEntropy"))}let Y=yt(...K),Z=_;function q(j){let st=k(j);if(!i.isValidNot0(st))return;let Lt=i.inv(st),X=r.BASE.multiply(st).toAffine(),it=i.create(X.x);if(it===Ft)return;let br=i.create(Lt*i.create(Z+it*P));if(br===Ft)return;let Ws=(X.x===it?0:2)|Number(X.y&Ne),Js=br;return L&&v(br)&&(Js=i.neg(br),Ws^=1),new B(it,Js,I?void 0:Ws)}return{seed:Y,k2sig:q}}function O(b,h,S={}){let{seed:L,k2sig:D}=N(b,h,S);return Go(t.outputLen,i.BYTES,s)(L,D).toBytes(S.format)}function T(b,h,S,L={}){let{lowS:D,prehash:R,format:_}=ks(L,p);if(S=C(S,void 0,"publicKey"),h=x(h,R),!oe(b)){let P=b instanceof B?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+P)}w(b,_);try{let P=B.fromBytes(b,_),K=r.fromBytes(S);if(D&&P.hasHighS())return!1;let{r:Y,s:Z}=P,q=U(h),j=i.inv(Z),st=i.create(q*j),Lt=i.create(Y*j),X=r.BASE.multiplyUnsafe(st).add(K.multiplyUnsafe(Lt));return X.is0()?!1:i.create(X.x)===Y}catch{return!1}}function m(b,h,S={}){let{prehash:L}=ks(S,p);return h=x(h,L),B.fromBytes(b,"recovered").recoverPublicKey(h).toBytes()}return Object.freeze({keygen:f,getPublicKey:l,getSharedSecret:u,utils:g,lengths:d,Point:r,sign:O,verify:T,recoverPublicKey:m,Signature:B,hash:t})}var Us={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Mu={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Fi=BigInt(2);function Ou(r){let t=Us.p,e=BigInt(3),n=BigInt(6),s=BigInt(11),o=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),f=r*r*r%t,l=f*f*r%t,u=$(l,e,t)*l%t,g=$(u,e,t)*l%t,d=$(g,Fi,t)*f%t,p=$(d,s,t)*d%t,I=$(p,o,t)*p%t,v=$(I,a,t)*I%t,y=$(v,c,t)*v%t,A=$(y,a,t)*I%t,w=$(A,e,t)*l%t,B=$(w,i,t)*p%t,k=$(B,n,t)*f%t,U=$(k,Fi,t);if(!Cs.eql(Cs.sqr(U),r))throw new Error("Cannot find square root");return U}var Cs=De(Us.p,{sqrt:Ou}),qu=Oi(Us,{Fp:Cs,endo:Mu}),Ke=Hi(qu,Be);function zi(r,t,e,n){let s=se.digest(e instanceof Uint8Array?e:e.subarray());if(Nr(s))return s.then(({digest:o})=>(n?.signal?.throwIfAborted(),Ke.verify(t,o,r,{prehash:!1,format:"der"}))).catch(o=>{throw o.name==="AbortError"?o:new Je(String(o))});try{return n?.signal?.throwIfAborted(),Ke.verify(t,s.digest,r,{prehash:!1,format:"der"})}catch(o){throw new Je(String(o))}}var Hr=class{type="secp256k1";raw;_key;constructor(t){this._key=$i(t),this.raw=Zi(this._key)}toMultihash(){return At.digest(Kt(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:pt(this.raw,t.raw)}verify(t,e,n){return zi(this._key,e,t,n)}};function Ms(r){return new Hr(r)}function Zi(r){return Ke.Point.fromBytes(r).toBytes()}function $i(r){try{return Ke.Point.fromBytes(r),r}catch(t){throw new ye(String(t))}}function Os(r,t){let{Type:e,Data:n}=Rt.decode(r),s=n??new Uint8Array;switch(e){case tt.RSA:return Ds(s,t);case tt.Ed25519:return rs(s);case tt.secp256k1:return Ms(s);case tt.ECDSA:return Rn(s);default:throw new re}}function Gi(r){let{Type:t,Data:e}=Rt.decode(r.digest),n=e??new Uint8Array;switch(t){case tt.Ed25519:return rs(n);case tt.secp256k1:return Ms(n);case tt.ECDSA:return Rn(n);default:throw new re}}function Kt(r){return Rt.encode({Type:tt[r.type],Data:r.raw})}var Yi=Symbol.for("nodejs.util.inspect.custom"),Vu=114,nr=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()})`}[rn]=!0;toString(){return this.string==null&&(this.string=G.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return at.createV1(Vu,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return pt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return pt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Yi](){return`PeerId(${this.toString()})`}},sr=class extends nr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},or=class extends nr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},ir=class extends nr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Hu=2336,Fr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=At.digest(F(this.url))}[Yi](){return`PeerId(${this.url})`}[rn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return at.createV1(Hu,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=H(t)),t.toString()===this.toString())}};function qs(r){if(r.type==="Ed25519")return new or({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new ir({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new sr({multihash:r.toCID().multihash,publicKey:r});throw new re}function ji(r){return qs(r.publicKey)}function ar(r){if(zu(r))return new sr({multihash:r});if(Fu(r))try{let t=Gi(r);if(t.type==="Ed25519")return new or({multihash:r,publicKey:t});if(t.type==="secp256k1")return new ir({multihash:r,publicKey:t})}catch{let e=H(r.digest);return new Fr(new URL(e))}throw new gr("Supplied PeerID Multihash is invalid")}function Fu(r){return r.code===At.code}function zu(r){return r.code===se.code}function pe(r,t){let e={[Symbol.iterator]:()=>e,next:()=>{let n=r.next(),s=n.value;return n.done===!0||s==null?{done:!0,value:void 0}:{done:!1,value:t(s)}}};return e}function zr(r){let t=Zt(G.decode(`z${r}`));return ar(t)}var cr=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 pe(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 pe(this.map.values(),t=>t.key)}values(){return pe(this.map.values(),t=>t.value)}get size(){return this.map.size}};var ur=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 pe(this.set.entries(),t=>{let e=zr(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=zr(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return pe(this.set.values(),t=>zr(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}};var fr=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},Vs=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},Xi=r=>globalThis.DOMException===void 0?new Vs(r):new DOMException(r),Wi=r=>{let t=r.reason===void 0?Xi("This operation was aborted."):r.reason;return t instanceof Error?t:Xi(t)};function lr(r,t){let{milliseconds:e,fallback:n,message:s,customTimers:o={setTimeout,clearTimeout}}=t,i,a,f=new Promise((l,u)=>{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:d}=t;d.aborted&&u(Wi(d)),a=()=>{u(Wi(d))},d.addEventListener("abort",a,{once:!0})}if(e===Number.POSITIVE_INFINITY){r.then(l,u);return}let g=new fr;i=o.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(d){u(d)}return}typeof r.cancel=="function"&&r.cancel(),s===!1?l():s instanceof Error?u(s):(g.message=s??`Promise timed out after ${e} milliseconds`,u(g))},e),(async()=>{try{l(await r)}catch(d){u(d)}})()}).finally(()=>{f.clear(),a&&t.signal&&t.signal.removeEventListener("abort",a)});return f.clear=()=>{o.clearTimeout.call(void 0,i),i=void 0},f}var Zu=r=>{let t=r.addEventListener||r.on||r.addListener,e=r.removeEventListener||r.off||r.removeListener;if(!t||!e)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(r),removeListener:e.bind(r)}};function $u(r,t,e){let n,s=new Promise((o,i)=>{if(e={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...e},!(e.count>=0&&(e.count===Number.POSITIVE_INFINITY||Number.isInteger(e.count))))throw new TypeError("The `count` option should be at least 0 or more");e.signal?.throwIfAborted();let a=[t].flat(),c=[],{addListener:f,removeListener:l}=Zu(r),u=async(...d)=>{let p=e.multiArgs?d:d[0];if(e.filter)try{if(!await e.filter(p))return}catch(I){n(),i(I);return}c.push(p),e.count===c.length&&(n(),o(c))},g=(...d)=>{n(),i(e.rejectionMultiArgs?d:d[0])};n=()=>{for(let d of a)l(d,u);for(let d of e.rejectionEvents)a.includes(d)||l(d,g)};for(let d of a)f(d,u);for(let d of e.rejectionEvents)a.includes(d)||f(d,g);e.signal&&e.signal.addEventListener("abort",()=>{g(e.signal.reason)},{once:!0}),e.resolveImmediately&&o(c)});if(s.cancel=n,typeof e.timeout=="number"){let o=lr(s,{milliseconds:e.timeout});return o.cancel=()=>{n(),o.clear()},o}return s}function Ji(r,t,e){typeof e=="function"&&(e={filter:e}),e={...e,count:1,resolveImmediately:!1};let n=$u(r,t,e),s=n.then(o=>o[0]);return s.cancel=n.cancel,s}var me=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function Gu(r){return r.reason}async function Qi(r,t,e){if(t==null)return r;let n=e?.translateError??Gu;if(t.aborted)return r.catch(()=>{}),Promise.reject(n(t));let s;try{return await Promise.race([r,new Promise((o,i)=>{s=()=>{i(n(t))},t.addEventListener("abort",s)})])}finally{s!=null&&t.removeEventListener("abort",s)}}var ju=4194304,Zr=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Fs=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},zs=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Zs=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Xu(r){return typeof r?.closeRead=="function"}function Wu(r){return typeof r?.close=="function"}function Hs(r){return Xu(r)?r.readStatus==="closing"||r.readStatus==="closed":Wu(r)?r.status!=="open":!1}function Ju(r){return r?.addEventListener!=null&&r?.removeEventListener!=null&&r?.send!=null&&r?.push!=null&&r?.log!=null}function Qu(r,t){let e=t?.maxBufferSize??ju,n=new et,s,o=!1;if(!Ju(r))throw new z("Argument should be a Stream or a Multiaddr");let i=l=>{if(n.append(l.data),n.byteLength>e){let u=n.byteLength;n.consume(n.byteLength),s?.reject(new Error(`Read buffer overflow - ${u} > ${e}`))}s?.resolve()};r.addEventListener("message",i);let a=l=>{l.error!=null?s?.reject(l.error):s?.resolve()};r.addEventListener("close",a);let c=()=>{s?.resolve()};r.addEventListener("remoteCloseWrite",c);let f={readBuffer:n,async read(l){if(o===!0)throw new Zr("Stream was unwrapped");if(Hs(r)){if(l?.bytes==null)return null;if(n.byteLength<l.bytes)throw r.log.error("closed after reading %d/%d bytes",n.byteLength,l.bytes),new me(`Unexpected EOF - stream closed after reading ${n.byteLength}/${l.bytes} bytes`)}let u=l?.bytes??1;for(s=Promise.withResolvers();;){if(n.byteLength>=u){s.resolve();break}if(await Qi(s.promise,l?.signal),Hs(r)){if(n.byteLength===0&&l?.bytes==null)return null;break}s=Promise.withResolvers()}let g=l?.bytes??n.byteLength;if(n.byteLength<g){if(Hs(r))throw r.log.error("closed while reading %d/%d bytes",n.byteLength,g),new me(`Unexpected EOF - stream closed while reading ${n.byteLength}/${g} bytes`);return f.read(l)}let d=n.sublist(0,g);return n.consume(g),d},async write(l,u){if(o===!0)throw new Zr("Stream was unwrapped");r.send(l)||await Ji(r,"drain",{signal:u?.signal,rejectionEvents:["close"]})},unwrap(){return o||(o=!0,r.removeEventListener("message",i),r.removeEventListener("close",a),r.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(r.log("stream unwrapped with %d unread bytes",n.byteLength),r.push(n))),r}};return f}function tf(r,t={}){let e=Qu(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=Ht(t.maxDataLength));let n=t?.lengthDecoder??xi,s=t?.lengthEncoder??wi;return{async read(i){let a=-1,c=new et;for(;;){let l=await e.read({...i,bytes:1});if(l==null)break;c.append(l);try{a=n(c)}catch(u){if(u instanceof RangeError)continue;throw u}if(a<0)throw new Fs("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new Zs(`Message length length too long - ${c.byteLength} > ${t.maxLengthLength}`);if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new zs(`Message length too long - ${a} > ${t.maxDataLength}`);let f=await e.read({...i,bytes:a});if(f==null)throw r.log.error("tried to read %d bytes but the stream closed",a),new me(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(f.byteLength!==a)throw r.log.error("read %d/%d bytes before the stream closed",f.byteLength,a),new me(`Unexpected EOF - read ${f.byteLength}/${a} bytes before the stream closed`);return f},async write(i,a){await e.write(new et(s(i.byteLength),i),a)},async writeV(i,a){let c=new et(...i.flatMap(f=>[s(f.byteLength),f]));await e.write(c,a)},unwrap(){return e.unwrap()}}}function $s(r,t){let e=tf(r,t),n={read:async(s,o)=>{let i=await e.read(o);return s.decode(i)},write:async(s,o,i)=>{await e.write(o.encode(s),i)},writeV:async(s,o,i)=>{await e.writeV(s.map(a=>o.encode(a)),i)},pb:s=>({read:async o=>n.read(s,o),write:async(o,i)=>n.write(o,s,i),writeV:async(o,i)=>n.writeV(o,s,i),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}var Ys=ma(ea(),1);function js(r,t,e){let n=0,s=r.length;for(;s>0;){let o=Math.trunc(s/2),i=n+o;e(r[i],t)<=0?(n=++i,s-=o+1):s=o}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 s=js(this.#t,n,(o,i)=>i.priority-o.priority);this.#t.splice(s,0,n)}setPriority(t,e){let n=this.#t.findIndex(o=>o.id===t);if(n===-1)throw new ReferenceError(`No promise function with the id "${t}" exists in the queue.`);let[s]=this.#t.splice(n,1);this.enqueue(s.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;#o=0;#d;#a;#p=0;#r;#c;#e;#m;#n=0;#u;#s;#b;#w=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.#b=t.throwOnTimeout===!0,this.#s=t.autoStart===!1}get#x(){return this.#i||this.#o<this.#d}get#E(){return this.#n<this.#u}#S(){this.#n--,this.#f(),this.emit("next")}#v(){this.#g(),this.#y(),this.#c=void 0}get#A(){let t=Date.now();if(this.#r===void 0){let e=this.#p-t;if(e<0)this.#o=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.#s){let t=!this.#A;if(this.#x&&this.#E){let e=this.#e.dequeue();return e?(this.emit("active"),e(),t&&this.#y(),!0):!1}}return!1}#y(){this.#i||this.#r!==void 0||(this.#r=setInterval(()=>{this.#g()},this.#a),this.#p=Date.now()+this.#a)}#g(){this.#o===0&&this.#n===0&&this.#r&&(clearInterval(this.#r),this.#r=void 0),this.#o=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.#w++).toString(),e={timeout:this.timeout,throwOnTimeout:this.#b,...e},new Promise((n,s)=>{this.#e.enqueue(async()=>{this.#n++;try{e.signal?.throwIfAborted(),this.#o++;let o=t({signal:e.signal});e.timeout&&(o=lr(Promise.resolve(o),{milliseconds:e.timeout})),e.signal&&(o=Promise.race([o,this.#I(e.signal)]));let i=await o;n(i),this.emit("completed",i)}catch(o){if(o instanceof fr&&!e.throwOnTimeout){n();return}s(o),this.emit("error",o)}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.#s?(this.#s=!1,this.#l(),this):this}pause(){this.#s=!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 s=()=>{e&&!e()||(this.off(t,s),n())};this.on(t,s)})}get size(){return this.#e.size}sizeBy(t){return this.#e.filter(t).length}get pending(){return this.#n}get isPaused(){return this.#s}};var Gr=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 be;(function(r){let t;(function(s){let o;s.codec=()=>(o==null&&(o=xt((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 f={},l=a==null?i.len:i.pos+a;for(;i.pos<l;){let u=i.uint32();switch(u>>>3){case 1:{f.subscribe=i.bool();break}case 2:{f.topic=i.string();break}default:{i.skipType(u&7);break}}}return f})),o),s.encode=i=>wt(i,s.codec()),s.decode=(i,a)=>gt(i,s.codec(),a)})(t=r.SubOpts||(r.SubOpts={}));let e;(function(s){let o;s.codec=()=>(o==null&&(o=xt((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 f={},l=a==null?i.len:i.pos+a;for(;i.pos<l;){let u=i.uint32();switch(u>>>3){case 1:{f.from=i.bytes();break}case 2:{f.data=i.bytes();break}case 3:{f.sequenceNumber=i.bytes();break}case 4:{f.topic=i.string();break}case 5:{f.signature=i.bytes();break}case 6:{f.key=i.bytes();break}default:{i.skipType(u&7);break}}}return f})),o),s.encode=i=>wt(i,s.codec()),s.decode=(i,a)=>gt(i,s.codec(),a)})(e=r.Message||(r.Message={}));let n;r.codec=()=>(n==null&&(n=xt((s,o,i={})=>{if(i.lengthDelimited!==!1&&o.fork(),s.subscriptions!=null)for(let a of s.subscriptions)o.uint32(10),r.SubOpts.codec().encode(a,o);if(s.messages!=null)for(let a of s.messages)o.uint32(18),r.Message.codec().encode(a,o);s.control!=null&&(o.uint32(26),Yr.codec().encode(s.control,o)),i.lengthDelimited!==!1&&o.ldelim()},(s,o,i={})=>{let a={subscriptions:[],messages:[]},c=o==null?s.len:s.pos+o;for(;s.pos<c;){let f=s.uint32();switch(f>>>3){case 1:{if(i.limits?.subscriptions!=null&&a.subscriptions.length===i.limits.subscriptions)throw new vt('Decode error - map field "subscriptions" had too many elements');a.subscriptions.push(r.SubOpts.codec().decode(s,s.uint32(),{limits:i.limits?.subscriptions$}));break}case 2:{if(i.limits?.messages!=null&&a.messages.length===i.limits.messages)throw new vt('Decode error - map field "messages" had too many elements');a.messages.push(r.Message.codec().decode(s,s.uint32(),{limits:i.limits?.messages$}));break}case 3:{a.control=Yr.codec().decode(s,s.uint32(),{limits:i.limits?.control});break}default:{s.skipType(f&7);break}}}return a})),n),r.encode=s=>wt(s,r.codec()),r.decode=(s,o)=>gt(s,r.codec(),o)})(be||(be={}));var Yr;(function(r){let t;r.codec=()=>(t==null&&(t=xt((e,n,s={})=>{if(s.lengthDelimited!==!1&&n.fork(),e.ihave!=null)for(let o of e.ihave)n.uint32(10),jr.codec().encode(o,n);if(e.iwant!=null)for(let o of e.iwant)n.uint32(18),Xr.codec().encode(o,n);if(e.graft!=null)for(let o of e.graft)n.uint32(26),Wr.codec().encode(o,n);if(e.prune!=null)for(let o of e.prune)n.uint32(34),Jr.codec().encode(o,n);s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let o={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(s.limits?.ihave!=null&&o.ihave.length===s.limits.ihave)throw new vt('Decode error - map field "ihave" had too many elements');o.ihave.push(jr.codec().decode(e,e.uint32(),{limits:s.limits?.ihave$}));break}case 2:{if(s.limits?.iwant!=null&&o.iwant.length===s.limits.iwant)throw new vt('Decode error - map field "iwant" had too many elements');o.iwant.push(Xr.codec().decode(e,e.uint32(),{limits:s.limits?.iwant$}));break}case 3:{if(s.limits?.graft!=null&&o.graft.length===s.limits.graft)throw new vt('Decode error - map field "graft" had too many elements');o.graft.push(Wr.codec().decode(e,e.uint32(),{limits:s.limits?.graft$}));break}case 4:{if(s.limits?.prune!=null&&o.prune.length===s.limits.prune)throw new vt('Decode error - map field "prune" had too many elements');o.prune.push(Jr.codec().decode(e,e.uint32(),{limits:s.limits?.prune$}));break}default:{e.skipType(a&7);break}}}return o})),t),r.encode=e=>wt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(Yr||(Yr={}));var jr;(function(r){let t;r.codec=()=>(t==null&&(t=xt((e,n,s={})=>{if(s.lengthDelimited!==!1&&n.fork(),e.topic!=null&&(n.uint32(10),n.string(e.topic)),e.messageIDs!=null)for(let o of e.messageIDs)n.uint32(18),n.bytes(o);s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let o={messageIDs:[]},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{o.topic=e.string();break}case 2:{if(s.limits?.messageIDs!=null&&o.messageIDs.length===s.limits.messageIDs)throw new vt('Decode error - map field "messageIDs" had too many elements');o.messageIDs.push(e.bytes());break}default:{e.skipType(a&7);break}}}return o})),t),r.encode=e=>wt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(jr||(jr={}));var Xr;(function(r){let t;r.codec=()=>(t==null&&(t=xt((e,n,s={})=>{if(s.lengthDelimited!==!1&&n.fork(),e.messageIDs!=null)for(let o of e.messageIDs)n.uint32(10),n.bytes(o);s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let o={messageIDs:[]},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{if(s.limits?.messageIDs!=null&&o.messageIDs.length===s.limits.messageIDs)throw new vt('Decode error - map field "messageIDs" had too many elements');o.messageIDs.push(e.bytes());break}default:{e.skipType(a&7);break}}}return o})),t),r.encode=e=>wt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(Xr||(Xr={}));var Wr;(function(r){let t;r.codec=()=>(t==null&&(t=xt((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.topic!=null&&(n.uint32(10),n.string(e.topic)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let o={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{o.topic=e.string();break}default:{e.skipType(a&7);break}}}return o})),t),r.encode=e=>wt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(Wr||(Wr={}));var Jr;(function(r){let t;r.codec=()=>(t==null&&(t=xt((e,n,s={})=>{if(s.lengthDelimited!==!1&&n.fork(),e.topic!=null&&(n.uint32(10),n.string(e.topic)),e.peers!=null)for(let o of e.peers)n.uint32(18),Qr.codec().encode(o,n);e.backoff!=null&&(n.uint32(24),n.uint64(e.backoff)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let o={peers:[]},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{o.topic=e.string();break}case 2:{if(s.limits?.peers!=null&&o.peers.length===s.limits.peers)throw new vt('Decode error - map field "peers" had too many elements');o.peers.push(Qr.codec().decode(e,e.uint32(),{limits:s.limits?.peers$}));break}case 3:{o.backoff=e.uint64();break}default:{e.skipType(a&7);break}}}return o})),t),r.encode=e=>wt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(Jr||(Jr={}));var Qr;(function(r){let t;r.codec=()=>(t==null&&(t=xt((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.peerID!=null&&(n.uint32(10),n.bytes(e.peerID)),e.signedPeerRecord!=null&&(n.uint32(18),n.bytes(e.signedPeerRecord)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let o={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let a=e.uint32();switch(a>>>3){case 1:{o.peerID=e.bytes();break}case 2:{o.signedPeerRecord=e.bytes();break}default:{e.skipType(a&7);break}}}return o})),t),r.encode=e=>wt(e,r.codec()),r.decode=(e,n)=>gt(e,r.codec(),n)})(Qr||(Qr={}));var tn=class extends ge{peerId;shutDownController;inboundPb;outboundPb;constructor(t){super(),this.peerId=t,this.shutDownController=new AbortController}attachInboundStream(t,e){this.inboundPb=$s(t,e).pb(be),Promise.resolve().then(async()=>{for(;;){if(this.inboundPb==null)return;let n=await this.inboundPb.read({signal:this.shutDownController.signal});this.safeDispatchEvent("message",{detail:n})}}).catch(n=>{this.inboundPb?.unwrap().unwrap().abort(n)})}attachOutboundStream(t,e){this.outboundPb=$s(t,e).pb(be)}write(t){this.outboundPb!=null&&this.outboundPb.write(t,{signal:this.shutDownController.signal}).catch(e=>{this.outboundPb?.unwrap().unwrap().abort(e)})}close(){this.shutDownController.abort(),Promise.all([this.inboundPb?.unwrap().unwrap().close().catch(t=>{this.inboundPb?.unwrap().unwrap().abort(t)}),this.outboundPb?.unwrap().unwrap().close().catch(t=>{this.inboundPb?.unwrap().unwrap().abort(t)})]).finally(()=>{this.safeDispatchEvent("close")})}};function ra(){return BigInt(`0x${H(Or(8),"base16")}`)}var na=(r,t)=>{let e=F(t.toString(16).padStart(16,"0"),"base16"),n=Kt(r),s=new Uint8Array(n.byteLength+e.length);return s.set(n,0),s.set(e,n.byteLength),s},sa=r=>se.encode(r);var nf=async r=>{if(r.sequenceNumber==null||r.from==null||r.signature==null)return!1;let t=ar(Zt(r.from));if(t.publicKey!=null)return!0;if(r.key!=null){let e=r.key;return qs(Os(e)).equals(t)}return!1},oa=async r=>{if(r.from==null)throw new J("RPC message was missing from");if(!await nf(r))return{type:"unsigned",topic:r.topic??"",data:r.data??new Uint8Array(0)};let t=ar(Zt(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:of(r.sequenceNumber??new Uint8Array(0)),data:r.data??new Uint8Array(0),signature:r.signature??new Uint8Array(0),key:e instanceof Uint8Array?Os(e):e}},mr=r=>r.type==="signed"?{from:r.from.toMultihash().bytes,data:r.data,sequenceNumber:sf(r.sequenceNumber),topic:r.topic,signature:r.signature,key:r.key?Kt(r.key):void 0}:{data:r.data,topic:r.topic},sf=r=>{let t=r.toString(16);return t.length%2!==0&&(t=`0${t}`),F(t,"base16")},of=r=>BigInt(`0x${H(r,"base16")}`);var ia=F("libp2p-pubsub:");async function aa(r,t,e){let n={type:"signed",topic:t.topic,data:t.data,sequenceNumber:t.sequenceNumber,from:ji(r)},s=ne([ia,e(mr(n)).subarray()]);return n.signature=await r.sign(s),n.key=r.publicKey,n}async function ca(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=ne([ia,t({...mr(r),signature:void 0,key:void 0}).subarray()]);return af(r).verify(e,r.signature)}function af(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 en=class extends ge{log;started;topics;subscriptions;peers;globalSignaturePolicy;canRelayMessage;emitSelf;topicValidators;queue;protocol;components;_registrarTopologyId;maxInboundStreams;maxOutboundStreams;seenCache;constructor(t,e){super(),this.log=t.logger.forComponent("libp2p:floodsub"),this.components=t,this.protocol=e.protocol??Xs,this.started=!1,this.topics=new Map,this.subscriptions=new Set,this.peers=new cr,this.globalSignaturePolicy=e.globalSignaturePolicy==="StrictNoSign"?"StrictNoSign":"StrictSign",this.canRelayMessage=e.canRelayMessage??!0,this.emitSelf=e.emitSelf??!1,this.topicValidators=new Map,this.queue=new pr({concurrency:e.messageProcessingConcurrency??10}),this.maxInboundStreams=e.maxInboundStreams??1,this.maxOutboundStreams=e.maxOutboundStreams??1,this.seenCache=new Gr({validityMs:e?.seenTTL??3e4}),this._onIncomingStream=this._onIncomingStream.bind(this),this._onPeerConnected=this._onPeerConnected.bind(this),this._onPeerDisconnected=this._onPeerDisconnected.bind(this)}[Ue]=!0;[Symbol.toStringTag]="@libp2p/floodsub";[to]=["@libp2p/pubsub"];[eo]=["@libp2p/identify"];async start(){this.started||(this.log("starting"),await this.components.registrar.handle(this.protocol,this._onIncomingStream,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this._registrarTopologyId=await this.components.registrar.register(this.protocol,{onConnect:this._onPeerConnected,onDisconnect:this._onPeerDisconnected}),this.log("started"),this.started=!0)}async stop(){if(!this.started)return;let t=this.components.registrar;this._registrarTopologyId!=null&&t.unregister(this._registrarTopologyId),await t.unhandle(this.protocol),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,e){this.addPeer(e.remotePeer,t).attachInboundStream(t)}async _onPeerConnected(t,e){if(this.log("connected %p",t),e.streams.find(o=>o.direction==="outbound"&&o.protocol===this.protocol)){this.log("outbound pubsub stream already present on connection from %p",t);return}let n=await e.newStream(this.protocol);this.addPeer(t,n).attachOutboundStream(n),this.send(t,{subscriptions:Array.from(this.subscriptions).map(o=>o.toString()),subscribe:!0})}_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 s=new tn(t);return this.peers.set(t,s),s.addEventListener("message",o=>{let i=o.detail,a=[];for(let c of i.messages??[]){if(c.from==null||c.data==null||c.topic==null){this.log("message from %p was missing from, data or topic fields, dropping",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(s,{subscriptions:(i.subscriptions??[]).map(c=>({subscribe:!!c.subscribe,topic:c.topic??""})),messages:a}).catch(c=>{this.log(c)})}),s.addEventListener("close",()=>this._removePeer(t),{once:!0}),s}_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)}}async processRpc(t,e){this.log("rpc from %p",t.peerId);let{subscriptions:n,messages:s}=e;return n!=null&&n.length>0&&(this.log("subscription update from %p",t.peerId),n.forEach(o=>{this.processRpcSubOpt(t.peerId,o)}),super.dispatchEvent(new CustomEvent("subscription-change",{detail:{peerId:t.peerId,subscriptions:n.map(({topic:o,subscribe:i})=>({topic:`${o??""}`,subscribe:!!i}))}}))),s!=null&&s.length>0&&(this.log("messages from %p",t.peerId),this.queue.addAll(s.map(o=>async()=>{if(o.topic==null||!this.subscriptions.has(o.topic)&&!this.canRelayMessage)return this.log("received message we didn't subscribe to. Dropping."),!1;try{let i=await oa(o);await this.processMessage(t.peerId,i)}catch(i){this.log.error(i)}})).catch(o=>{this.log(o)})),!0}processRpcSubOpt(t,e){let n=e.topic;if(n==null)return;let s=this.topics.get(n);s==null&&(s=new ur,this.topics.set(n,s)),e.subscribe===!0?s.add(t):s.delete(t)}async processMessage(t,e){if(this.components.peerId.equals(t)&&!this.emitSelf)return;let n=await this.getMsgId(e),s=H(n,"base64");if(!this.seenCache.has(s)){this.seenCache.put(s,!0);try{await this.validate(t,e)}catch(o){this.log("Message is invalid, dropping it. %O",o);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 na(t.key,t.sequenceNumber);case"StrictNoSign":return sa(t.data);default:throw new J("Cannot get message id: unhandled signature policy")}}encodeMessage(t){return be.Message.encode(t)}send(t,e){let{messages:n,subscriptions:s,subscribe:o}=e;this.sendRpc(t,{subscriptions:(s??[]).map(i=>({topic:i,subscribe:!!o})),messages:(n??[]).map(mr)})}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}n.write(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 ca(e,this.encodeMessage.bind(this)))throw new J("StrictSigning: Invalid message signature");break;default:throw new J("Cannot validate message: unhandled signature policy")}let s=this.topicValidators.get(e.topic);if(s!=null){let o=await s(t,e);if(o===Ce.Reject||o===Ce.Ignore)throw new J("Message validation failed")}}async buildMessage(t){switch(this.globalSignaturePolicy){case"StrictSign":return aa(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 wr("not started yet");if(t==null)throw new z("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:ra()};this.log("publish topic: %s from: %p data: %m",t,n.from,n.data);let s=await this.buildMessage(n),o=!1;this.emitSelf&&this.subscriptions.has(t)&&(o=!0,super.dispatchEvent(new CustomEvent("message",{detail:s})));let i=await this.publishMessage(this.components.peerId,s);return o&&(i.recipients=[...i.recipients,this.components.peerId]),i}async publishMessage(t,e){let n=this.getSubscribers(e.topic),s=[];return n==null||n.length===0?(this.log("no peers are subscribed to topic %s",e.topic),{recipients:s}):(n.forEach(o=>{if(this.components.peerId.equals(o)){this.log("not sending message on topic %s to myself",e.topic);return}if(o.equals(t)){this.log("not sending message on topic %s to sender %p",e.topic,o);return}this.log("publish msgs on topics %s %p",e.topic,o),s.push(o),this.send(o,{messages:[e]})}),{recipients:s})}subscribe(t){if(!this.started)throw new Error("Pubsub has not started");if(!this.subscriptions.has(t)){this.log("subscribe to topic: %s",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");if(this.subscriptions.has(t)){this.log("unsubscribe from %s",t),this.subscriptions.delete(t);for(let e of this.peers.keys())this.send(e,{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 Xs="/floodsub/1.0.0",cf="StrictSign",uf="StrictNoSign",Ce;(function(r){r.Accept="accept",r.Ignore="ignore",r.Reject="reject"})(Ce||(Ce={}));function ff(r){return!!r?.[Ue]}function lf(r={}){return t=>new en(t,r)}return ba(hf);})();
3
3
  /*! Bundled license information:
4
4
 
5
- @noble/hashes/esm/utils.js:
5
+ @noble/hashes/utils.js:
6
6
  (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
7
7
 
8
- @noble/curves/esm/utils.js:
9
- @noble/curves/esm/abstract/modular.js:
10
- @noble/curves/esm/abstract/curve.js:
11
- @noble/curves/esm/abstract/edwards.js:
12
- @noble/curves/esm/ed25519.js:
13
- @noble/curves/esm/abstract/weierstrass.js:
14
- @noble/curves/esm/_shortw_utils.js:
15
- @noble/curves/esm/secp256k1.js:
8
+ @noble/curves/utils.js:
9
+ @noble/curves/abstract/modular.js:
10
+ @noble/curves/abstract/curve.js:
11
+ @noble/curves/abstract/edwards.js:
12
+ @noble/curves/ed25519.js:
13
+ @noble/curves/abstract/weierstrass.js:
14
+ @noble/curves/secp256k1.js:
16
15
  (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
17
16
  */
18
17
  return Libp2PFloodsub}));