@libp2p/pubsub 10.1.10-afa5c9f59 → 10.1.10-cdc63e6cc
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 +2 -15
- package/dist/index.min.js.map +7 -0
- package/package.json +8 -8
package/dist/index.min.js
CHANGED
@@ -1,32 +1,19 @@
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PPubsub = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
2
|
-
"use strict";var Libp2PPubsub=(()=>{var Qi=Object.create;var pr=Object.defineProperty;var ta=Object.getOwnPropertyDescriptor;var ea=Object.getOwnPropertyNames;var ra=Object.getPrototypeOf,na=Object.prototype.hasOwnProperty;var oa=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),gt=(r,t)=>{for(var e in t)pr(r,e,{get:t[e],enumerable:!0})},Go=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ea(t))!na.call(r,o)&&o!==e&&pr(r,o,{get:()=>t[o],enumerable:!(n=ta(t,o))||n.enumerable});return r};var sa=(r,t,e)=>(e=r!=null?Qi(ra(r)):{},Go(t||!r||!r.__esModule?pr(e,"default",{value:r,enumerable:!0}):e,r)),ia=r=>Go(pr({},"__esModule",{value:!0}),r);var Ri=oa((rm,ko)=>{"use strict";var cf=Object.prototype.hasOwnProperty,yt="~";function ar(){}Object.create&&(ar.prototype=Object.create(null),new ar().__proto__||(yt=!1));function uf(r,t,e){this.fn=r,this.context=t,this.once=e||!1}function Ni(r,t,e,n,o){if(typeof e!="function")throw new TypeError("The listener must be a function");var s=new uf(e,n||r,o),i=yt?yt+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 Gr(r,t){--r._eventsCount===0?r._events=new ar:delete r._events[t]}function pt(){this._events=new ar,this._eventsCount=0}pt.prototype.eventNames=function(){var t=[],e,n;if(this._eventsCount===0)return t;for(n in e=this._events)cf.call(e,n)&&t.push(yt?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(e)):t};pt.prototype.listeners=function(t){var e=yt?yt+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};pt.prototype.listenerCount=function(t){var e=yt?yt+t:t,n=this._events[e];return n?n.fn?1:n.length:0};pt.prototype.emit=function(t,e,n,o,s,i){var c=yt?yt+t:t;if(!this._events[c])return!1;var a=this._events[c],l=arguments.length,u,f;if(a.fn){switch(a.once&&this.removeListener(t,a.fn,void 0,!0),l){case 1:return a.fn.call(a.context),!0;case 2:return a.fn.call(a.context,e),!0;case 3:return a.fn.call(a.context,e,n),!0;case 4:return a.fn.call(a.context,e,n,o),!0;case 5:return a.fn.call(a.context,e,n,o,s),!0;case 6:return a.fn.call(a.context,e,n,o,s,i),!0}for(f=1,u=new Array(l-1);f<l;f++)u[f-1]=arguments[f];a.fn.apply(a.context,u)}else{var d=a.length,w;for(f=0;f<d;f++)switch(a[f].once&&this.removeListener(t,a[f].fn,void 0,!0),l){case 1:a[f].fn.call(a[f].context);break;case 2:a[f].fn.call(a[f].context,e);break;case 3:a[f].fn.call(a[f].context,e,n);break;case 4:a[f].fn.call(a[f].context,e,n,o);break;default:if(!u)for(w=1,u=new Array(l-1);w<l;w++)u[w-1]=arguments[w];a[f].fn.apply(a[f].context,u)}}return!0};pt.prototype.on=function(t,e,n){return Ni(this,t,e,n,!1)};pt.prototype.once=function(t,e,n){return Ni(this,t,e,n,!0)};pt.prototype.removeListener=function(t,e,n,o){var s=yt?yt+t:t;if(!this._events[s])return this;if(!e)return Gr(this,s),this;var i=this._events[s];if(i.fn)i.fn===e&&(!o||i.once)&&(!n||i.context===n)&&Gr(this,s);else{for(var c=0,a=[],l=i.length;c<l;c++)(i[c].fn!==e||o&&!i[c].once||n&&i[c].context!==n)&&a.push(i[c]);a.length?this._events[s]=a.length===1?a[0]:a:Gr(this,s)}return this};pt.prototype.removeAllListeners=function(t){var e;return t?(e=yt?yt+t:t,this._events[e]&&Gr(this,e)):(this._events=new ar,this._eventsCount=0),this};pt.prototype.off=pt.prototype.removeListener;pt.prototype.addListener=pt.prototype.on;pt.prefixed=yt;pt.EventEmitter=pt;typeof ko<"u"&&(ko.exports=pt)});var yf={};gt(yf,{PubSubBaseProtocol:()=>zo});var Qr=Symbol.for("@libp2p/peer-id");var ke;(function(r){r.Accept="accept",r.Ignore="ignore",r.Reject="reject"})(ke||(ke={}));var wf=Symbol.for("@libp2p/pubsub");var W=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},be=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var mr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var tt=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var yr=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 ge=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let e=this.#t.get(t);return e==null?0:e.length}addEventListener(t,e,n){super.addEventListener(t,e,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:e,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,e,n){super.removeEventListener(t.toString(),e??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==e),this.#t.set(t,o))}dispatchEvent(t){let e=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),e}safeDispatchEvent(t,e={}){return this.dispatchEvent(new CustomEvent(t,e))}};var on={};gt(on,{base58btc:()=>$,base58flickr:()=>ha});var vf=new Uint8Array(0);function jo(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Nt(r){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 Zo(r){return new TextEncoder().encode(r)}function Yo(r){return new TextDecoder().decode(r)}function aa(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var c=r.length,a=r.charAt(0),l=Math.log(c)/Math.log(256),u=Math.log(256)/Math.log(c);function f(E){if(E instanceof Uint8Array||(ArrayBuffer.isView(E)?E=new Uint8Array(E.buffer,E.byteOffset,E.byteLength):Array.isArray(E)&&(E=Uint8Array.from(E))),!(E instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(E.length===0)return"";for(var y=0,h=0,b=0,v=E.length;b!==v&&E[b]===0;)b++,y++;for(var p=(v-b)*u+1>>>0,I=new Uint8Array(p);b!==v;){for(var C=E[b],D=0,_=p-1;(C!==0||D<h)&&_!==-1;_--,D++)C+=256*I[_]>>>0,I[_]=C%c>>>0,C=C/c>>>0;if(C!==0)throw new Error("Non-zero carry");h=D,b++}for(var L=p-h;L!==p&&I[L]===0;)L++;for(var T=a.repeat(y);L<p;++L)T+=r.charAt(I[L]);return T}function d(E){if(typeof E!="string")throw new TypeError("Expected String");if(E.length===0)return new Uint8Array;var y=0;if(E[y]!==" "){for(var h=0,b=0;E[y]===a;)h++,y++;for(var v=(E.length-y)*l+1>>>0,p=new Uint8Array(v);E[y];){var I=e[E.charCodeAt(y)];if(I===255)return;for(var C=0,D=v-1;(I!==0||C<b)&&D!==-1;D--,C++)I+=c*p[D]>>>0,p[D]=I%256>>>0,I=I/256>>>0;if(I!==0)throw new Error("Non-zero carry");b=C,y++}if(E[y]!==" "){for(var _=v-b;_!==v&&p[_]===0;)_++;for(var L=new Uint8Array(h+(v-_)),T=h;_!==v;)L[T++]=p[_++];return L}}}function w(E){var y=d(E);if(y)return y;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:d,decode:w}}var ca=aa,ua=ca,$o=ua;var tn=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")}},en=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 Xo(this,t)}},rn=class{decoders;constructor(t){this.decoders=t}or(t){return Xo(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 Xo(r,t){return new rn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var nn=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 tn(t,e,n),this.decoder=new en(t,e,o)}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 nn(r,t,e,n)}function zt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=$o(e,r);return we({prefix:t,name:r,encode:n,decode:s=>Nt(o(s))})}function fa(r,t,e,n){let o={};for(let u=0;u<t.length;++u)o[t[u]]=u;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*e/8|0),c=0,a=0,l=0;for(let u=0;u<s;++u){let f=o[r[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|f,c+=e,c>=8&&(c-=8,i[l++]=255&a>>c)}if(c>=e||(255&a<<8-c)!==0)throw new SyntaxError("Unexpected end of data");return i}function la(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,c=0;for(let a=0;a<r.length;++a)for(c=c<<8|r[a],i+=8;i>e;)i-=e,s+=t[o&c>>i];if(i!==0&&(s+=t[o&c<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function J({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return we({prefix:t,name:r,encode(o){return la(o,n,e)},decode(o){return fa(o,n,e,r)}})}var $=zt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ha=zt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var sn={};gt(sn,{base32:()=>xe,base32hex:()=>ya,base32hexpad:()=>ga,base32hexpadupper:()=>wa,base32hexupper:()=>ba,base32pad:()=>pa,base32padupper:()=>ma,base32upper:()=>da,base32z:()=>xa});var xe=J({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),da=J({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),pa=J({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),ma=J({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ya=J({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),ba=J({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ga=J({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),wa=J({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),xa=J({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var an={};gt(an,{base36:()=>Oe,base36upper:()=>Ea});var Oe=zt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Ea=zt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Sa=ts,Jo=128,va=127,Aa=~va,Ia=Math.pow(2,31);function ts(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Ia;)t[e++]=r&255|Jo,r/=128;for(;r&Aa;)t[e++]=r&255|Jo,r>>>=7;return t[e]=r|0,ts.bytes=e-n+1,t}var Ba=cn,_a=128,Qo=127;function cn(r,n){var e=0,n=n||0,o=0,s=n,i,c=r.length;do{if(s>=c)throw cn.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&Qo)<<o:(i&Qo)*Math.pow(2,o),o+=7}while(i>=_a);return cn.bytes=s-n,e}var La=Math.pow(2,7),Ta=Math.pow(2,14),Pa=Math.pow(2,21),Ca=Math.pow(2,28),Da=Math.pow(2,35),Na=Math.pow(2,42),Ra=Math.pow(2,49),Ka=Math.pow(2,56),Ua=Math.pow(2,63),ka=function(r){return r<La?1:r<Ta?2:r<Pa?3:r<Ca?4:r<Da?5:r<Na?6:r<Ra?7:r<Ka?8:r<Ua?9:10},Oa={encode:Sa,decode:Ba,encodingLength:ka},Ma=Oa,Me=Ma;function qe(r,t=0){return[Me.decode(r,t),Me.decode.bytes]}function Ee(r,t,e=0){return Me.encode(r,t,e),t}function Se(r){return Me.encodingLength(r)}function It(r,t){let e=t.byteLength,n=Se(r),o=n+Se(e),s=new Uint8Array(o+e);return Ee(r,s,0),Ee(e,s,n),s.set(t,o),new ve(r,e,t,s)}function Ft(r){let t=Nt(r),[e,n]=qe(t),[o,s]=qe(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new ve(e,o,i,t)}function es(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&jo(r.bytes,e.bytes)}}var ve=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function rs(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Ha(e,un(r),t??$.encoder);default:return Va(e,un(r),t??xe.encoder)}}var ns=new WeakMap;function un(r){let t=ns.get(r);if(t==null){let e=new Map;return ns.set(r,e),e}return t}var ft=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!==He)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==za)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=It(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&&es(t.multihash,n.multihash)}toString(t){return rs(this,t)}toJSON(){return{"/":rs(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??os(n,o,s.bytes))}else if(e[Fa]===!0){let{version:n,multihash:o,code:s}=e,i=Ft(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!==He)throw new Error(`Version 0 CID must use dag-pb (code: ${He}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=os(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,He,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=Nt(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new ve(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[f,d]=qe(t.subarray(e));return e+=d,f},o=n(),s=He;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,c=n(),a=n(),l=e+a,u=l-i;return{version:o,codec:s,multihashCode:c,digestSize:a,multihashSize:u,size:l}}static parse(t,e){let[n,o]=qa(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return un(s).set(n,t),s}};function qa(r,t){switch(r[0]){case"Q":{let e=t??$;return[$.prefix,e.decode(`${$.prefix}${r}`)]}case $.prefix:{let e=t??$;return[$.prefix,e.decode(r)]}case xe.prefix:{let e=t??xe;return[xe.prefix,e.decode(r)]}case Oe.prefix:{let e=t??Oe;return[Oe.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 Ha(r,t,e){let{prefix:n}=e;if(n!==$.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function Va(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 He=112,za=18;function os(r,t,e){let n=Se(r),o=n+Se(t),s=new Uint8Array(o+e.byteLength);return Ee(r,s,0),Ee(t,s,n),s.set(e,o),s}var Fa=Symbol.for("@ipld/js-cid/CID");var fn={};gt(fn,{identity:()=>Bt});var ss=0,Ga="identity",is=Nt;function ja(r){return It(ss,is(r))}var Bt={code:ss,name:Ga,encode:is,digest:ja};function wt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Rt(r=0){return new Uint8Array(r)}function lt(r=0){return new Uint8Array(r)}function ne(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=lt(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var cs=Symbol.for("@achingbrain/uint8arraylist");function as(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 gr(r){return!!r?.[cs]}var ot=class r{bufs;length;[cs]=!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(gr(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(gr(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=as(this.bufs,t);return e.buf[e.index]}set(t,e){let n=as(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(gr(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 ne(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:ne(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=[...n],s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],c=o,a=c+i.byteLength;if(o=a,t>=a)continue;let l=t>=c&&t<a,u=e>c&&e<=a;if(l&&u){if(t===c&&e===a){n.push(i);break}let f=t-c;n.push(i.subarray(f,f+(e-t)));break}if(l){if(t===0){n.push(i);continue}n.push(i.subarray(t-c));continue}if(u){if(e===a){n.push(i);break}n.push(i.subarray(0,e-c));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!gr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let f=0;f<s;f++)i[f]=-1;for(let f=0;f<o;f++)i[n[f]]=f;let c=i,a=this.byteLength-n.byteLength,l=n.byteLength-1,u;for(let f=e;f<=a;f+=u){u=0;for(let d=l;d>=0;d--){let w=this.get(f+d);if(n[d]!==w){u=Math.max(1,d-c[w]);break}}if(u===0)return f}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=lt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=Rt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=Rt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=Rt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=lt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=Rt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=Rt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=Rt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=Rt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=Rt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!wt(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 ln={};gt(ln,{base10:()=>Za});var Za=zt({prefix:"9",name:"base10",alphabet:"0123456789"});var hn={};gt(hn,{base16:()=>Ya,base16upper:()=>Wa});var Ya=J({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Wa=J({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var dn={};gt(dn,{base2:()=>$a});var $a=J({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var pn={};gt(pn,{base256emoji:()=>ec});var us=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}"),Xa=us.reduce((r,t,e)=>(r[e]=t,r),[]),Ja=us.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Qa(r){return r.reduce((t,e)=>(t+=Xa[e],t),"")}function tc(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=Ja[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var ec=we({prefix:"\u{1F680}",name:"base256emoji",encode:Qa,decode:tc});var mn={};gt(mn,{base64:()=>rc,base64pad:()=>nc,base64url:()=>oc,base64urlpad:()=>sc});var rc=J({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),nc=J({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),oc=J({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),sc=J({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var yn={};gt(yn,{base8:()=>ic});var ic=J({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var bn={};gt(bn,{identity:()=>ac});var ac=we({prefix:"\0",name:"identity",encode:r=>Yo(r),decode:r=>Zo(r)});var il=new TextEncoder,al=new TextDecoder;var xn={};gt(xn,{sha256:()=>oe,sha512:()=>fc});function wn({name:r,code:t,encode:e}){return new gn(r,t,e)}var gn=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?It(this.code,e):e.then(n=>It(this.code,n))}else throw Error("Unknown type, must be binary type")}};function ls(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var oe=wn({name:"sha2-256",code:18,encode:ls("SHA-256")}),fc=wn({name:"sha2-512",code:19,encode:ls("SHA-512")});var En={...bn,...dn,...yn,...ln,...hn,...sn,...an,...on,...mn,...pn},wl={...xn,...fn};function ds(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var hs=ds("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Sn=ds("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=lt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),lc={utf8:hs,"utf-8":hs,hex:En.base16,latin1:Sn,ascii:Sn,binary:Sn,...En},wr=lc;function G(r,t="utf8"){let e=wr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function j(r,t="utf8"){let e=wr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var hc=parseInt("11111",2),vn=parseInt("10000000",2),dc=parseInt("01111111",2),ps={0:Ve,1:Ve,2:pc,3:bc,4:gc,5:yc,6:mc,16:Ve,22:Ve,48:Ve};function Kt(r,t={offset:0}){let e=r[t.offset]&hc;if(t.offset++,ps[e]!=null)return ps[e](r,t);throw new Error("No decoder for tag "+e)}function ze(r,t){let e=0;if((r[t.offset]&vn)===vn){let n=r[t.offset]&dc,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 Ve(r,t){ze(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=Kt(r,t);if(n===null)break;e.push(n)}return e}function pc(r,t){let e=ze(r,t),n=t.offset,o=t.offset+e,s=[];for(let i=n;i<o;i++)i===n&&r[i]===0||s.push(r[i]);return t.offset+=e,Uint8Array.from(s)}function mc(r,t){let e=ze(r,t),n=t.offset+e,o=r[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let c=`${s}.${i}`,a=[];for(;t.offset<n;){let l=r[t.offset];if(t.offset++,a.push(l&127),l<128){a.reverse();let u=0;for(let f=0;f<a.length;f++)u+=a[f]<<f*7;c+=`.${u}`,a=[]}}return c}function yc(r,t){return t.offset++,null}function bc(r,t){let e=ze(r,t),n=r[t.offset];t.offset++;let o=r.subarray(t.offset,t.offset+e-1);if(t.offset+=e,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function gc(r,t){let e=ze(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function wc(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new ot;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function An(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=wc(r.byteLength);return new ot(Uint8Array.from([t.byteLength|vn]),t)}function xt(r){let t=new ot,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new ot(Uint8Array.from([2]),An(t),t)}function xr(r){let t=Uint8Array.from([0]),e=new ot(t,r);return new ot(Uint8Array.from([3]),An(e),e)}function jt(r,t=48){let e=new ot;for(let n of r)e.append(n);return new ot(Uint8Array.from([t]),An(e),e)}async function ms(r,t,e){let n=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);return crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},n,t,e.subarray())}var xc=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Ec=Uint8Array.from([6,5,43,129,4,0,34]),Sc=Uint8Array.from([6,5,43,129,4,0,35]),vc={ext:!0,kty:"EC",crv:"P-256"},Ac={ext:!0,kty:"EC",crv:"P-384"},Ic={ext:!0,kty:"EC",crv:"P-521"},In=32,Bn=48,_n=66;function Ln(r){let t=Kt(r);return ys(t)}function ys(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===In*2+1)return n=j(t.subarray(e,e+In),"base64url"),o=j(t.subarray(e+In),"base64url"),new Ae({...vc,key_ops:["verify"],x:n,y:o});if(t.byteLength===Bn*2+1)return n=j(t.subarray(e,e+Bn),"base64url"),o=j(t.subarray(e+Bn),"base64url"),new Ae({...Ac,key_ops:["verify"],x:n,y:o});if(t.byteLength===_n*2+1)return n=j(t.subarray(e,e+_n),"base64url"),o=j(t.subarray(e+_n),"base64url"),new Ae({...Ic,key_ops:["verify"],x:n,y:o});throw new W(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function bs(r){return jt([xt(Uint8Array.from([1])),jt([Bc(r.crv)],160),jt([xr(new ot(Uint8Array.from([4]),G(r.x??"","base64url"),G(r.y??"","base64url")))],161)]).subarray()}function Bc(r){if(r==="P-256")return xc;if(r==="P-384")return Ec;if(r==="P-521")return Sc;throw new W(`Invalid curve ${r}`)}var Ae=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=bs(this.jwk)),this._raw}toMultihash(){return Bt.digest(Ut(this))}toCID(){return ft.createV1(114,this.toMultihash())}toString(){return $.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:wt(this.raw,t.raw)}async verify(t,e){return ms(this.jwk,e,t)}};function gs(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function _c(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Ie(r,...t){if(!_c(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 ws(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");gs(r.outputLen),gs(r.blockLen)}function Be(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 xs(r,t){Ie(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}var se=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Er(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function _t(r,t){return r<<32-t|r>>>t}var th=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function";function Es(r){if(typeof r!="string")throw new Error("utf8ToBytes expected string, got "+typeof r);return new Uint8Array(new TextEncoder().encode(r))}function Fe(r){return typeof r=="string"&&(r=Es(r)),Ie(r),r}function Tn(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];Ie(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 _e=class{clone(){return this._cloneInto()}};function Sr(r){let t=n=>r().update(Fe(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function Le(r=32){if(se&&typeof se.getRandomValues=="function")return se.getRandomValues(new Uint8Array(r));if(se&&typeof se.randomBytes=="function")return Uint8Array.from(se.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function Lc(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),c=Number(e&s),a=n?4:0,l=n?0:4;r.setUint32(t+a,i,n),r.setUint32(t+l,c,n)}function Ss(r,t,e){return r&t^~r&e}function vs(r,t,e){return r&t^r&e^t&e}var Te=class extends _e{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=Er(this.buffer)}update(t){Be(this);let{view:e,buffer:n,blockLen:o}=this;t=Fe(t);let s=t.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let a=Er(t);for(;o<=s-i;i+=o)this.process(a,i);continue}n.set(t.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Be(this),xs(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>o-i&&(this.process(n,0),i=0);for(let f=i;f<o;f++)e[f]=0;Lc(n,o-8,BigInt(this.length*8),s),this.process(n,0);let c=Er(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let l=a/4,u=this.get();if(l>u.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<l;f++)c.setUint32(4*f,u[f],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:n,length:o,finished:s,destroyed:i,pos:c}=this;return t.length=o,t.pos=c,t.finished=s,t.destroyed=i,o%e&&t.buffer.set(n),t}};var Tc=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Zt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Yt=new Uint32Array(64),Pn=class extends Te{constructor(t=32){super(64,t,8,!1),this.A=Zt[0]|0,this.B=Zt[1]|0,this.C=Zt[2]|0,this.D=Zt[3]|0,this.E=Zt[4]|0,this.F=Zt[5]|0,this.G=Zt[6]|0,this.H=Zt[7]|0}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:c,H:a}=this;return[t,e,n,o,s,i,c,a]}set(t,e,n,o,s,i,c,a){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=c|0,this.H=a|0}process(t,e){for(let f=0;f<16;f++,e+=4)Yt[f]=t.getUint32(e,!1);for(let f=16;f<64;f++){let d=Yt[f-15],w=Yt[f-2],E=_t(d,7)^_t(d,18)^d>>>3,y=_t(w,17)^_t(w,19)^w>>>10;Yt[f]=y+Yt[f-7]+E+Yt[f-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:a,G:l,H:u}=this;for(let f=0;f<64;f++){let d=_t(c,6)^_t(c,11)^_t(c,25),w=u+d+Ss(c,a,l)+Tc[f]+Yt[f]|0,y=(_t(n,2)^_t(n,13)^_t(n,22))+vs(n,o,s)|0;u=l,l=a,a=c,c=i+w|0,i=s,s=o,o=n,n=w+y|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,a=a+this.F|0,l=l+this.G|0,u=u+this.H|0,this.set(n,o,s,i,c,a,l,u)}roundClean(){Yt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var ie=Sr(()=>new Pn);var vr=BigInt(4294967295),Cn=BigInt(32);function As(r,t=!1){return t?{h:Number(r&vr),l:Number(r>>Cn&vr)}:{h:Number(r>>Cn&vr)|0,l:Number(r&vr)|0}}function Pc(r,t=!1){let e=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let o=0;o<r.length;o++){let{h:s,l:i}=As(r[o],t);[e[o],n[o]]=[s,i]}return[e,n]}var Cc=(r,t)=>BigInt(r>>>0)<<Cn|BigInt(t>>>0),Dc=(r,t,e)=>r>>>e,Nc=(r,t,e)=>r<<32-e|t>>>e,Rc=(r,t,e)=>r>>>e|t<<32-e,Kc=(r,t,e)=>r<<32-e|t>>>e,Uc=(r,t,e)=>r<<64-e|t>>>e-32,kc=(r,t,e)=>r>>>e-32|t<<64-e,Oc=(r,t)=>t,Mc=(r,t)=>r,qc=(r,t,e)=>r<<e|t>>>32-e,Hc=(r,t,e)=>t<<e|r>>>32-e,Vc=(r,t,e)=>t<<e-32|r>>>64-e,zc=(r,t,e)=>r<<e-32|t>>>64-e;function Fc(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var Gc=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),jc=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Zc=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Yc=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Wc=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),$c=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var Xc={fromBig:As,split:Pc,toBig:Cc,shrSH:Dc,shrSL:Nc,rotrSH:Rc,rotrSL:Kc,rotrBH:Uc,rotrBL:kc,rotr32H:Oc,rotr32L:Mc,rotlSH:qc,rotlSL:Hc,rotlBH:Vc,rotlBL:zc,add:Fc,add3L:Gc,add3H:jc,add4L:Zc,add4H:Yc,add5H:$c,add5L:Wc},R=Xc;var[Jc,Qc]=R.split(["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))),Wt=new Uint32Array(80),$t=new Uint32Array(80),Dn=class extends Te{constructor(t=64){super(128,t,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:c,Dl:a,Eh:l,El:u,Fh:f,Fl:d,Gh:w,Gl:E,Hh:y,Hl:h}=this;return[t,e,n,o,s,i,c,a,l,u,f,d,w,E,y,h]}set(t,e,n,o,s,i,c,a,l,u,f,d,w,E,y,h){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=c|0,this.Dl=a|0,this.Eh=l|0,this.El=u|0,this.Fh=f|0,this.Fl=d|0,this.Gh=w|0,this.Gl=E|0,this.Hh=y|0,this.Hl=h|0}process(t,e){for(let p=0;p<16;p++,e+=4)Wt[p]=t.getUint32(e),$t[p]=t.getUint32(e+=4);for(let p=16;p<80;p++){let I=Wt[p-15]|0,C=$t[p-15]|0,D=R.rotrSH(I,C,1)^R.rotrSH(I,C,8)^R.shrSH(I,C,7),_=R.rotrSL(I,C,1)^R.rotrSL(I,C,8)^R.shrSL(I,C,7),L=Wt[p-2]|0,T=$t[p-2]|0,F=R.rotrSH(L,T,19)^R.rotrBH(L,T,61)^R.shrSH(L,T,6),q=R.rotrSL(L,T,19)^R.rotrBL(L,T,61)^R.shrSL(L,T,6),U=R.add4L(_,q,$t[p-7],$t[p-16]),nt=R.add4H(U,D,F,Wt[p-7],Wt[p-16]);Wt[p]=nt|0,$t[p]=U|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:l,Dl:u,Eh:f,El:d,Fh:w,Fl:E,Gh:y,Gl:h,Hh:b,Hl:v}=this;for(let p=0;p<80;p++){let I=R.rotrSH(f,d,14)^R.rotrSH(f,d,18)^R.rotrBH(f,d,41),C=R.rotrSL(f,d,14)^R.rotrSL(f,d,18)^R.rotrBL(f,d,41),D=f&w^~f&y,_=d&E^~d&h,L=R.add5L(v,C,_,Qc[p],$t[p]),T=R.add5H(L,b,I,D,Jc[p],Wt[p]),F=L|0,q=R.rotrSH(n,o,28)^R.rotrBH(n,o,34)^R.rotrBH(n,o,39),U=R.rotrSL(n,o,28)^R.rotrBL(n,o,34)^R.rotrBL(n,o,39),nt=n&s^n&c^s&c,S=o&i^o&a^i&a;b=y|0,v=h|0,y=w|0,h=E|0,w=f|0,E=d|0,{h:f,l:d}=R.add(l|0,u|0,T|0,F|0),l=c|0,u=a|0,c=s|0,a=i|0,s=n|0,i=o|0;let B=R.add3L(F,U,S);n=R.add3H(B,T,q,nt),o=B|0}({h:n,l:o}=R.add(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=R.add(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:a}=R.add(this.Ch|0,this.Cl|0,c|0,a|0),{h:l,l:u}=R.add(this.Dh|0,this.Dl|0,l|0,u|0),{h:f,l:d}=R.add(this.Eh|0,this.El|0,f|0,d|0),{h:w,l:E}=R.add(this.Fh|0,this.Fl|0,w|0,E|0),{h:y,l:h}=R.add(this.Gh|0,this.Gl|0,y|0,h|0),{h:b,l:v}=R.add(this.Hh|0,this.Hl|0,b|0,v|0),this.set(n,o,s,i,c,a,l,u,f,d,w,E,y,h,b,v)}roundClean(){Wt.fill(0),$t.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Nn=Sr(()=>new Dn);var kn=BigInt(0),Un=BigInt(1);function ae(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function On(r){if(!ae(r))throw new Error("Uint8Array expected")}function Pt(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}function Ge(r){let t=r.toString(16);return t.length&1?"0"+t:t}function _s(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?kn:BigInt("0x"+r)}var Ls=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",tu=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function Xt(r){if(On(r),Ls)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=tu[r[e]];return t}var kt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Is(r){if(r>=kt._0&&r<=kt._9)return r-kt._0;if(r>=kt.A&&r<=kt.F)return r-(kt.A-10);if(r>=kt.a&&r<=kt.f)return r-(kt.a-10)}function je(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(Ls)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=Is(r.charCodeAt(s)),c=Is(r.charCodeAt(s+1));if(i===void 0||c===void 0){let a=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+s)}n[o]=i*16+c}return n}function Ot(r){return _s(Xt(r))}function ce(r){return On(r),_s(Xt(Uint8Array.from(r).reverse()))}function ue(r,t){return je(r.toString(16).padStart(t*2,"0"))}function Pe(r,t){return ue(r,t).reverse()}function X(r,t,e){let n;if(typeof t=="string")try{n=je(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(ae(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 Jt(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];On(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 Rn=r=>typeof r=="bigint"&&kn<=r;function Ar(r,t,e){return Rn(r)&&Rn(t)&&Rn(e)&&t<=r&&r<e}function St(r,t,e,n){if(!Ar(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function Ts(r){let t;for(t=0;r>kn;r>>=Un,t+=1);return t}var fe=r=>(Un<<BigInt(r))-Un,Kn=r=>new Uint8Array(r),Bs=r=>Uint8Array.from(r);function Ps(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=Kn(r),o=Kn(r),s=0,i=()=>{n.fill(1),o.fill(0),s=0},c=(...f)=>e(o,n,...f),a=(f=Kn(0))=>{o=c(Bs([0]),f),n=c(),f.length!==0&&(o=c(Bs([1]),f),n=c())},l=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,d=[];for(;f<t;){n=c();let w=n.slice();d.push(w),f+=n.length}return Jt(...d)};return(f,d)=>{i(),a(f);let w;for(;!(w=d(l()));)a();return i(),w}}var eu={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||ae(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,t)=>t.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function Mt(r,t,e={}){let n=(o,s,i)=>{let c=eu[s];if(typeof c!="function")throw new Error("invalid validator function");let a=r[o];if(!(i&&a===void 0)&&!c(a,r))throw new Error("param "+String(o)+" is invalid. Expected "+s+", got "+a)};for(let[o,s]of Object.entries(t))n(o,s,!1);for(let[o,s]of Object.entries(e))n(o,s,!0);return r}function Ce(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 st=BigInt(0),Z=BigInt(1),le=BigInt(2),ru=BigInt(3),Mn=BigInt(4),Cs=BigInt(5),Ds=BigInt(8),nu=BigInt(9),ou=BigInt(16);function z(r,t){let e=r%t;return e>=st?e:t+e}function su(r,t,e){if(t<st)throw new Error("invalid exponent, negatives unsupported");if(e<=st)throw new Error("invalid modulus");if(e===Z)return st;let n=Z;for(;t>st;)t&Z&&(n=n*r%e),r=r*r%e,t>>=Z;return n}function Y(r,t,e){let n=r;for(;t-- >st;)n*=n,n%=e;return n}function Ir(r,t){if(r===st)throw new Error("invert: expected non-zero number");if(t<=st)throw new Error("invert: expected positive modulus, got "+t);let e=z(r,t),n=t,o=st,s=Z,i=Z,c=st;for(;e!==st;){let l=n/e,u=n%e,f=o-i*l,d=s-c*l;n=e,e=u,o=i,s=c,i=f,c=d}if(n!==Z)throw new Error("invert: does not exist");return z(o,t)}function iu(r){let t=(r-Z)/le,e,n,o;for(e=r-Z,n=0;e%le===st;e/=le,n++);for(o=le;o<r&&su(o,t,r)!==r-Z;o++)if(o>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){let i=(r+Z)/Mn;return function(a,l){let u=a.pow(l,i);if(!a.eql(a.sqr(u),l))throw new Error("Cannot find square root");return u}}let s=(e+Z)/le;return function(c,a){if(c.pow(a,t)===c.neg(c.ONE))throw new Error("Cannot find square root");let l=n,u=c.pow(c.mul(c.ONE,o),e),f=c.pow(a,s),d=c.pow(a,e);for(;!c.eql(d,c.ONE);){if(c.eql(d,c.ZERO))return c.ZERO;let w=1;for(let y=c.sqr(d);w<l&&!c.eql(y,c.ONE);w++)y=c.sqr(y);let E=c.pow(u,Z<<BigInt(l-w-1));u=c.sqr(E),f=c.mul(f,E),d=c.mul(d,u),l=w}return f}}function au(r){if(r%Mn===ru){let t=(r+Z)/Mn;return function(n,o){let s=n.pow(o,t);if(!n.eql(n.sqr(s),o))throw new Error("Cannot find square root");return s}}if(r%Ds===Cs){let t=(r-Cs)/Ds;return function(n,o){let s=n.mul(o,le),i=n.pow(s,t),c=n.mul(o,i),a=n.mul(n.mul(c,le),i),l=n.mul(c,n.sub(a,n.ONE));if(!n.eql(n.sqr(l),o))throw new Error("Cannot find square root");return l}}return r%ou,iu(r)}var Ns=(r,t)=>(z(r,t)&Z)===Z,cu=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function qn(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=cu.reduce((n,o)=>(n[o]="function",n),t);return Mt(r,e)}function uu(r,t,e){if(e<st)throw new Error("invalid exponent, negatives unsupported");if(e===st)return r.ONE;if(e===Z)return t;let n=r.ONE,o=t;for(;e>st;)e&Z&&(n=r.mul(n,o)),o=r.sqr(o),e>>=Z;return n}function fu(r,t){let e=new Array(t.length),n=t.reduce((s,i,c)=>r.is0(i)?s:(e[c]=s,r.mul(s,i)),r.ONE),o=r.inv(n);return t.reduceRight((s,i,c)=>r.is0(i)?s:(e[c]=r.mul(s,e[c]),r.mul(s,i)),o),e}function Hn(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function Qt(r,t,e=!1,n={}){if(r<=st)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:o,nByteLength:s}=Hn(r,t);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let i,c=Object.freeze({ORDER:r,isLE:e,BITS:o,BYTES:s,MASK:fe(o),ZERO:st,ONE:Z,create:a=>z(a,r),isValid:a=>{if(typeof a!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof a);return st<=a&&a<r},is0:a=>a===st,isOdd:a=>(a&Z)===Z,neg:a=>z(-a,r),eql:(a,l)=>a===l,sqr:a=>z(a*a,r),add:(a,l)=>z(a+l,r),sub:(a,l)=>z(a-l,r),mul:(a,l)=>z(a*l,r),pow:(a,l)=>uu(c,a,l),div:(a,l)=>z(a*Ir(l,r),r),sqrN:a=>a*a,addN:(a,l)=>a+l,subN:(a,l)=>a-l,mulN:(a,l)=>a*l,inv:a=>Ir(a,r),sqrt:n.sqrt||(a=>(i||(i=au(r)),i(c,a))),invertBatch:a=>fu(c,a),cmov:(a,l,u)=>u?l:a,toBytes:a=>e?Pe(a,s):ue(a,s),fromBytes:a=>{if(a.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+a.length);return e?ce(a):Ot(a)}});return Object.freeze(c)}function Rs(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 Vn(r){let t=Rs(r);return t+Math.ceil(t/2)}function Ks(r,t,e=!1){let n=r.length,o=Rs(t),s=Vn(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?ce(r):Ot(r),c=z(i,t-Z)+Z;return e?Pe(c,o):ue(c,o)}var Us=BigInt(0),Zn=BigInt(1);function zn(r,t){let e=t.negate();return r?e:t}function Os(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function Fn(r,t){Os(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=fe(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function ks(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,c=Number(r&o),a=r>>i;c>n&&(c-=s,a+=Zn);let l=t*n,u=l+Math.abs(c)-1,f=c===0,d=c<0,w=t%2!==0;return{nextN:a,offset:u,isZero:f,isNeg:d,isNegF:w,offsetF:l}}function lu(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 hu(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 Gn=new WeakMap,Ms=new WeakMap;function jn(r){return Ms.get(r)||1}function Br(r,t){return{constTimeNegate:zn,hasPrecomputes(e){return jn(e)!==1},unsafeLadder(e,n,o=r.ZERO){let s=e;for(;n>Us;)n&Zn&&(o=o.add(s)),s=s.double(),n>>=Zn;return o},precomputeWindow(e,n){let{windows:o,windowSize:s}=Fn(n,t),i=[],c=e,a=c;for(let l=0;l<o;l++){a=c,i.push(a);for(let u=1;u<s;u++)a=a.add(c),i.push(a);c=a.double()}return i},wNAF(e,n,o){let s=r.ZERO,i=r.BASE,c=Fn(e,t);for(let a=0;a<c.windows;a++){let{nextN:l,offset:u,isZero:f,isNeg:d,isNegF:w,offsetF:E}=ks(o,a,c);o=l,f?i=i.add(zn(w,n[E])):s=s.add(zn(d,n[u]))}return{p:s,f:i}},wNAFUnsafe(e,n,o,s=r.ZERO){let i=Fn(e,t);for(let c=0;c<i.windows&&o!==Us;c++){let{nextN:a,offset:l,isZero:u,isNeg:f}=ks(o,c,i);if(o=a,!u){let d=n[l];s=s.add(f?d.negate():d)}}return s},getPrecomputes(e,n,o){let s=Gn.get(n);return s||(s=this.precomputeWindow(n,e),e!==1&&Gn.set(n,o(s))),s},wNAFCached(e,n,o){let s=jn(e);return this.wNAF(s,this.getPrecomputes(s,e,o),n)},wNAFCachedUnsafe(e,n,o,s){let i=jn(e);return i===1?this.unsafeLadder(e,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,e,o),n,s)},setWindowSize(e,n){Os(n,t),Ms.set(e,n),Gn.delete(e)}}}function _r(r,t,e,n){if(lu(e,r),hu(n,t),e.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let o=r.ZERO,s=Ts(BigInt(e.length)),i=s>12?s-3:s>4?s-2:s?2:1,c=fe(i),a=new Array(Number(c)+1).fill(o),l=Math.floor((t.BITS-1)/i)*i,u=o;for(let f=l;f>=0;f-=i){a.fill(o);for(let w=0;w<n.length;w++){let E=n[w],y=Number(E>>BigInt(f)&c);a[y]=a[y].add(e[w])}let d=o;for(let w=a.length-1,E=o;w>0;w--)E=E.add(a[w]),d=d.add(E);if(u=u.add(d),f!==0)for(let w=0;w<i;w++)u=u.double()}return u}function Ze(r){return qn(r.Fp),Mt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Hn(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Ct=BigInt(0),mt=BigInt(1),qs=BigInt(2),du=BigInt(8),pu={zip215:!0};function mu(r){let t=Ze(r);return Mt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function Hs(r){let t=mu(r),{Fp:e,n,prehash:o,hash:s,randomBytes:i,nByteLength:c,h:a}=t,l=qs<<BigInt(c*8)-mt,u=e.create,f=Qt(t.n,t.nBitLength),d=t.uvRatio||((g,m)=>{try{return{isValid:!0,value:e.sqrt(g*e.inv(m))}}catch{return{isValid:!1,value:Ct}}}),w=t.adjustScalarBytes||(g=>g),E=t.domain||((g,m,x)=>{if(Pt("phflag",x),m.length||x)throw new Error("Contexts/pre-hash are not supported");return g});function y(g,m,x=!1){let A=x?mt:Ct;St("coordinate "+g,m,A,l)}function h(g){if(!(g instanceof p))throw new Error("ExtendedPoint expected")}let b=Ce((g,m)=>{let{ex:x,ey:A,ez:N}=g,K=g.is0();m==null&&(m=K?du:e.inv(N));let k=u(x*m),O=u(A*m),M=u(N*m);if(K)return{x:Ct,y:mt};if(M!==mt)throw new Error("invZ was invalid");return{x:k,y:O}}),v=Ce(g=>{let{a:m,d:x}=t;if(g.is0())throw new Error("bad point: ZERO");let{ex:A,ey:N,ez:K,et:k}=g,O=u(A*A),M=u(N*N),V=u(K*K),rt=u(V*V),Q=u(O*m),ct=u(V*u(Q+M)),bt=u(rt+u(x*u(O*M)));if(ct!==bt)throw new Error("bad point: equation left != right (1)");let it=u(A*N),ut=u(K*k);if(it!==ut)throw new Error("bad point: equation left != right (2)");return!0});class p{constructor(m,x,A,N){y("x",m),y("y",x),y("z",A,!0),y("t",N),this.ex=m,this.ey=x,this.ez=A,this.et=N,Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(m){if(m instanceof p)throw new Error("extended point not allowed");let{x,y:A}=m||{};return y("x",x),y("y",A),new p(x,A,mt,u(x*A))}static normalizeZ(m){let x=e.invertBatch(m.map(A=>A.ez));return m.map((A,N)=>A.toAffine(x[N])).map(p.fromAffine)}static msm(m,x){return _r(p,f,m,x)}_setWindowSize(m){D.setWindowSize(this,m)}assertValidity(){v(this)}equals(m){h(m);let{ex:x,ey:A,ez:N}=this,{ex:K,ey:k,ez:O}=m,M=u(x*O),V=u(K*N),rt=u(A*O),Q=u(k*N);return M===V&&rt===Q}is0(){return this.equals(p.ZERO)}negate(){return new p(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){let{a:m}=t,{ex:x,ey:A,ez:N}=this,K=u(x*x),k=u(A*A),O=u(qs*u(N*N)),M=u(m*K),V=x+A,rt=u(u(V*V)-K-k),Q=M+k,ct=Q-O,bt=M-k,it=u(rt*ct),ut=u(Q*bt),Et=u(rt*bt),At=u(ct*Q);return new p(it,ut,At,Et)}add(m){h(m);let{a:x,d:A}=t,{ex:N,ey:K,ez:k,et:O}=this,{ex:M,ey:V,ez:rt,et:Q}=m,ct=u(N*M),bt=u(K*V),it=u(O*A*Q),ut=u(k*rt),Et=u((N+K)*(M+V)-ct-bt),At=ut-it,Ue=ut+it,Fo=u(bt-x*ct),Wi=u(Et*At),$i=u(Ue*Fo),Xi=u(Et*Fo),Ji=u(At*Ue);return new p(Wi,$i,Ji,Xi)}subtract(m){return this.add(m.negate())}wNAF(m){return D.wNAFCached(this,m,p.normalizeZ)}multiply(m){let x=m;St("scalar",x,mt,n);let{p:A,f:N}=this.wNAF(x);return p.normalizeZ([A,N])[0]}multiplyUnsafe(m,x=p.ZERO){let A=m;return St("scalar",A,Ct,n),A===Ct?C:this.is0()||A===mt?this:D.wNAFCachedUnsafe(this,A,p.normalizeZ,x)}isSmallOrder(){return this.multiplyUnsafe(a).is0()}isTorsionFree(){return D.unsafeLadder(this,n).is0()}toAffine(m){return b(this,m)}clearCofactor(){let{h:m}=t;return m===mt?this:this.multiplyUnsafe(m)}static fromHex(m,x=!1){let{d:A,a:N}=t,K=e.BYTES;m=X("pointHex",m,K),Pt("zip215",x);let k=m.slice(),O=m[K-1];k[K-1]=O&-129;let M=ce(k),V=x?l:e.ORDER;St("pointHex.y",M,Ct,V);let rt=u(M*M),Q=u(rt-mt),ct=u(A*rt-N),{isValid:bt,value:it}=d(Q,ct);if(!bt)throw new Error("Point.fromHex: invalid y coordinate");let ut=(it&mt)===mt,Et=(O&128)!==0;if(!x&&it===Ct&&Et)throw new Error("Point.fromHex: x=0 and x_0=1");return Et!==ut&&(it=u(-it)),p.fromAffine({x:it,y:M})}static fromPrivateKey(m){let{scalar:x}=T(m);return I.multiply(x)}toRawBytes(){let{x:m,y:x}=this.toAffine(),A=Pe(x,e.BYTES);return A[A.length-1]|=m&mt?128:0,A}toHex(){return Xt(this.toRawBytes())}}p.BASE=new p(t.Gx,t.Gy,mt,u(t.Gx*t.Gy)),p.ZERO=new p(Ct,mt,mt,Ct);let{BASE:I,ZERO:C}=p,D=Br(p,c*8);function _(g){return z(g,n)}function L(g){return _(ce(g))}function T(g){let m=e.BYTES;g=X("private key",g,m);let x=X("hashed private key",s(g),2*m),A=w(x.slice(0,m)),N=x.slice(m,2*m),K=L(A);return{head:A,prefix:N,scalar:K}}function F(g){let{head:m,prefix:x,scalar:A}=T(g),N=I.multiply(A),K=N.toRawBytes();return{head:m,prefix:x,scalar:A,point:N,pointBytes:K}}function q(g){return F(g).pointBytes}function U(g=new Uint8Array,...m){let x=Jt(...m);return L(s(E(x,X("context",g),!!o)))}function nt(g,m,x={}){g=X("message",g),o&&(g=o(g));let{prefix:A,scalar:N,pointBytes:K}=F(m),k=U(x.context,A,g),O=I.multiply(k).toRawBytes(),M=U(x.context,O,K,g),V=_(k+M*N);St("signature.s",V,Ct,n);let rt=Jt(O,Pe(V,e.BYTES));return X("result",rt,e.BYTES*2)}let S=pu;function B(g,m,x,A=S){let{context:N,zip215:K}=A,k=e.BYTES;g=X("signature",g,2*k),m=X("message",m),x=X("publicKey",x,k),K!==void 0&&Pt("zip215",K),o&&(m=o(m));let O=ce(g.slice(k,2*k)),M,V,rt;try{M=p.fromHex(x,K),V=p.fromHex(g.slice(0,k),K),rt=I.multiplyUnsafe(O)}catch{return!1}if(!K&&M.isSmallOrder())return!1;let Q=U(N,V.toRawBytes(),M.toRawBytes(),m);return V.add(M.multiplyUnsafe(Q)).subtract(rt).clearCofactor().equals(p.ZERO)}return I._setWindowSize(8),{CURVE:t,getPublicKey:q,sign:nt,verify:B,ExtendedPoint:p,utils:{getExtendedPublicKey:F,randomPrivateKey:()=>i(e.BYTES),precompute(g=8,m=p.BASE){return m._setWindowSize(g),m.multiply(BigInt(3)),m}}}}var Yn=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Vs=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Kh=BigInt(0),yu=BigInt(1),zs=BigInt(2),Uh=BigInt(3),bu=BigInt(5),gu=BigInt(8);function wu(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=Yn,c=r*r%s*r%s,a=Y(c,zs,s)*c%s,l=Y(a,yu,s)*r%s,u=Y(l,bu,s)*l%s,f=Y(u,t,s)*u%s,d=Y(f,e,s)*f%s,w=Y(d,n,s)*d%s,E=Y(w,o,s)*w%s,y=Y(E,o,s)*w%s,h=Y(y,t,s)*u%s;return{pow_p_5_8:Y(h,zs,s)*r%s,b2:c}}function xu(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function Eu(r,t){let e=Yn,n=z(t*t*t,e),o=z(n*n*t,e),s=wu(r*o).pow_p_5_8,i=z(r*n*s,e),c=z(t*i*i,e),a=i,l=z(i*Vs,e),u=c===r,f=c===z(-r,e),d=c===z(-r*Vs,e);return u&&(i=a),(f||d)&&(i=l),Ns(i,e)&&(i=z(-i,e)),{isValid:u||f,value:i}}var Fs=Qt(Yn,void 0,!0),Su={a:Fs.create(BigInt(-1)),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Fs,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:gu,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Nn,randomBytes:Le,adjustScalarBytes:xu,uvRatio:Eu},Gs=Hs(Su);var Lr=32;function js(r,t,e){return Gs.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}var Tr=class{type="Ed25519";raw;constructor(t){this.raw=Wn(t,Lr)}toMultihash(){return Bt.digest(Ut(this))}toCID(){return ft.createV1(114,this.toMultihash())}toString(){return $.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:wt(this.raw,t.raw)}verify(t,e){return js(this.raw,e,t)}};function $n(r){return r=Wn(r,Lr),new Tr(r)}function Wn(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new W(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var Au=Math.pow(2,7),Iu=Math.pow(2,14),Bu=Math.pow(2,21),Xn=Math.pow(2,28),Jn=Math.pow(2,35),Qn=Math.pow(2,42),to=Math.pow(2,49),H=128,ht=127;function Lt(r){if(r<Au)return 1;if(r<Iu)return 2;if(r<Bu)return 3;if(r<Xn)return 4;if(r<Jn)return 5;if(r<Qn)return 6;if(r<to)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function eo(r,t,e=0){switch(Lt(r)){case 8:t[e++]=r&255|H,r/=128;case 7:t[e++]=r&255|H,r/=128;case 6:t[e++]=r&255|H,r/=128;case 5:t[e++]=r&255|H,r/=128;case 4:t[e++]=r&255|H,r>>>=7;case 3:t[e++]=r&255|H,r>>>=7;case 2:t[e++]=r&255|H,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function _u(r,t,e=0){switch(Lt(r)){case 8:t.set(e++,r&255|H),r/=128;case 7:t.set(e++,r&255|H),r/=128;case 6:t.set(e++,r&255|H),r/=128;case 5:t.set(e++,r&255|H),r/=128;case 4:t.set(e++,r&255|H),r>>>=7;case 3:t.set(e++,r&255|H),r>>>=7;case 2:t.set(e++,r&255|H),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function ro(r,t){let e=r[t],n=0;if(n+=e&ht,e<H||(e=r[t+1],n+=(e&ht)<<7,e<H)||(e=r[t+2],n+=(e&ht)<<14,e<H)||(e=r[t+3],n+=(e&ht)<<21,e<H)||(e=r[t+4],n+=(e&ht)*Xn,e<H)||(e=r[t+5],n+=(e&ht)*Jn,e<H)||(e=r[t+6],n+=(e&ht)*Qn,e<H)||(e=r[t+7],n+=(e&ht)*to,e<H))return n;throw new RangeError("Could not decode varint")}function Lu(r,t){let e=r.get(t),n=0;if(n+=e&ht,e<H||(e=r.get(t+1),n+=(e&ht)<<7,e<H)||(e=r.get(t+2),n+=(e&ht)<<14,e<H)||(e=r.get(t+3),n+=(e&ht)<<21,e<H)||(e=r.get(t+4),n+=(e&ht)*Xn,e<H)||(e=r.get(t+5),n+=(e&ht)*Jn,e<H)||(e=r.get(t+6),n+=(e&ht)*Qn,e<H)||(e=r.get(t+7),n+=(e&ht)*to,e<H))return n;throw new RangeError("Could not decode varint")}function Ys(r,t,e=0){return t==null&&(t=lt(Lt(r))),t instanceof Uint8Array?eo(r,t,e):_u(r,t,e)}function Ws(r,t=0){return r instanceof Uint8Array?ro(r,t):Lu(r,t)}var no=new Float32Array([-0]),te=new Uint8Array(no.buffer);function Xs(r,t,e){no[0]=r,t[e]=te[0],t[e+1]=te[1],t[e+2]=te[2],t[e+3]=te[3]}function Js(r,t){return te[0]=r[t],te[1]=r[t+1],te[2]=r[t+2],te[3]=r[t+3],no[0]}var oo=new Float64Array([-0]),dt=new Uint8Array(oo.buffer);function Qs(r,t,e){oo[0]=r,t[e]=dt[0],t[e+1]=dt[1],t[e+2]=dt[2],t[e+3]=dt[3],t[e+4]=dt[4],t[e+5]=dt[5],t[e+6]=dt[6],t[e+7]=dt[7]}function ti(r,t){return dt[0]=r[t],dt[1]=r[t+1],dt[2]=r[t+2],dt[3]=r[t+3],dt[4]=r[t+4],dt[5]=r[t+5],dt[6]=r[t+6],dt[7]=r[t+7],oo[0]}var Tu=BigInt(Number.MAX_SAFE_INTEGER),Pu=BigInt(Number.MIN_SAFE_INTEGER),vt=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return he;if(t<Tu&&t>Pu)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>ei&&(o=0n,++n>ei&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return he;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):he}},he=new vt(0,0);he.toBigInt=function(){return 0n};he.zzEncode=he.zzDecode=function(){return this};he.length=function(){return 1};var ei=4294967296n;function ri(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 ni(r,t,e){if(e-t<1)return"";let o,s=[],i=0,c;for(;t<e;)c=r[t++],c<128?s[i++]=c:c>191&&c<224?s[i++]=(c&31)<<6|r[t++]&63:c>239&&c<365?(c=((c&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(c>>10),s[i++]=56320+(c&1023)):s[i++]=(c&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function so(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 Tt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Pr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var io=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,Tt(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 Tt(this,4);return Pr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Tt(this,4);return Pr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Tt(this,4);let t=Js(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Tt(this,4);let t=ti(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 Tt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return ni(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Tt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Tt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new vt(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw Tt(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 Tt(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 Tt(this,8);let t=Pr(this.buf,this.pos+=4),e=Pr(this.buf,this.pos+=4);return new vt(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=ro(this.buf,this.pos);return this.pos+=Lt(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 ao(r){return new io(r instanceof Uint8Array?r:r.subarray())}function Cr(r,t,e){let n=ao(r);return t.decode(n,void 0,e)}function co(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return lt(i);o+i>t&&(n=lt(t),o=0);let c=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),c}}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 uo(){}var lo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Cu=co();function Du(r){return globalThis.Buffer!=null?lt(r):Cu(r)}var We=class{len;head;tail;states;constructor(){this.len=0,this.head=new de(uo,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 ho((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(Dr,10,vt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=vt.fromBigInt(t);return this._push(Dr,e.length(),e)}uint64Number(t){return this._push(eo,Lt(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=vt.fromBigInt(t).zzEncode();return this._push(Dr,e.length(),e)}sint64Number(t){let e=vt.fromNumber(t).zzEncode();return this._push(Dr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(fo,1,t?1:0)}fixed32(t){return this._push(Ye,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=vt.fromBigInt(t);return this._push(Ye,4,e.lo)._push(Ye,4,e.hi)}fixed64Number(t){let e=vt.fromNumber(t);return this._push(Ye,4,e.lo)._push(Ye,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(Xs,4,t)}double(t){return this._push(Qs,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(fo,1,0):this.uint32(e)._push(Ru,e,t)}string(t){let e=ri(t);return e!==0?this.uint32(e)._push(so,e,t):this._push(fo,1,0)}fork(){return this.states=new lo(this),this.head=this.tail=new de(uo,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(uo,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=Du(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function fo(r,t,e){t[e]=r&255}function Nu(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var ho=class extends de{next;constructor(t,e){super(Nu,t,e),this.next=void 0}};function Dr(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 Ye(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 Ru(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(We.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Ku,t,r),this},We.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Uu,t,r),this});function Ku(r,t,e){t.set(r,e)}function Uu(r,t,e){r.length<40?so(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(G(r),e)}function po(){return new We}function Nr(r,t){let e=po();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var De;(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"})(De||(De={}));function Rr(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function mo(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(s,i){let c=t(s);i.int32(c)},n=function(s){let i=s.int32();return t(i)};return Rr("enum",De.VARINT,e,n)}function Kr(r,t){return Rr("message",De.LENGTH_DELIMITED,r,t)}var et;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(et||(et={}));var yo;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(yo||(yo={}));(function(r){r.codec=()=>mo(yo)})(et||(et={}));var Dt;(function(r){let t;r.codec=()=>(t==null&&(t=Kr((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),et.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 c=e.uint32();switch(c>>>3){case 1:{s.Type=et.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(c&7);break}}}return s})),t),r.encode=e=>Nr(e,r.codec()),r.decode=(e,n)=>Cr(e,r.codec(),n)})(Dt||(Dt={}));var bo;(function(r){let t;r.codec=()=>(t==null&&(t=Kr((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),et.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 c=e.uint32();switch(c>>>3){case 1:{s.Type=et.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(c&7);break}}}return s})),t),r.encode=e=>Nr(e,r.codec()),r.decode=(e,n)=>Cr(e,r.codec(),n)})(bo||(bo={}));function Ur(r){if(isNaN(r)||r<=0)throw new W("random bytes length must be a Number bigger than 0");return Le(r)}var $e=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},kr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var ii={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new kr("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 ee=ii;var Je={};gt(Je,{MAX_RSA_KEY_SIZE:()=>go,generateRSAKeyPair:()=>fi,jwkToJWKKeyPair:()=>li,jwkToPkcs1:()=>qu,jwkToPkix:()=>So,jwkToRSAPrivateKey:()=>Bo,pkcs1MessageToJwk:()=>xo,pkcs1MessageToRSAPrivateKey:()=>vo,pkcs1ToJwk:()=>Mu,pkcs1ToRSAPrivateKey:()=>ui,pkixMessageToJwk:()=>Eo,pkixMessageToRSAPublicKey:()=>Io,pkixToJwk:()=>Hu,pkixToRSAPublicKey:()=>Ao});var Ne=class{type="RSA";jwk;_raw;_multihash;constructor(t,e){this.jwk=t,this._multihash=e}get raw(){return this._raw==null&&(this._raw=Je.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return ft.createV1(114,this._multihash)}toString(){return $.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:wt(this.raw,t.raw)}verify(t,e){return ci(this.jwk,e,t)}},Xe=class{type="RSA";jwk;_raw;publicKey;constructor(t,e){this.jwk=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=Je.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:wt(this.raw,t.raw)}sign(t){return ai(this.jwk,t)}};var go=8192,wo=18,ku=1062,Ou=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Mu(r){let t=Kt(r);return xo(t)}function xo(r){return{n:j(r[1],"base64url"),e:j(r[2],"base64url"),d:j(r[3],"base64url"),p:j(r[4],"base64url"),q:j(r[5],"base64url"),dp:j(r[6],"base64url"),dq:j(r[7],"base64url"),qi:j(r[8],"base64url"),kty:"RSA"}}function qu(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 W("JWK was missing components");return jt([xt(Uint8Array.from([0])),xt(G(r.n,"base64url")),xt(G(r.e,"base64url")),xt(G(r.d,"base64url")),xt(G(r.p,"base64url")),xt(G(r.q,"base64url")),xt(G(r.dp,"base64url")),xt(G(r.dq,"base64url")),xt(G(r.qi,"base64url"))]).subarray()}function Hu(r){let t=Kt(r,{offset:0});return Eo(t)}function Eo(r){let t=Kt(r[1],{offset:0});return{kty:"RSA",n:j(t[0],"base64url"),e:j(t[1],"base64url")}}function So(r){if(r.n==null||r.e==null)throw new W("JWK was missing components");return jt([Ou,xr(jt([xt(G(r.n,"base64url")),xt(G(r.e,"base64url"))]))]).subarray()}function ui(r){let t=Kt(r);return vo(t)}function vo(r){let t=xo(r);return Bo(t)}function Ao(r,t){if(r.byteLength>=ku)throw new be("Key size is too large");let e=Kt(r,{offset:0});return Io(e,r,t)}function Io(r,t,e){let n=Eo(r);if(e==null){let o=ie(Dt.encode({Type:et.RSA,Data:t}));e=It(wo,o)}return new Ne(n,e)}function Bo(r){if(di(r)>go)throw new W("Key size is too large");let t=li(r),e=ie(Dt.encode({Type:et.RSA,Data:So(t.publicKey)})),n=It(wo,e);return new Xe(t.privateKey,new Ne(t.publicKey,n))}async function fi(r){if(r>go)throw new W("Key size is too large");let t=await hi(r),e=ie(Dt.encode({Type:et.RSA,Data:So(t.publicKey)})),n=It(wo,e);return new Xe(t.privateKey,new Ne(t.publicKey,n))}function li(r){if(r==null)throw new W("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function hi(r){let t=await ee.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),e=await Vu(t);return{privateKey:e[0],publicKey:e[1]}}async function ai(r,t){let e=await ee.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await ee.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},e,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(n,0,n.byteLength)}async function ci(r,t,e){let n=await ee.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return ee.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,t,e instanceof Uint8Array?e:e.subarray())}async function Vu(r){if(r.privateKey==null||r.publicKey==null)throw new W("Private and public key are required");return Promise.all([ee.get().subtle.exportKey("jwk",r.privateKey),ee.get().subtle.exportKey("jwk",r.publicKey)])}function di(r){if(r.kty!=="RSA")throw new W("invalid key type");if(r.n==null)throw new W("invalid key modulus");return G(r.n,"base64url").length*8}var Or=class extends _e{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,ws(t);let n=Fe(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),s.fill(0)}update(t){return Be(this),this.iHash.update(t),this}digestInto(t){Be(this),Ie(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:c}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=c,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},_o=(r,t,e)=>new Or(r,t).update(e).digest();_o.create=(r,t)=>new Or(r,t);function pi(r){r.lowS!==void 0&&Pt("lowS",r.lowS),r.prehash!==void 0&&Pt("prehash",r.prehash)}function zu(r){let t=Ze(r);Mt(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:e,Fp:n,a:o}=t;if(e){if(!n.eql(o,n.ZERO))throw new Error("invalid endomorphism, can only be defined for Koblitz curves that have a=0");if(typeof e!="object"||typeof e.beta!="bigint"||typeof e.splitScalar!="function")throw new Error("invalid endomorphism, expected beta: bigint and splitScalar: function")}return Object.freeze({...t})}var Lo=class extends Error{constructor(t=""){super(t)}},qt={Err:Lo,_tlv:{encode:(r,t)=>{let{Err:e}=qt;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,o=Ge(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?Ge(o.length/2|128):"";return Ge(r)+s+o+t},decode(r,t){let{Err:e}=qt,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let a=o&127;if(!a)throw new e("tlv.decode(long): indefinite length not supported");if(a>4)throw new e("tlv.decode(long): byte length is too big");let l=t.subarray(n,n+a);if(l.length!==a)throw new e("tlv.decode: length bytes not complete");if(l[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let u of l)i=i<<8|u;if(n+=a,i<128)throw new e("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+i);if(c.length!==i)throw new e("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=qt;if(r<Ht)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}=qt;if(r[0]&128)throw new t("invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Ot(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=qt,o=X("signature",r),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:c,l:a}=n.decode(2,s),{v:l,l:u}=n.decode(2,a);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(c),s:e.decode(l)}},hexFromSig(r){let{_tlv:t,_int:e}=qt,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}},Ht=BigInt(0),at=BigInt(1),lp=BigInt(2),mi=BigInt(3),hp=BigInt(4);function Fu(r){let t=zu(r),{Fp:e}=t,n=Qt(t.n,t.nBitLength),o=t.toBytes||((y,h,b)=>{let v=h.toAffine();return Jt(Uint8Array.from([4]),e.toBytes(v.x),e.toBytes(v.y))}),s=t.fromBytes||(y=>{let h=y.subarray(1),b=e.fromBytes(h.subarray(0,e.BYTES)),v=e.fromBytes(h.subarray(e.BYTES,2*e.BYTES));return{x:b,y:v}});function i(y){let{a:h,b}=t,v=e.sqr(y),p=e.mul(v,y);return e.add(e.add(p,e.mul(y,h)),b)}if(!e.eql(e.sqr(t.Gy),i(t.Gx)))throw new Error("bad generator point: equation left != right");function c(y){return Ar(y,at,t.n)}function a(y){let{allowedPrivateKeyLengths:h,nByteLength:b,wrapPrivateKey:v,n:p}=t;if(h&&typeof y!="bigint"){if(ae(y)&&(y=Xt(y)),typeof y!="string"||!h.includes(y.length))throw new Error("invalid private key");y=y.padStart(b*2,"0")}let I;try{I=typeof y=="bigint"?y:Ot(X("private key",y,b))}catch{throw new Error("invalid private key, expected hex or "+b+" bytes, got "+typeof y)}return v&&(I=z(I,p)),St("private key",I,at,p),I}function l(y){if(!(y instanceof d))throw new Error("ProjectivePoint expected")}let u=Ce((y,h)=>{let{px:b,py:v,pz:p}=y;if(e.eql(p,e.ONE))return{x:b,y:v};let I=y.is0();h==null&&(h=I?e.ONE:e.inv(p));let C=e.mul(b,h),D=e.mul(v,h),_=e.mul(p,h);if(I)return{x:e.ZERO,y:e.ZERO};if(!e.eql(_,e.ONE))throw new Error("invZ was invalid");return{x:C,y:D}}),f=Ce(y=>{if(y.is0()){if(t.allowInfinityPoint&&!e.is0(y.py))return;throw new Error("bad point: ZERO")}let{x:h,y:b}=y.toAffine();if(!e.isValid(h)||!e.isValid(b))throw new Error("bad point: x or y not FE");let v=e.sqr(b),p=i(h);if(!e.eql(v,p))throw new Error("bad point: equation left != right");if(!y.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class d{constructor(h,b,v){if(h==null||!e.isValid(h))throw new Error("x required");if(b==null||!e.isValid(b))throw new Error("y required");if(v==null||!e.isValid(v))throw new Error("z required");this.px=h,this.py=b,this.pz=v,Object.freeze(this)}static fromAffine(h){let{x:b,y:v}=h||{};if(!h||!e.isValid(b)||!e.isValid(v))throw new Error("invalid affine point");if(h instanceof d)throw new Error("projective point not allowed");let p=I=>e.eql(I,e.ZERO);return p(b)&&p(v)?d.ZERO:new d(b,v,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){let b=e.invertBatch(h.map(v=>v.pz));return h.map((v,p)=>v.toAffine(b[p])).map(d.fromAffine)}static fromHex(h){let b=d.fromAffine(s(X("pointHex",h)));return b.assertValidity(),b}static fromPrivateKey(h){return d.BASE.multiply(a(h))}static msm(h,b){return _r(d,n,h,b)}_setWindowSize(h){E.setWindowSize(this,h)}assertValidity(){f(this)}hasEvenY(){let{y:h}=this.toAffine();if(e.isOdd)return!e.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){l(h);let{px:b,py:v,pz:p}=this,{px:I,py:C,pz:D}=h,_=e.eql(e.mul(b,D),e.mul(I,p)),L=e.eql(e.mul(v,D),e.mul(C,p));return _&&L}negate(){return new d(this.px,e.neg(this.py),this.pz)}double(){let{a:h,b}=t,v=e.mul(b,mi),{px:p,py:I,pz:C}=this,D=e.ZERO,_=e.ZERO,L=e.ZERO,T=e.mul(p,p),F=e.mul(I,I),q=e.mul(C,C),U=e.mul(p,I);return U=e.add(U,U),L=e.mul(p,C),L=e.add(L,L),D=e.mul(h,L),_=e.mul(v,q),_=e.add(D,_),D=e.sub(F,_),_=e.add(F,_),_=e.mul(D,_),D=e.mul(U,D),L=e.mul(v,L),q=e.mul(h,q),U=e.sub(T,q),U=e.mul(h,U),U=e.add(U,L),L=e.add(T,T),T=e.add(L,T),T=e.add(T,q),T=e.mul(T,U),_=e.add(_,T),q=e.mul(I,C),q=e.add(q,q),T=e.mul(q,U),D=e.sub(D,T),L=e.mul(q,F),L=e.add(L,L),L=e.add(L,L),new d(D,_,L)}add(h){l(h);let{px:b,py:v,pz:p}=this,{px:I,py:C,pz:D}=h,_=e.ZERO,L=e.ZERO,T=e.ZERO,F=t.a,q=e.mul(t.b,mi),U=e.mul(b,I),nt=e.mul(v,C),S=e.mul(p,D),B=e.add(b,v),P=e.add(I,C);B=e.mul(B,P),P=e.add(U,nt),B=e.sub(B,P),P=e.add(b,p);let g=e.add(I,D);return P=e.mul(P,g),g=e.add(U,S),P=e.sub(P,g),g=e.add(v,p),_=e.add(C,D),g=e.mul(g,_),_=e.add(nt,S),g=e.sub(g,_),T=e.mul(F,P),_=e.mul(q,S),T=e.add(_,T),_=e.sub(nt,T),T=e.add(nt,T),L=e.mul(_,T),nt=e.add(U,U),nt=e.add(nt,U),S=e.mul(F,S),P=e.mul(q,P),nt=e.add(nt,S),S=e.sub(U,S),S=e.mul(F,S),P=e.add(P,S),U=e.mul(nt,P),L=e.add(L,U),U=e.mul(g,P),_=e.mul(B,_),_=e.sub(_,U),U=e.mul(B,nt),T=e.mul(g,T),T=e.add(T,U),new d(_,L,T)}subtract(h){return this.add(h.negate())}is0(){return this.equals(d.ZERO)}wNAF(h){return E.wNAFCached(this,h,d.normalizeZ)}multiplyUnsafe(h){let{endo:b,n:v}=t;St("scalar",h,Ht,v);let p=d.ZERO;if(h===Ht)return p;if(this.is0()||h===at)return this;if(!b||E.hasPrecomputes(this))return E.wNAFCachedUnsafe(this,h,d.normalizeZ);let{k1neg:I,k1:C,k2neg:D,k2:_}=b.splitScalar(h),L=p,T=p,F=this;for(;C>Ht||_>Ht;)C&at&&(L=L.add(F)),_&at&&(T=T.add(F)),F=F.double(),C>>=at,_>>=at;return I&&(L=L.negate()),D&&(T=T.negate()),T=new d(e.mul(T.px,b.beta),T.py,T.pz),L.add(T)}multiply(h){let{endo:b,n:v}=t;St("scalar",h,at,v);let p,I;if(b){let{k1neg:C,k1:D,k2neg:_,k2:L}=b.splitScalar(h),{p:T,f:F}=this.wNAF(D),{p:q,f:U}=this.wNAF(L);T=E.constTimeNegate(C,T),q=E.constTimeNegate(_,q),q=new d(e.mul(q.px,b.beta),q.py,q.pz),p=T.add(q),I=F.add(U)}else{let{p:C,f:D}=this.wNAF(h);p=C,I=D}return d.normalizeZ([p,I])[0]}multiplyAndAddUnsafe(h,b,v){let p=d.BASE,I=(D,_)=>_===Ht||_===at||!D.equals(p)?D.multiplyUnsafe(_):D.multiply(_),C=I(this,b).add(I(h,v));return C.is0()?void 0:C}toAffine(h){return u(this,h)}isTorsionFree(){let{h,isTorsionFree:b}=t;if(h===at)return!0;if(b)return b(d,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:b}=t;return h===at?this:b?b(d,this):this.multiplyUnsafe(t.h)}toRawBytes(h=!0){return Pt("isCompressed",h),this.assertValidity(),o(d,this,h)}toHex(h=!0){return Pt("isCompressed",h),Xt(this.toRawBytes(h))}}d.BASE=new d(t.Gx,t.Gy,e.ONE),d.ZERO=new d(e.ZERO,e.ONE,e.ZERO);let w=t.nBitLength,E=Br(d,t.endo?Math.ceil(w/2):w);return{CURVE:t,ProjectivePoint:d,normPrivateKeyToScalar:a,weierstrassEquation:i,isWithinCurveOrder:c}}function Gu(r){let t=Ze(r);return Mt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function yi(r){let t=Gu(r),{Fp:e,n}=t,o=e.BYTES+1,s=2*e.BYTES+1;function i(S){return z(S,n)}function c(S){return Ir(S,n)}let{ProjectivePoint:a,normPrivateKeyToScalar:l,weierstrassEquation:u,isWithinCurveOrder:f}=Fu({...t,toBytes(S,B,P){let g=B.toAffine(),m=e.toBytes(g.x),x=Jt;return Pt("isCompressed",P),P?x(Uint8Array.from([B.hasEvenY()?2:3]),m):x(Uint8Array.from([4]),m,e.toBytes(g.y))},fromBytes(S){let B=S.length,P=S[0],g=S.subarray(1);if(B===o&&(P===2||P===3)){let m=Ot(g);if(!Ar(m,at,e.ORDER))throw new Error("Point is not on curve");let x=u(m),A;try{A=e.sqrt(x)}catch(k){let O=k instanceof Error?": "+k.message:"";throw new Error("Point is not on curve"+O)}let N=(A&at)===at;return(P&1)===1!==N&&(A=e.neg(A)),{x:m,y:A}}else if(B===s&&P===4){let m=e.fromBytes(g.subarray(0,e.BYTES)),x=e.fromBytes(g.subarray(e.BYTES,2*e.BYTES));return{x:m,y:x}}else{let m=o,x=s;throw new Error("invalid Point, expected length of "+m+", or uncompressed "+x+", got "+B)}}}),d=S=>Xt(ue(S,t.nByteLength));function w(S){let B=n>>at;return S>B}function E(S){return w(S)?i(-S):S}let y=(S,B,P)=>Ot(S.slice(B,P));class h{constructor(B,P,g){St("r",B,at,n),St("s",P,at,n),this.r=B,this.s=P,g!=null&&(this.recovery=g),Object.freeze(this)}static fromCompact(B){let P=t.nByteLength;return B=X("compactSignature",B,P*2),new h(y(B,0,P),y(B,P,2*P))}static fromDER(B){let{r:P,s:g}=qt.toSig(X("DER",B));return new h(P,g)}assertValidity(){}addRecoveryBit(B){return new h(this.r,this.s,B)}recoverPublicKey(B){let{r:P,s:g,recovery:m}=this,x=D(X("msgHash",B));if(m==null||![0,1,2,3].includes(m))throw new Error("recovery id invalid");let A=m===2||m===3?P+t.n:P;if(A>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let N=(m&1)===0?"02":"03",K=a.fromHex(N+d(A)),k=c(A),O=i(-x*k),M=i(g*k),V=a.BASE.multiplyAndAddUnsafe(K,O,M);if(!V)throw new Error("point at infinify");return V.assertValidity(),V}hasHighS(){return w(this.s)}normalizeS(){return this.hasHighS()?new h(this.r,i(-this.s),this.recovery):this}toDERRawBytes(){return je(this.toDERHex())}toDERHex(){return qt.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return je(this.toCompactHex())}toCompactHex(){return d(this.r)+d(this.s)}}let b={isValidPrivateKey(S){try{return l(S),!0}catch{return!1}},normPrivateKeyToScalar:l,randomPrivateKey:()=>{let S=Vn(t.n);return Ks(t.randomBytes(S),t.n)},precompute(S=8,B=a.BASE){return B._setWindowSize(S),B.multiply(BigInt(3)),B}};function v(S,B=!0){return a.fromPrivateKey(S).toRawBytes(B)}function p(S){let B=ae(S),P=typeof S=="string",g=(B||P)&&S.length;return B?g===o||g===s:P?g===2*o||g===2*s:S instanceof a}function I(S,B,P=!0){if(p(S))throw new Error("first arg must be private key");if(!p(B))throw new Error("second arg must be public key");return a.fromHex(B).multiply(l(S)).toRawBytes(P)}let C=t.bits2int||function(S){if(S.length>8192)throw new Error("input is too large");let B=Ot(S),P=S.length*8-t.nBitLength;return P>0?B>>BigInt(P):B},D=t.bits2int_modN||function(S){return i(C(S))},_=fe(t.nBitLength);function L(S){return St("num < 2^"+t.nBitLength,S,Ht,_),ue(S,t.nByteLength)}function T(S,B,P=F){if(["recovered","canonical"].some(Q=>Q in P))throw new Error("sign() legacy options not supported");let{hash:g,randomBytes:m}=t,{lowS:x,prehash:A,extraEntropy:N}=P;x==null&&(x=!0),S=X("msgHash",S),pi(P),A&&(S=X("prehashed msgHash",g(S)));let K=D(S),k=l(B),O=[L(k),L(K)];if(N!=null&&N!==!1){let Q=N===!0?m(e.BYTES):N;O.push(X("extraEntropy",Q))}let M=Jt(...O),V=K;function rt(Q){let ct=C(Q);if(!f(ct))return;let bt=c(ct),it=a.BASE.multiply(ct).toAffine(),ut=i(it.x);if(ut===Ht)return;let Et=i(bt*i(V+ut*k));if(Et===Ht)return;let At=(it.x===ut?0:2)|Number(it.y&at),Ue=Et;return x&&w(Et)&&(Ue=E(Et),At^=1),new h(ut,Ue,At)}return{seed:M,k2sig:rt}}let F={lowS:t.lowS,prehash:!1},q={lowS:t.lowS,prehash:!1};function U(S,B,P=F){let{seed:g,k2sig:m}=T(S,B,P),x=t;return Ps(x.hash.outputLen,x.nByteLength,x.hmac)(g,m)}a.BASE._setWindowSize(8);function nt(S,B,P,g=q){let m=S;B=X("msgHash",B),P=X("publicKey",P);let{lowS:x,prehash:A,format:N}=g;if(pi(g),"strict"in g)throw new Error("options.strict was renamed to lowS");if(N!==void 0&&N!=="compact"&&N!=="der")throw new Error("format must be compact or der");let K=typeof m=="string"||ae(m),k=!K&&!N&&typeof m=="object"&&m!==null&&typeof m.r=="bigint"&&typeof m.s=="bigint";if(!K&&!k)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let O,M;try{if(k&&(O=new h(m.r,m.s)),K){try{N!=="compact"&&(O=h.fromDER(m))}catch(At){if(!(At instanceof qt.Err))throw At}!O&&N!=="der"&&(O=h.fromCompact(m))}M=a.fromHex(P)}catch{return!1}if(!O||x&&O.hasHighS())return!1;A&&(B=t.hash(B));let{r:V,s:rt}=O,Q=D(B),ct=c(rt),bt=i(Q*ct),it=i(V*ct),ut=a.BASE.multiplyAndAddUnsafe(M,bt,it)?.toAffine();return ut?i(ut.x)===V:!1}return{CURVE:t,getPublicKey:v,getSharedSecret:I,sign:U,verify:nt,ProjectivePoint:a,Signature:h,utils:b}}function ju(r){return{hash:r,hmac:(t,...e)=>_o(r,t,Tn(...e)),randomBytes:Le}}function bi(r,t){let e=n=>yi({...r,...ju(n)});return{...e(t),create:e}}var xi=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),gi=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Zu=BigInt(1),To=BigInt(2),wi=(r,t)=>(r+t/To)/t;function Yu(r){let t=xi,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),a=BigInt(88),l=r*r*r%t,u=l*l*r%t,f=Y(u,e,t)*u%t,d=Y(f,e,t)*u%t,w=Y(d,To,t)*l%t,E=Y(w,o,t)*w%t,y=Y(E,s,t)*E%t,h=Y(y,c,t)*y%t,b=Y(h,a,t)*h%t,v=Y(b,c,t)*y%t,p=Y(v,e,t)*u%t,I=Y(p,i,t)*E%t,C=Y(I,n,t)*l%t,D=Y(C,To,t);if(!Po.eql(Po.sqr(D),r))throw new Error("Cannot find square root");return D}var Po=Qt(xi,void 0,void 0,{sqrt:Yu}),pe=bi({a:BigInt(0),b:BigInt(7),Fp:Po,n:gi,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=gi,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Zu*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=e,i=BigInt("0x100000000000000000000000000000000"),c=wi(s*r,t),a=wi(-n*r,t),l=z(r-c*e-a*o,t),u=z(-c*n-a*s,t),f=l>i,d=u>i;if(f&&(l=t-l),d&&(u=t-u),l>i||u>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:f,k1:l,k2neg:d,k2:u}}}},ie),Ep=BigInt(0);var Sp=pe.ProjectivePoint;function Ei(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Si(r,t,e){let n=oe.digest(e instanceof Uint8Array?e:e.subarray());if(Ei(n))return n.then(({digest:o})=>pe.verify(t,o,r)).catch(o=>{throw new $e(String(o))});try{return pe.verify(t,n.digest,r)}catch(o){throw new $e(String(o))}}var Mr=class{type="secp256k1";raw;_key;constructor(t){this._key=Ai(t),this.raw=vi(this._key)}toMultihash(){return Bt.digest(Ut(this))}toCID(){return ft.createV1(114,this.toMultihash())}toString(){return $.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:wt(this.raw,t.raw)}verify(t,e){return Si(this._key,e,t)}};function Co(r){return new Mr(r)}function vi(r){return pe.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Ai(r){try{return pe.ProjectivePoint.fromHex(r),r}catch(t){throw new be(String(t))}}function Do(r,t){let{Type:e,Data:n}=Dt.decode(r),o=n??new Uint8Array;switch(e){case et.RSA:return Ao(o,t);case et.Ed25519:return $n(o);case et.secp256k1:return Co(o);case et.ECDSA:return Ln(o);default:throw new re}}function Ii(r){let{Type:t,Data:e}=Dt.decode(r.digest),n=e??new Uint8Array;switch(t){case et.Ed25519:return $n(n);case et.secp256k1:return Co(n);case et.ECDSA:return Ln(n);default:throw new re}}function Ut(r){return Dt.encode({Type:et[r.type],Data:r.raw})}var Bi=Symbol.for("nodejs.util.inspect.custom"),Wu=114,Qe=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()})`}[Qr]=!0;toString(){return this.string==null&&(this.string=$.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ft.createV1(Wu,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return wt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return wt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Bi](){return`PeerId(${this.toString()})`}},tr=class extends Qe{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},er=class extends Qe{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},rr=class extends Qe{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},$u=2336,qr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Bt.digest(G(this.url))}[Bi](){return`PeerId(${this.url})`}[Qr]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ft.createV1($u,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=j(t)),t.toString()===this.toString())}};function No(r){if(r.type==="Ed25519")return new er({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new rr({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new tr({multihash:r.toCID().multihash,publicKey:r});throw new re}function _i(r){return No(r.publicKey)}function nr(r){if(Ju(r))return new tr({multihash:r});if(Xu(r))try{let t=Ii(r);if(t.type==="Ed25519")return new er({multihash:r,publicKey:t});if(t.type==="secp256k1")return new rr({multihash:r,publicKey:t})}catch{let e=j(r.digest);return new qr(new URL(e))}throw new mr("Supplied PeerID Multihash is invalid")}function Xu(r){return r.code===Bt.code}function Ju(r){return r.code===oe.code}function me(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 Hr(r){let t=Ft($.decode(`z${r}`));return nr(t)}var or=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 me(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 me(this.map.values(),t=>t.key)}values(){return me(this.map.values(),t=>t.value)}get size(){return this.map.size}};var sr=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 me(this.set.entries(),t=>{let e=Hr(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=Hr(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return me(this.set.values(),t=>Hr(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 Vt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Vr=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}},Re=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Vr(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 Vr(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 Ro=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function zr(r={}){return Qu(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 Qu(r,t){t=t??{};let e=t.onEnd,n=new Re,o,s,i,c=Vt(),a=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((h,b)=>{s=v=>{s=null,n.push(v);try{h(r(n))}catch(p){b(p)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{c.resolve(),c=Vt()})}},l=h=>s!=null?s(h):(n.push(h),o),u=h=>(n=new Re,s!=null?s({error:h}):(n.push({error:h}),o)),f=h=>{if(i)return o;if(t?.objectMode!==!0&&h?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:h})},d=h=>i?o:(i=!0,h!=null?u(h):l({done:!0})),w=()=>(n=new Re,d(),{done:!0}),E=h=>(d(h),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:a,return:w,throw:E,push:f,end:d,get readableLength(){return n.size},onEmpty:async h=>{let b=h?.signal;if(b?.throwIfAborted(),n.isEmpty())return;let v,p;b!=null&&(v=new Promise((I,C)=>{p=()=>{C(new Ro)},b.addEventListener("abort",p)}));try{await Promise.race([c.promise,v])}finally{p!=null&&b!=null&&b?.removeEventListener("abort",p)}}},e==null)return o;let y=o;return o={[Symbol.asyncIterator](){return this},next(){return y.next()},throw(h){return y.throw(h),e!=null&&(e(h),e=void 0),{done:!0}},return(){return y.return(),e!=null&&(e(),e=void 0),{done:!0}},push:f,end(h){return y.end(h),e!=null&&(e(h),e=void 0),o},get readableLength(){return y.readableLength},onEmpty:h=>y.onEmpty(h)},o}var Fr=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 Li(r,t,e){if(t==null)return r;if(t.aborted)return r.catch(()=>{}),Promise.reject(new Fr(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new Fr(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 Ko=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=Vt(),this.haveNext=Vt()}[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=Vt(),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=Vt(),await Li(this.readNext.promise,e?.signal,e)}};function Ti(){return new Ko}function tf(r){return r[Symbol.asyncIterator]!=null}async function ef(r,t){try{await Promise.all(r.map(async e=>{for await(let n of e)await t.push(n)})),await t.end()}catch(e){await t.end(e).catch(()=>{})}}async function*rf(r){let t=Ti();ef(r,t).catch(()=>{}),yield*t}function*nf(r){for(let t of r)yield*t}function of(...r){let t=[];for(let e of r)tf(e)||t.push(e);return t.length===r.length?nf(t):rf(r)}var Pi=of;function ir(r,...t){if(r==null)throw new Error("Empty pipeline");if(Uo(r)){let n=r;r=()=>n.source}else if(Di(r)||Ci(r)){let n=r;r=()=>n}let e=[r,...t];if(e.length>1&&Uo(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++)Uo(e[n])&&(e[n]=af(e[n]));return sf(...e)}var sf=(...r)=>{let t;for(;r.length>0;)t=r.shift()(t);return t},Ci=r=>r?.[Symbol.asyncIterator]!=null,Di=r=>r?.[Symbol.iterator]!=null,Uo=r=>r==null?!1:r.sink!=null&&r.source!=null,af=r=>t=>{let e=r.sink(t);if(e?.then!=null){let n=zr({objectMode:!0});e.then(()=>{n.end()},i=>{n.end(i)});let o,s=r.source;if(Ci(s))o=async function*(){yield*s,n.end()};else if(Di(s))o=function*(){yield*s,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return Pi(n,o())}return r.source};var Oo=sa(Ri(),1);var cr=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},Mo=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},Ki=r=>globalThis.DOMException===void 0?new Mo(r):new DOMException(r),Ui=r=>{let t=r.reason===void 0?Ki("This operation was aborted."):r.reason;return t instanceof Error?t:Ki(t)};function qo(r,t){let{milliseconds:e,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=t,i,c,l=new Promise((u,f)=>{if(typeof e!="number"||Math.sign(e)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${e}\``);if(t.signal){let{signal:w}=t;w.aborted&&f(Ui(w)),c=()=>{f(Ui(w))},w.addEventListener("abort",c,{once:!0})}if(e===Number.POSITIVE_INFINITY){r.then(u,f);return}let d=new cr;i=s.setTimeout.call(void 0,()=>{if(n){try{u(n())}catch(w){f(w)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?u():o instanceof Error?f(o):(d.message=o??`Promise timed out after ${e} milliseconds`,f(d))},e),(async()=>{try{u(await r)}catch(w){f(w)}})()}).finally(()=>{l.clear(),c&&t.signal&&t.signal.removeEventListener("abort",c)});return l.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},l}function Ho(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 ur=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=Ho(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 fr=class extends Oo.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:ur,...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}#S(){this.#n--,this.#f(),this.emit("next")}#v(){this.#g(),this.#b(),this.#c=void 0}get#A(){let t=Date.now();if(this.#r===void 0){let e=this.#p-t;if(e<0)this.#s=this.#t?this.#n:0;else return this.#c===void 0&&(this.#c=setTimeout(()=>{this.#v()},e)),!0}return!1}#f(){if(this.#e.size===0)return this.#r&&clearInterval(this.#r),this.#r=void 0,this.emit("empty"),this.#n===0&&this.emit("idle"),!1;if(!this.#o){let t=!this.#A;if(this.#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++,this.#s++;try{e.signal?.throwIfAborted();let s=t({signal:e.signal});e.timeout&&(s=qo(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 cr&&!e.throwOnTimeout){n();return}o(s),this.emit("error",s)}finally{this.#S()}},e),this.emit("add"),this.#f()})}async addAll(t,e){return Promise.all(t.map(async n=>this.add(n,e)))}start(){return this.#o?(this.#o=!1,this.#l(),this):this}pause(){this.#o=!0}clear(){this.#e=new this.#m}async onEmpty(){this.#e.size!==0&&await this.#h("empty")}async onSizeLessThan(t){this.#e.size<t||await this.#h("next",()=>this.#e.size<t)}async onIdle(){this.#n===0&&this.#e.size===0||await this.#h("idle")}async#h(t,e){return new Promise(n=>{let o=()=>{e&&!e()||(this.off(t,o),n())};this.on(t,o)})}get size(){return this.#e.size}sizeBy(t){return this.#e.filter(t).length}get pending(){return this.#n}get isPaused(){return this.#o}};function ki(r){if(r!=null){if(typeof r[Symbol.iterator]=="function")return r[Symbol.iterator]();if(typeof r[Symbol.asyncIterator]=="function")return r[Symbol.asyncIterator]();if(typeof r.next=="function")return r}throw new Error("argument is not an iterator or iterable")}function Oi(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Mi(r,t){let e=ki(r).return?.();Oi(e)&&e.catch(n=>{t.error("could not cause iterator to return",n)})}var jr=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Ke=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Zr=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},lr=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function Yr(r){return r[Symbol.asyncIterator]!=null}function qi(r,t){if(r.byteLength>t)throw new Ke("Message length too long")}var $r=r=>{let t=Lt(r),e=lt(t);return Ys(r,e),$r.bytes=t,e};$r.bytes=0;function Xr(r,t){t=t??{};let e=t.lengthEncoder??$r,n=t?.maxDataLength??4194304;function*o(s){qi(s,n);let i=e(s.byteLength);i instanceof Uint8Array?yield i:yield*i,s instanceof Uint8Array?yield s:yield*s}return Yr(r)?async function*(){for await(let s of r)yield*o(s)}():function*(){for(let s of r)yield*o(s)}()}Xr.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??$r,n=t?.maxDataLength??4194304;return qi(r,n),new ot(e(r.byteLength),r)};var ye;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(ye||(ye={}));var Vo=r=>{let t=Ws(r);return Vo.bytes=Lt(t),t};Vo.bytes=0;function hr(r,t){let e=new ot,n=ye.LENGTH,o=-1,s=t?.lengthDecoder??Vo,i=t?.maxLengthLength??8,c=t?.maxDataLength??4194304;function*a(){for(;e.byteLength>0;){if(n===ye.LENGTH)try{if(o=s(e),o<0)throw new jr("Invalid message length");if(o>c)throw new Ke("Message length too long");let l=s.bytes;e.consume(l),t?.onLength!=null&&t.onLength(o),n=ye.DATA}catch(l){if(l instanceof RangeError){if(e.byteLength>i)throw new Zr("Message length length too long");break}throw l}if(n===ye.DATA){if(e.byteLength<o)break;let l=e.sublist(0,o);e.consume(o),t?.onData!=null&&t.onData(l),yield l,n=ye.LENGTH}}}return Yr(r)?async function*(){for await(let l of r)e.append(l),yield*a();if(e.byteLength>0)throw new lr("Unexpected end of input")}():function*(){for(let l of r)e.append(l),yield*a();if(e.byteLength>0)throw new lr("Unexpected end of input")}()}hr.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 hr(n,{...t??{},onLength:s=>{e=s}})};var Jr=class extends ge{id;protocol;outboundStream;inboundStream;_rawOutboundStream;_rawInboundStream;_inboundAbortController;closed;log;constructor(t,e){super(),this.log=t.logger.forComponent("libp2p-pubsub:peer-streams"),this.id=e.id,this.protocol=e.protocol,this._inboundAbortController=new AbortController,this.closed=!1}get isReadable(){return!!this.inboundStream}get isWritable(){return!!this.outboundStream}write(t){if(this.outboundStream==null){let e=this.id.toString();throw new Error("No writable connection to "+e)}this.outboundStream.push(t instanceof Uint8Array?new ot(t):t)}attachInboundStream(t,e){let n=()=>{Mi(t.source,this.log)};return this._inboundAbortController.signal.addEventListener("abort",n,{once:!0}),this._rawInboundStream=t,this.inboundStream=ir(this._rawInboundStream,o=>hr(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=zr({onEnd:n=>{this._rawOutboundStream?.closeWrite().catch(o=>{this.log("error closing outbound stream",o)}),this._rawOutboundStream=void 0,this.outboundStream=void 0,n!=null&&this.dispatchEvent(new CustomEvent("close"))}}),ir(this.outboundStream,n=>Xr(n),this._rawOutboundStream).catch(n=>{this.log.error(n)}),e==null&&this.dispatchEvent(new CustomEvent("stream:outbound")),this.outboundStream}close(){this.closed||(this.closed=!0,this.outboundStream!=null&&this.outboundStream.end(),this.inboundStream!=null&&this._inboundAbortController.abort(),this._rawOutboundStream=void 0,this.outboundStream=void 0,this._rawInboundStream=void 0,this.inboundStream=void 0,this.dispatchEvent(new CustomEvent("close")))}};function Hi(){return BigInt(`0x${j(Ur(8),"base16")}`)}var Vi=(r,t)=>{let e=G(t.toString(16).padStart(16,"0"),"base16"),n=Ut(r),o=new Uint8Array(n.byteLength+e.length);return o.set(n,0),o.set(e,n.byteLength),o},zi=r=>oe.encode(r);var Fi=function(r){return Array.isArray(r)?r:[r]},hf=async r=>{if(r.sequenceNumber==null||r.from==null||r.signature==null)return!1;let t=nr(Ft(r.from));if(t.publicKey!=null)return!0;if(r.key!=null){let e=r.key;return No(Do(e)).equals(t)}return!1},Gi=async r=>{if(r.from==null)throw new tt("RPC message was missing from");if(!await hf(r))return{type:"unsigned",topic:r.topic??"",data:r.data??new Uint8Array(0)};let t=nr(Ft(r.from)),e=r.key??t.publicKey;if(e==null)throw new tt("RPC message was missing public key");return{type:"signed",from:t,topic:r.topic??"",sequenceNumber:pf(r.sequenceNumber??new Uint8Array(0)),data:r.data??new Uint8Array(0),signature:r.signature??new Uint8Array(0),key:e instanceof Uint8Array?Do(e):e}},dr=r=>r.type==="signed"?{from:r.from.toMultihash().bytes,data:r.data,sequenceNumber:df(r.sequenceNumber),topic:r.topic,signature:r.signature,key:r.key?Ut(r.key):void 0}:{data:r.data,topic:r.topic},df=r=>{let t=r.toString(16);return t.length%2!==0&&(t=`0${t}`),G(t,"base16")},pf=r=>BigInt(`0x${j(r,"base16")}`);var ji=G("libp2p-pubsub:");async function Zi(r,t,e){let n={type:"signed",topic:t.topic,data:t.data,sequenceNumber:t.sequenceNumber,from:_i(r)},o=ne([ji,e(dr(n)).subarray()]);return n.signature=await r.sign(o),n.key=r.publicKey,n}async function Yi(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([ji,t({...dr(r),signature:void 0,key:void 0}).subarray()]);return mf(r).verify(e,r.signature)}function mf(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 zo=class extends ge{log;started;topics;subscriptions;peers;globalSignaturePolicy;canRelayMessage;emitSelf;topicValidators;queue;multicodecs;components;_registrarTopologyIds;enabled;maxInboundStreams;maxOutboundStreams;constructor(t,e){super();let{multicodecs:n=[],globalSignaturePolicy:o="StrictSign",canRelayMessage:s=!1,emitSelf:i=!1,messageProcessingConcurrency:c=10,maxInboundStreams:a=1,maxOutboundStreams:l=1}=e;this.log=t.logger.forComponent("libp2p:pubsub"),this.components=t,this.multicodecs=Fi(n),this.enabled=e.enabled!==!1,this.started=!1,this.topics=new Map,this.subscriptions=new Set,this.peers=new or,this.globalSignaturePolicy=o==="StrictNoSign"?"StrictNoSign":"StrictSign",this.canRelayMessage=s,this.emitSelf=i,this.topicValidators=new Map,this.queue=new fr({concurrency:c}),this.maxInboundStreams=a,this.maxOutboundStreams=l,this._onIncomingStream=this._onIncomingStream.bind(this),this._onPeerConnected=this._onPeerConnected.bind(this),this._onPeerDisconnected=this._onPeerDisconnected.bind(this)}async start(){if(this.started||!this.enabled)return;this.log("starting");let t=this.components.registrar;await Promise.all(this.multicodecs.map(async n=>{await t.handle(n,this._onIncomingStream,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams})}));let e={onConnect:this._onPeerConnected,onDisconnect:this._onPeerDisconnected};this._registrarTopologyIds=await Promise.all(this.multicodecs.map(async n=>t.register(n,e))),this.log("started"),this.started=!0}async stop(){if(!this.started||!this.enabled)return;let t=this.components.registrar;this._registrarTopologyIds!=null&&this._registrarTopologyIds?.forEach(e=>{t.unregister(e)}),await Promise.all(this.multicodecs.map(async e=>{await t.unhandle(e)})),this.log("stopping");for(let e of this.peers.values())e.close();this.peers.clear(),this.subscriptions=new Set,this.started=!1,this.log("stopped")}isStarted(){return this.started}_onIncomingStream(t){let{stream:e,connection:n}=t,o=n.remotePeer;if(e.protocol==null){e.abort(new Error("Stream was not multiplexed"));return}let s=this.addPeer(o,e.protocol),i=s.attachInboundStream(e);this.processMessages(o,i,s).catch(c=>{this.log(c)})}_onPeerConnected(t,e){if(this.log("connected %p",t),e.streams.find(n=>n.direction==="outbound"&&n.protocol!=null&&this.multicodecs.includes(n.protocol))!=null){this.log("outbound pubsub streams already present on connection from %p",t);return}Promise.resolve().then(async()=>{try{let n=await e.newStream(this.multicodecs);if(n.protocol==null){n.abort(new Error("Stream was not multiplexed"));return}await this.addPeer(t,n.protocol).attachOutboundStream(n)}catch(n){this.log.error(n)}this.send(t,{subscriptions:Array.from(this.subscriptions).map(n=>n.toString()),subscribe:!0})}).catch(n=>{this.log.error(n)})}_onPeerDisconnected(t,e){this.log("connection ended %p",t),this._removePeer(t)}addPeer(t,e){let n=this.peers.get(t);if(n!=null)return n;this.log("new peer %p",t);let o=new Jr(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 ir(e,async o=>{for await(let s of o){let i=this.decodeRpc(s),c=[];for(let a of i.messages??[]){if(a.from==null||a.data==null||a.topic==null){this.log("message from %p was missing from, data or topic fields, dropping",t);continue}c.push({from:a.from,data:a.data,topic:a.topic,sequenceNumber:a.sequenceNumber??void 0,signature:a.signature??void 0,key:a.key??void 0})}this.processRpc(t,n,{subscriptions:(i.subscriptions??[]).map(a=>({subscribe:!!a.subscribe,topic:a.topic??""})),messages:c}).catch(a=>{this.log(a)})}})}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:c})=>({topic:`${i??""}`,subscribe:!!c}))}}))),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 c=await Gi(i);await this.processMessage(t,c)}catch(c){this.log.error(c)}})).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 sr,this.topics.set(n,o)),e.subscribe===!0?o.add(t):o.delete(t)}async processMessage(t,e){if(!(this.components.peerId.equals(t)&&!this.emitSelf)){try{await this.validate(t,e)}catch(n){this.log("Message is invalid, dropping it. %O",n);return}this.subscriptions.has(e.topic)&&(!this.components.peerId.equals(t)||this.emitSelf)&&super.dispatchEvent(new CustomEvent("message",{detail:e})),await this.publishMessage(t,e)}}getMsgId(t){switch(this.globalSignaturePolicy){case"StrictSign":if(t.type!=="signed")throw new tt('Message type should be "signed" when signature policy is StrictSign but it was not');if(t.sequenceNumber==null)throw new tt("Need sequence number when signature policy is StrictSign but it was missing");if(t.key==null)throw new tt("Need key when signature policy is StrictSign but it was missing");return Vi(t.key,t.sequenceNumber);case"StrictNoSign":return zi(t.data);default:throw new tt("Cannot get message id: unhandled signature policy")}}acceptFrom(t){return!0}send(t,e){let{messages:n,subscriptions:o,subscribe:s}=e;this.sendRpc(t,{subscriptions:(o??[]).map(i=>({topic:i,subscribe:!!s})),messages:(n??[]).map(dr)})}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 tt('Message type should be "unsigned" when signature policy is StrictNoSign but it was not');if(e.signature!=null)throw new tt("StrictNoSigning: signature should not be present");if(e.key!=null)throw new tt("StrictNoSigning: key should not be present");if(e.sequenceNumber!=null)throw new tt("StrictNoSigning: seqno should not be present");break;case"StrictSign":if(e.type!=="signed")throw new tt('Message type should be "signed" when signature policy is StrictSign but it was not');if(e.signature==null)throw new tt("StrictSigning: Signing required and no signature was present");if(e.sequenceNumber==null)throw new tt("StrictSigning: Signing required and no sequenceNumber was present");if(!await Yi(e,this.encodeMessage.bind(this)))throw new tt("StrictSigning: Invalid message signature");break;default:throw new tt("Cannot validate message: unhandled signature policy")}let o=this.topicValidators.get(e.topic);if(o!=null){let s=await o(t,e);if(s===ke.Reject||s===ke.Ignore)throw new tt("Message validation failed")}}async buildMessage(t){switch(this.globalSignaturePolicy){case"StrictSign":return Zi(this.components.privateKey,t,this.encodeMessage.bind(this));case"StrictNoSign":return Promise.resolve({type:"unsigned",...t});default:throw new tt("Cannot build message: unhandled signature policy")}}getSubscribers(t){if(!this.started)throw new yr("not started yet");if(t==null)throw new W("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:Hi()};this.log("publish topic: %s from: %p data: %m",t,n.from,n.data);let o=await this.buildMessage(n),s=!1;this.emitSelf&&this.subscriptions.has(t)&&(s=!0,super.dispatchEvent(new CustomEvent("message",{detail:o})));let i=await this.publishMessage(this.components.peerId,o);return s&&(i.recipients=[...i.recipients,this.components.peerId]),i}subscribe(t){if(!this.started)throw new Error("Pubsub has not started");if(this.log("subscribe to topic: %s",t),!this.subscriptions.has(t)){this.subscriptions.add(t);for(let e of this.peers.keys())this.send(e,{subscriptions:[t],subscribe:!0})}}unsubscribe(t){if(!this.started)throw new Error("Pubsub is not started");super.removeEventListener(t);let e=this.subscriptions.has(t);if(this.log("unsubscribe from %s - am subscribed %s",t,e),e){this.subscriptions.delete(t);for(let n of this.peers.keys())this.send(n,{subscriptions:[t],subscribe:!1})}}getTopics(){if(!this.started)throw new Error("Pubsub is not started");return Array.from(this.subscriptions)}getPeers(){if(!this.started)throw new Error("Pubsub is not started");return Array.from(this.peers.keys())}};return ia(yf);})();
|
2
|
+
"use strict";var Libp2PPubsub=(()=>{var ba=Object.create;var wr=Object.defineProperty;var ga=Object.getOwnPropertyDescriptor;var xa=Object.getOwnPropertyNames;var wa=Object.getPrototypeOf,Ea=Object.prototype.hasOwnProperty;var Sa=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),gt=(r,t)=>{for(var e in t)wr(r,e,{get:t[e],enumerable:!0})},ts=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of xa(t))!Ea.call(r,o)&&o!==e&&wr(r,o,{get:()=>t[o],enumerable:!(n=ga(t,o))||n.enumerable});return r};var va=(r,t,e)=>(e=r!=null?ba(wa(r)):{},ts(t||!r||!r.__esModule?wr(e,"default",{value:r,enumerable:!0}):e,r)),Aa=r=>ts(wr({},"__esModule",{value:!0}),r);var Ji=Sa((z0,jo)=>{"use strict";var of=Object.prototype.hasOwnProperty,yt="~";function dr(){}Object.create&&(dr.prototype=Object.create(null),new dr().__proto__||(yt=!1));function sf(r,t,e){this.fn=r,this.context=t,this.once=e||!1}function Xi(r,t,e,n,o){if(typeof e!="function")throw new TypeError("The listener must be a function");var s=new sf(e,n||r,o),i=yt?yt+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 tn(r,t){--r._eventsCount===0?r._events=new dr:delete r._events[t]}function dt(){this._events=new dr,this._eventsCount=0}dt.prototype.eventNames=function(){var t=[],e,n;if(this._eventsCount===0)return t;for(n in e=this._events)of.call(e,n)&&t.push(yt?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(e)):t};dt.prototype.listeners=function(t){var e=yt?yt+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};dt.prototype.listenerCount=function(t){var e=yt?yt+t:t,n=this._events[e];return n?n.fn?1:n.length:0};dt.prototype.emit=function(t,e,n,o,s,i){var c=yt?yt+t:t;if(!this._events[c])return!1;var a=this._events[c],l=arguments.length,u,f;if(a.fn){switch(a.once&&this.removeListener(t,a.fn,void 0,!0),l){case 1:return a.fn.call(a.context),!0;case 2:return a.fn.call(a.context,e),!0;case 3:return a.fn.call(a.context,e,n),!0;case 4:return a.fn.call(a.context,e,n,o),!0;case 5:return a.fn.call(a.context,e,n,o,s),!0;case 6:return a.fn.call(a.context,e,n,o,s,i),!0}for(f=1,u=new Array(l-1);f<l;f++)u[f-1]=arguments[f];a.fn.apply(a.context,u)}else{var d=a.length,x;for(f=0;f<d;f++)switch(a[f].once&&this.removeListener(t,a[f].fn,void 0,!0),l){case 1:a[f].fn.call(a[f].context);break;case 2:a[f].fn.call(a[f].context,e);break;case 3:a[f].fn.call(a[f].context,e,n);break;case 4:a[f].fn.call(a[f].context,e,n,o);break;default:if(!u)for(x=1,u=new Array(l-1);x<l;x++)u[x-1]=arguments[x];a[f].fn.apply(a[f].context,u)}}return!0};dt.prototype.on=function(t,e,n){return Xi(this,t,e,n,!1)};dt.prototype.once=function(t,e,n){return Xi(this,t,e,n,!0)};dt.prototype.removeListener=function(t,e,n,o){var s=yt?yt+t:t;if(!this._events[s])return this;if(!e)return tn(this,s),this;var i=this._events[s];if(i.fn)i.fn===e&&(!o||i.once)&&(!n||i.context===n)&&tn(this,s);else{for(var c=0,a=[],l=i.length;c<l;c++)(i[c].fn!==e||o&&!i[c].once||n&&i[c].context!==n)&&a.push(i[c]);a.length?this._events[s]=a.length===1?a[0]:a:tn(this,s)}return this};dt.prototype.removeAllListeners=function(t){var e;return t?(e=yt?yt+t:t,this._events[e]&&tn(this,e)):(this._events=new dr,this._eventsCount=0),this};dt.prototype.off=dt.prototype.removeListener;dt.prototype.addListener=dt.prototype.on;dt.prefixed=yt;dt.EventEmitter=dt;typeof jo<"u"&&(jo.exports=dt)});var df={};gt(df,{PubSubBaseProtocol:()=>Jo});var un=Symbol.for("@libp2p/peer-id");var qe;(function(r){r.Accept="accept",r.Ignore="ignore",r.Reject="reject"})(qe||(qe={}));var yf=Symbol.for("@libp2p/pubsub");var Z=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Ee=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Er=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 Sr=class extends Error{static name="NotStartedError";constructor(t="Not started"){super(t),this.name="NotStartedError"}};var oe=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Se=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 pn={};gt(pn,{base58btc:()=>Y,base58flickr:()=>Pa});var wf=new Uint8Array(0);function es(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Nt(r){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 rs(r){return new TextEncoder().encode(r)}function ns(r){return new TextDecoder().decode(r)}function Ia(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var c=r.length,a=r.charAt(0),l=Math.log(c)/Math.log(256),u=Math.log(256)/Math.log(c);function f(E){if(E instanceof Uint8Array||(ArrayBuffer.isView(E)?E=new Uint8Array(E.buffer,E.byteOffset,E.byteLength):Array.isArray(E)&&(E=Uint8Array.from(E))),!(E instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(E.length===0)return"";for(var y=0,h=0,b=0,v=E.length;b!==v&&E[b]===0;)b++,y++;for(var p=(v-b)*u+1>>>0,I=new Uint8Array(p);b!==v;){for(var C=E[b],D=0,_=p-1;(C!==0||D<h)&&_!==-1;_--,D++)C+=256*I[_]>>>0,I[_]=C%c>>>0,C=C/c>>>0;if(C!==0)throw new Error("Non-zero carry");h=D,b++}for(var L=p-h;L!==p&&I[L]===0;)L++;for(var T=a.repeat(y);L<p;++L)T+=r.charAt(I[L]);return T}function d(E){if(typeof E!="string")throw new TypeError("Expected String");if(E.length===0)return new Uint8Array;var y=0;if(E[y]!==" "){for(var h=0,b=0;E[y]===a;)h++,y++;for(var v=(E.length-y)*l+1>>>0,p=new Uint8Array(v);E[y];){var I=e[E.charCodeAt(y)];if(I===255)return;for(var C=0,D=v-1;(I!==0||C<b)&&D!==-1;D--,C++)I+=c*p[D]>>>0,p[D]=I%256>>>0,I=I/256>>>0;if(I!==0)throw new Error("Non-zero carry");b=C,y++}if(E[y]!==" "){for(var _=v-b;_!==v&&p[_]===0;)_++;for(var L=new Uint8Array(h+(v-_)),T=h;_!==v;)L[T++]=p[_++];return L}}}function x(E){var y=d(E);if(y)return y;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:d,decode:x}}var Ba=Ia,_a=Ba,ss=_a;var fn=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")}},ln=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 is(this,t)}},hn=class{decoders;constructor(t){this.decoders=t}or(t){return is(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 is(r,t){return new hn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var dn=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 fn(t,e,n),this.decoder=new ln(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ve({name:r,prefix:t,encode:e,decode:n}){return new dn(r,t,e,n)}function Zt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=ss(e,r);return ve({prefix:t,name:r,encode:n,decode:s=>Nt(o(s))})}function La(r,t,e,n){let o={};for(let u=0;u<t.length;++u)o[t[u]]=u;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*e/8|0),c=0,a=0,l=0;for(let u=0;u<s;++u){let f=o[r[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|f,c+=e,c>=8&&(c-=8,i[l++]=255&a>>c)}if(c>=e||(255&a<<8-c)!==0)throw new SyntaxError("Unexpected end of data");return i}function Ta(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,c=0;for(let a=0;a<r.length;++a)for(c=c<<8|r[a],i+=8;i>e;)i-=e,s+=t[o&c>>i];if(i!==0&&(s+=t[o&c<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function $({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return ve({prefix:t,name:r,encode(o){return Ta(o,n,e)},decode(o){return La(o,n,e,r)}})}var Y=Zt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Pa=Zt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var mn={};gt(mn,{base32:()=>Ae,base32hex:()=>Na,base32hexpad:()=>Ka,base32hexpadupper:()=>ka,base32hexupper:()=>Ua,base32pad:()=>Da,base32padupper:()=>Ra,base32upper:()=>Ca,base32z:()=>Oa});var Ae=$({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ca=$({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Da=$({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ra=$({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Na=$({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ua=$({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ka=$({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ka=$({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Oa=$({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var yn={};gt(yn,{base36:()=>He,base36upper:()=>Ma});var He=Zt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Ma=Zt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var qa=us,as=128,Ha=127,Va=~Ha,za=Math.pow(2,31);function us(r,t,e){t=t||[],e=e||0;for(var n=e;r>=za;)t[e++]=r&255|as,r/=128;for(;r&Va;)t[e++]=r&255|as,r>>>=7;return t[e]=r|0,us.bytes=e-n+1,t}var Fa=bn,Ga=128,cs=127;function bn(r,n){var e=0,n=n||0,o=0,s=n,i,c=r.length;do{if(s>=c)throw bn.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&cs)<<o:(i&cs)*Math.pow(2,o),o+=7}while(i>=Ga);return bn.bytes=s-n,e}var ja=Math.pow(2,7),Za=Math.pow(2,14),Ya=Math.pow(2,21),Wa=Math.pow(2,28),$a=Math.pow(2,35),Xa=Math.pow(2,42),Ja=Math.pow(2,49),Qa=Math.pow(2,56),tc=Math.pow(2,63),ec=function(r){return r<ja?1:r<Za?2:r<Ya?3:r<Wa?4:r<$a?5:r<Xa?6:r<Ja?7:r<Qa?8:r<tc?9:10},rc={encode:qa,decode:Fa,encodingLength:ec},nc=rc,Ve=nc;function ze(r,t=0){return[Ve.decode(r,t),Ve.decode.bytes]}function Ie(r,t,e=0){return Ve.encode(r,t,e),t}function Be(r){return Ve.encodingLength(r)}function It(r,t){let e=t.byteLength,n=Be(r),o=n+Be(e),s=new Uint8Array(o+e);return Ie(r,s,0),Ie(e,s,n),s.set(t,o),new _e(r,e,t,s)}function Yt(r){let t=Nt(r),[e,n]=ze(t),[o,s]=ze(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new _e(e,o,i,t)}function fs(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&es(r.bytes,e.bytes)}}var _e=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function ls(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return sc(e,gn(r),t??Y.encoder);default:return ic(e,gn(r),t??Ae.encoder)}}var hs=new WeakMap;function gn(r){let t=hs.get(r);if(t==null){let e=new Map;return hs.set(r,e),e}return t}var ut=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==Fe)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==ac)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=It(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&&fs(t.multihash,n.multihash)}toString(t){return ls(this,t)}toJSON(){return{"/":ls(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??ds(n,o,s.bytes))}else if(e[cc]===!0){let{version:n,multihash:o,code:s}=e,i=Yt(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==Fe)throw new Error(`Version 0 CID must use dag-pb (code: ${Fe}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=ds(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Fe,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=Nt(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 _e(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[f,d]=ze(t.subarray(e));return e+=d,f},o=n(),s=Fe;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,c=n(),a=n(),l=e+a,u=l-i;return{version:o,codec:s,multihashCode:c,digestSize:a,multihashSize:u,size:l}}static parse(t,e){let[n,o]=oc(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 gn(s).set(n,t),s}};function oc(r,t){switch(r[0]){case"Q":{let e=t??Y;return[Y.prefix,e.decode(`${Y.prefix}${r}`)]}case Y.prefix:{let e=t??Y;return[Y.prefix,e.decode(r)]}case Ae.prefix:{let e=t??Ae;return[Ae.prefix,e.decode(r)]}case He.prefix:{let e=t??He;return[He.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function sc(r,t,e){let{prefix:n}=e;if(n!==Y.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 ic(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var Fe=112,ac=18;function ds(r,t,e){let n=Be(r),o=n+Be(t),s=new Uint8Array(o+e.byteLength);return Ie(r,s,0),Ie(t,s,n),s.set(e,o),s}var cc=Symbol.for("@ipld/js-cid/CID");var xn={};gt(xn,{identity:()=>Bt});var ps=0,uc="identity",ms=Nt;function fc(r){return It(ps,ms(r))}var Bt={code:ps,name:uc,encode:ms,digest:fc};function xt(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 ft(r=0){return new Uint8Array(r)}function se(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=ft(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var bs=Symbol.for("@achingbrain/uint8arraylist");function ys(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 Ar(r){return!!r?.[bs]}var rt=class r{bufs;length;[bs]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(Ar(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(Ar(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=ys(this.bufs,t);return e.buf[e.index]}set(t,e){let n=ys(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(Ar(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 se(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:se(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=[...n],s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],c=o,a=c+i.byteLength;if(o=a,t>=a)continue;let l=t>=c&&t<a,u=e>c&&e<=a;if(l&&u){if(t===c&&e===a){n.push(i);break}let f=t-c;n.push(i.subarray(f,f+(e-t)));break}if(l){if(t===0){n.push(i);continue}n.push(i.subarray(t-c));continue}if(u){if(e===a){n.push(i);break}n.push(i.subarray(0,e-c));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Ar(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let f=0;f<s;f++)i[f]=-1;for(let f=0;f<o;f++)i[n[f]]=f;let c=i,a=this.byteLength-n.byteLength,l=n.byteLength-1,u;for(let f=e;f<=a;f+=u){u=0;for(let d=l;d>=0;d--){let x=this.get(f+d);if(n[d]!==x){u=Math.max(1,d-c[x]);break}}if(u===0)return f}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=ft(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=ft(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(!xt(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 wn={};gt(wn,{base10:()=>lc});var lc=Zt({prefix:"9",name:"base10",alphabet:"0123456789"});var En={};gt(En,{base16:()=>hc,base16upper:()=>dc});var hc=$({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),dc=$({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Sn={};gt(Sn,{base2:()=>pc});var pc=$({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var vn={};gt(vn,{base256emoji:()=>xc});var gs=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),mc=gs.reduce((r,t,e)=>(r[e]=t,r),[]),yc=gs.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function bc(r){return r.reduce((t,e)=>(t+=mc[e],t),"")}function gc(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=yc[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var xc=ve({prefix:"\u{1F680}",name:"base256emoji",encode:bc,decode:gc});var An={};gt(An,{base64:()=>wc,base64pad:()=>Ec,base64url:()=>Sc,base64urlpad:()=>vc});var wc=$({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ec=$({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Sc=$({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),vc=$({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var In={};gt(In,{base8:()=>Ac});var Ac=$({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Bn={};gt(Bn,{identity:()=>Ic});var Ic=ve({prefix:"\0",name:"identity",encode:r=>ns(r),decode:r=>rs(r)});var nl=new TextEncoder,ol=new TextDecoder;var Tn={};gt(Tn,{sha256:()=>ie,sha512:()=>Lc});function Ln({name:r,code:t,encode:e}){return new _n(r,t,e)}var _n=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?It(this.code,e):e.then(n=>It(this.code,n))}else throw Error("Unknown type, must be binary type")}};function ws(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var ie=Ln({name:"sha2-256",code:18,encode:ws("SHA-256")}),Lc=Ln({name:"sha2-512",code:19,encode:ws("SHA-512")});var Pn={...Bn,...Sn,...In,...wn,...En,...mn,...yn,...pn,...An,...vn},yl={...Tn,...xn};function Ss(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Es=Ss("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Cn=Ss("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=ft(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Tc={utf8:Es,"utf-8":Es,hex:Pn.base16,latin1:Cn,ascii:Cn,binary:Cn,...Pn},Ir=Tc;function F(r,t="utf8"){let e=Ir[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function G(r,t="utf8"){let e=Ir[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Pc=parseInt("11111",2),Dn=parseInt("10000000",2),Cc=parseInt("01111111",2),vs={0:Ge,1:Ge,2:Dc,3:Uc,4:Kc,5:Nc,6:Rc,16:Ge,22:Ge,48:Ge};function Kt(r,t={offset:0}){let e=r[t.offset]&Pc;if(t.offset++,vs[e]!=null)return vs[e](r,t);throw new Error("No decoder for tag "+e)}function je(r,t){let e=0;if((r[t.offset]&Dn)===Dn){let n=r[t.offset]&Cc,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=r[t.offset].toString(16).padStart(2,"0");e=parseInt(o,16)}else e=r[t.offset],t.offset++;return e}function Ge(r,t){je(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=Kt(r,t);if(n===null)break;e.push(n)}return e}function Dc(r,t){let e=je(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 Rc(r,t){let e=je(r,t),n=t.offset+e,o=r[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let c=`${s}.${i}`,a=[];for(;t.offset<n;){let l=r[t.offset];if(t.offset++,a.push(l&127),l<128){a.reverse();let u=0;for(let f=0;f<a.length;f++)u+=a[f]<<f*7;c+=`.${u}`,a=[]}}return c}function Nc(r,t){return t.offset++,null}function Uc(r,t){let e=je(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 Kc(r,t){let e=je(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function kc(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new rt;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function Rn(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=kc(r.byteLength);return new rt(Uint8Array.from([t.byteLength|Dn]),t)}function wt(r){let t=new rt,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new rt(Uint8Array.from([2]),Rn(t),t)}function Br(r){let t=Uint8Array.from([0]),e=new rt(t,r);return new rt(Uint8Array.from([3]),Rn(e),e)}function $t(r,t=48){let e=new rt;for(let n of r)e.append(n);return new rt(Uint8Array.from([t]),Rn(e),e)}async function As(r,t,e){let n=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);return crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},n,t,e.subarray())}var Oc=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Mc=Uint8Array.from([6,5,43,129,4,0,34]),qc=Uint8Array.from([6,5,43,129,4,0,35]),Hc={ext:!0,kty:"EC",crv:"P-256"},Vc={ext:!0,kty:"EC",crv:"P-384"},zc={ext:!0,kty:"EC",crv:"P-521"},Nn=32,Un=48,Kn=66;function kn(r){let t=Kt(r);return Is(t)}function Is(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===Nn*2+1)return n=G(t.subarray(e,e+Nn),"base64url"),o=G(t.subarray(e+Nn),"base64url"),new Le({...Hc,key_ops:["verify"],x:n,y:o});if(t.byteLength===Un*2+1)return n=G(t.subarray(e,e+Un),"base64url"),o=G(t.subarray(e+Un),"base64url"),new Le({...Vc,key_ops:["verify"],x:n,y:o});if(t.byteLength===Kn*2+1)return n=G(t.subarray(e,e+Kn),"base64url"),o=G(t.subarray(e+Kn),"base64url"),new Le({...zc,key_ops:["verify"],x:n,y:o});throw new Z(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Bs(r){return $t([wt(Uint8Array.from([1])),$t([Fc(r.crv)],160),$t([Br(new rt(Uint8Array.from([4]),F(r.x??"","base64url"),F(r.y??"","base64url")))],161)]).subarray()}function Fc(r){if(r==="P-256")return Oc;if(r==="P-384")return Mc;if(r==="P-521")return qc;throw new Z(`Invalid curve ${r}`)}var Le=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Bs(this.jwk)),this._raw}toMultihash(){return Bt.digest(kt(this))}toCID(){return ut.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:xt(this.raw,t.raw)}async verify(t,e){return As(this.jwk,e,t)}};var ae=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Gc(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function _r(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function ce(r,...t){if(!Gc(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 _s(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");_r(r.outputLen),_r(r.blockLen)}function Pe(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 Ls(r,t){ce(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}function Ot(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function Lr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function _t(r,t){return r<<32-t|r>>>t}function Ts(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function Ze(r){return typeof r=="string"&&(r=Ts(r)),ce(r),r}function On(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];ce(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 Te=class{};function Mn(r){let t=n=>r().update(Ze(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function Ce(r=32){if(ae&&typeof ae.getRandomValues=="function")return ae.getRandomValues(new Uint8Array(r));if(ae&&typeof ae.randomBytes=="function")return Uint8Array.from(ae.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function jc(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),c=Number(e&s),a=n?4:0,l=n?0:4;r.setUint32(t+a,i,n),r.setUint32(t+l,c,n)}function Ps(r,t,e){return r&t^~r&e}function Cs(r,t,e){return r&t^r&e^t&e}var Ye=class extends Te{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=Lr(this.buffer)}update(t){Pe(this),t=Ze(t),ce(t);let{view:e,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let a=Lr(t);for(;o<=s-i;i+=o)this.process(a,i);continue}n.set(t.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Pe(this),Ls(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,Ot(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let f=i;f<o;f++)e[f]=0;jc(n,o-8,BigInt(this.length*8),s),this.process(n,0);let c=Lr(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let l=a/4,u=this.get();if(l>u.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<l;f++)c.setUint32(4*f,u[f],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:n,length:o,finished:s,destroyed:i,pos:c}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=c,o%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Mt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var at=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Tr=BigInt(4294967295),Ds=BigInt(32);function Zc(r,t=!1){return t?{h:Number(r&Tr),l:Number(r>>Ds&Tr)}:{h:Number(r>>Ds&Tr)|0,l:Number(r&Tr)|0}}function Rs(r,t=!1){let e=r.length,n=new Uint32Array(e),o=new Uint32Array(e);for(let s=0;s<e;s++){let{h:i,l:c}=Zc(r[s],t);[n[s],o[s]]=[i,c]}return[n,o]}var qn=(r,t,e)=>r>>>e,Hn=(r,t,e)=>r<<32-e|t>>>e,ue=(r,t,e)=>r>>>e|t<<32-e,fe=(r,t,e)=>r<<32-e|t>>>e,We=(r,t,e)=>r<<64-e|t>>>e-32,$e=(r,t,e)=>r>>>e-32|t<<64-e;function Pt(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var Ns=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Us=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Ks=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),ks=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Os=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Ms=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var Wc=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]),Xt=new Uint32Array(64),Pr=class extends Ye{constructor(t=32){super(64,t,8,!1),this.A=Mt[0]|0,this.B=Mt[1]|0,this.C=Mt[2]|0,this.D=Mt[3]|0,this.E=Mt[4]|0,this.F=Mt[5]|0,this.G=Mt[6]|0,this.H=Mt[7]|0}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:c,H:a}=this;return[t,e,n,o,s,i,c,a]}set(t,e,n,o,s,i,c,a){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=c|0,this.H=a|0}process(t,e){for(let f=0;f<16;f++,e+=4)Xt[f]=t.getUint32(e,!1);for(let f=16;f<64;f++){let d=Xt[f-15],x=Xt[f-2],E=_t(d,7)^_t(d,18)^d>>>3,y=_t(x,17)^_t(x,19)^x>>>10;Xt[f]=y+Xt[f-7]+E+Xt[f-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:a,G:l,H:u}=this;for(let f=0;f<64;f++){let d=_t(c,6)^_t(c,11)^_t(c,25),x=u+d+Ps(c,a,l)+Wc[f]+Xt[f]|0,y=(_t(n,2)^_t(n,13)^_t(n,22))+Cs(n,o,s)|0;u=l,l=a,a=c,c=i+x|0,i=s,s=o,o=n,n=x+y|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,a=a+this.F|0,l=l+this.G|0,u=u+this.H|0,this.set(n,o,s,i,c,a,l,u)}roundClean(){Ot(Xt)}destroy(){this.set(0,0,0,0,0,0,0,0),Ot(this.buffer)}};var qs=Rs(["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))),$c=qs[0],Xc=qs[1],Jt=new Uint32Array(80),Qt=new Uint32Array(80),Vn=class extends Ye{constructor(t=64){super(128,t,16,!1),this.Ah=at[0]|0,this.Al=at[1]|0,this.Bh=at[2]|0,this.Bl=at[3]|0,this.Ch=at[4]|0,this.Cl=at[5]|0,this.Dh=at[6]|0,this.Dl=at[7]|0,this.Eh=at[8]|0,this.El=at[9]|0,this.Fh=at[10]|0,this.Fl=at[11]|0,this.Gh=at[12]|0,this.Gl=at[13]|0,this.Hh=at[14]|0,this.Hl=at[15]|0}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:c,Dl:a,Eh:l,El:u,Fh:f,Fl:d,Gh:x,Gl:E,Hh:y,Hl:h}=this;return[t,e,n,o,s,i,c,a,l,u,f,d,x,E,y,h]}set(t,e,n,o,s,i,c,a,l,u,f,d,x,E,y,h){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=c|0,this.Dl=a|0,this.Eh=l|0,this.El=u|0,this.Fh=f|0,this.Fl=d|0,this.Gh=x|0,this.Gl=E|0,this.Hh=y|0,this.Hl=h|0}process(t,e){for(let p=0;p<16;p++,e+=4)Jt[p]=t.getUint32(e),Qt[p]=t.getUint32(e+=4);for(let p=16;p<80;p++){let I=Jt[p-15]|0,C=Qt[p-15]|0,D=ue(I,C,1)^ue(I,C,8)^qn(I,C,7),_=fe(I,C,1)^fe(I,C,8)^Hn(I,C,7),L=Jt[p-2]|0,T=Qt[p-2]|0,z=ue(L,T,19)^We(L,T,61)^qn(L,T,6),M=fe(L,T,19)^$e(L,T,61)^Hn(L,T,6),U=Ks(_,M,Qt[p-7],Qt[p-16]),et=ks(U,D,z,Jt[p-7],Jt[p-16]);Jt[p]=et|0,Qt[p]=U|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:l,Dl:u,Eh:f,El:d,Fh:x,Fl:E,Gh:y,Gl:h,Hh:b,Hl:v}=this;for(let p=0;p<80;p++){let I=ue(f,d,14)^ue(f,d,18)^We(f,d,41),C=fe(f,d,14)^fe(f,d,18)^$e(f,d,41),D=f&x^~f&y,_=d&E^~d&h,L=Os(v,C,_,Xc[p],Qt[p]),T=Ms(L,b,I,D,$c[p],Jt[p]),z=L|0,M=ue(n,o,28)^We(n,o,34)^We(n,o,39),U=fe(n,o,28)^$e(n,o,34)^$e(n,o,39),et=n&s^n&c^s&c,S=o&i^o&a^i&a;b=y|0,v=h|0,y=x|0,h=E|0,x=f|0,E=d|0,{h:f,l:d}=Pt(l|0,u|0,T|0,z|0),l=c|0,u=a|0,c=s|0,a=i|0,s=n|0,i=o|0;let B=Ns(z,U,S);n=Us(B,T,M,et),o=B|0}({h:n,l:o}=Pt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Pt(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:a}=Pt(this.Ch|0,this.Cl|0,c|0,a|0),{h:l,l:u}=Pt(this.Dh|0,this.Dl|0,l|0,u|0),{h:f,l:d}=Pt(this.Eh|0,this.El|0,f|0,d|0),{h:x,l:E}=Pt(this.Fh|0,this.Fl|0,x|0,E|0),{h:y,l:h}=Pt(this.Gh|0,this.Gl|0,y|0,h|0),{h:b,l:v}=Pt(this.Hh|0,this.Hl|0,b|0,v|0),this.set(n,o,s,i,c,a,l,u,f,d,x,E,y,h,b,v)}roundClean(){Ot(Jt,Qt)}destroy(){Ot(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Cr=Mn(()=>new Pr);var Hs=Mn(()=>new Vn);var jn=BigInt(0),Gn=BigInt(1);function le(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Zn(r){if(!le(r))throw new Error("Uint8Array expected")}function Ct(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}function Xe(r){let t=r.toString(16);return t.length&1?"0"+t:t}function Fs(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?jn:BigInt("0x"+r)}var Gs=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Jc=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function te(r){if(Zn(r),Gs)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=Jc[r[e]];return t}var qt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Vs(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 Je(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(Gs)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=Vs(r.charCodeAt(s)),c=Vs(r.charCodeAt(s+1));if(i===void 0||c===void 0){let a=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+s)}n[o]=i*16+c}return n}function Ht(r){return Fs(te(r))}function he(r){return Zn(r),Fs(te(Uint8Array.from(r).reverse()))}function de(r,t){return Je(r.toString(16).padStart(t*2,"0"))}function De(r,t){return de(r,t).reverse()}function W(r,t,e){let n;if(typeof t=="string")try{n=Je(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(le(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 ee(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];Zn(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 zn=r=>typeof r=="bigint"&&jn<=r;function Dr(r,t,e){return zn(r)&&zn(t)&&zn(e)&&t<=r&&r<e}function St(r,t,e,n){if(!Dr(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function js(r){let t;for(t=0;r>jn;r>>=Gn,t+=1);return t}var pe=r=>(Gn<<BigInt(r))-Gn,Fn=r=>new Uint8Array(r),zs=r=>Uint8Array.from(r);function Zs(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=Fn(r),o=Fn(r),s=0,i=()=>{n.fill(1),o.fill(0),s=0},c=(...f)=>e(o,n,...f),a=(f=Fn(0))=>{o=c(zs([0]),f),n=c(),f.length!==0&&(o=c(zs([1]),f),n=c())},l=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,d=[];for(;f<t;){n=c();let x=n.slice();d.push(x),f+=n.length}return ee(...d)};return(f,d)=>{i(),a(f);let x;for(;!(x=d(l()));)a();return i(),x}}var Qc={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||le(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,t)=>t.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function Vt(r,t,e={}){let n=(o,s,i)=>{let c=Qc[s];if(typeof c!="function")throw new Error("invalid validator function");let a=r[o];if(!(i&&a===void 0)&&!c(a,r))throw new Error("param "+String(o)+" is invalid. Expected "+s+", got "+a)};for(let[o,s]of Object.entries(t))n(o,s,!1);for(let[o,s]of Object.entries(e))n(o,s,!0);return r}function Re(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 pt=BigInt(0),nt=BigInt(1),me=BigInt(2),tu=BigInt(3),Yn=BigInt(4),Ys=BigInt(5),Ws=BigInt(8),eu=BigInt(9),ru=BigInt(16);function V(r,t){let e=r%t;return e>=pt?e:t+e}function j(r,t,e){let n=r;for(;t-- >pt;)n*=n,n%=e;return n}function Rr(r,t){if(r===pt)throw new Error("invert: expected non-zero number");if(t<=pt)throw new Error("invert: expected positive modulus, got "+t);let e=V(r,t),n=t,o=pt,s=nt,i=nt,c=pt;for(;e!==pt;){let l=n/e,u=n%e,f=o-i*l,d=s-c*l;n=e,e=u,o=i,s=c,i=f,c=d}if(n!==nt)throw new Error("invert: does not exist");return V(o,t)}function nu(r){let t=r-nt,e=0;for(;t%me===pt;)t/=me,e++;let n=me,o=zt(r);for(;n<r&&$s(o,n);)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1){let i=(r+nt)/Yn;return function(a,l){let u=a.pow(l,i);if(!a.eql(a.sqr(u),l))throw new Error("Cannot find square root");return u}}let s=(t+nt)/me;return function(c,a){if(!$s(c,a))throw new Error("Cannot find square root");let l=e,u=c.pow(c.mul(c.ONE,n),t),f=c.pow(a,s),d=c.pow(a,t);for(;!c.eql(d,c.ONE);){if(c.eql(d,c.ZERO))return c.ZERO;let x=1;for(let y=c.sqr(d);x<l&&!c.eql(y,c.ONE);x++)y=c.sqr(y);let E=c.pow(u,nt<<BigInt(l-x-1));u=c.sqr(E),f=c.mul(f,E),d=c.mul(d,u),l=x}return f}}function ou(r){return r%Yn===tu?function(e,n){let o=(r+nt)/Yn,s=e.pow(n,o);if(!e.eql(e.sqr(s),n))throw new Error("Cannot find square root");return s}:r%Ws===Ys?function(e,n){let o=e.mul(n,me),s=(r-Ys)/Ws,i=e.pow(o,s),c=e.mul(n,i),a=e.mul(e.mul(c,me),i),l=e.mul(c,e.sub(a,e.ONE));if(!e.eql(e.sqr(l),n))throw new Error("Cannot find square root");return l}:(r%ru,nu(r))}var Xs=(r,t)=>(V(r,t)&nt)===nt,su=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Wn(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=su.reduce((n,o)=>(n[o]="function",n),t);return Vt(r,e)}function iu(r,t,e){if(e<pt)throw new Error("invalid exponent, negatives unsupported");if(e===pt)return r.ONE;if(e===nt)return t;let n=r.ONE,o=t;for(;e>pt;)e&nt&&(n=r.mul(n,o)),o=r.sqr(o),e>>=nt;return n}function Ne(r,t,e=!1){let n=new Array(t.length).fill(e?r.ZERO:void 0),o=t.reduce((i,c,a)=>r.is0(c)?i:(n[a]=i,r.mul(i,c)),r.ONE),s=r.inv(o);return t.reduceRight((i,c,a)=>r.is0(c)?i:(n[a]=r.mul(i,n[a]),r.mul(i,c)),s),n}function au(r,t){let e=(r.ORDER-nt)/me,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("Cannot find square root: probably non-prime P");return o?1:s?0:-1}function $s(r,t){let e=au(r,t);return e===0||e===1}function $n(r,t){t!==void 0&&_r(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function zt(r,t,e=!1,n={}){if(r<=pt)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:o,nByteLength:s}=$n(r,t);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let i,c=Object.freeze({ORDER:r,isLE:e,BITS:o,BYTES:s,MASK:pe(o),ZERO:pt,ONE:nt,create:a=>V(a,r),isValid:a=>{if(typeof a!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof a);return pt<=a&&a<r},is0:a=>a===pt,isOdd:a=>(a&nt)===nt,neg:a=>V(-a,r),eql:(a,l)=>a===l,sqr:a=>V(a*a,r),add:(a,l)=>V(a+l,r),sub:(a,l)=>V(a-l,r),mul:(a,l)=>V(a*l,r),pow:(a,l)=>iu(c,a,l),div:(a,l)=>V(a*Rr(l,r),r),sqrN:a=>a*a,addN:(a,l)=>a+l,subN:(a,l)=>a-l,mulN:(a,l)=>a*l,inv:a=>Rr(a,r),sqrt:n.sqrt||(a=>(i||(i=ou(r)),i(c,a))),toBytes:a=>e?De(a,s):de(a,s),fromBytes:a=>{if(a.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+a.length);return e?he(a):Ht(a)},invertBatch:a=>Ne(c,a),cmov:(a,l,u)=>u?l:a});return Object.freeze(c)}function Js(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 Xn(r){let t=Js(r);return t+Math.ceil(t/2)}function Qs(r,t,e=!1){let n=r.length,o=Js(t),s=Xn(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?he(r):Ht(r),c=V(i,t-nt)+nt;return e?De(c,o):de(c,o)}var ti=BigInt(0),ro=BigInt(1);function Jn(r,t){let e=t.negate();return r?e:t}function ri(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function Qn(r,t){ri(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=pe(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function ei(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,c=Number(r&o),a=r>>i;c>n&&(c-=s,a+=ro);let l=t*n,u=l+Math.abs(c)-1,f=c===0,d=c<0,x=t%2!==0;return{nextN:a,offset:u,isZero:f,isNeg:d,isNegF:x,offsetF:l}}function cu(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 uu(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 to=new WeakMap,ni=new WeakMap;function eo(r){return ni.get(r)||1}function Nr(r,t){return{constTimeNegate:Jn,hasPrecomputes(e){return eo(e)!==1},unsafeLadder(e,n,o=r.ZERO){let s=e;for(;n>ti;)n&ro&&(o=o.add(s)),s=s.double(),n>>=ro;return o},precomputeWindow(e,n){let{windows:o,windowSize:s}=Qn(n,t),i=[],c=e,a=c;for(let l=0;l<o;l++){a=c,i.push(a);for(let u=1;u<s;u++)a=a.add(c),i.push(a);c=a.double()}return i},wNAF(e,n,o){let s=r.ZERO,i=r.BASE,c=Qn(e,t);for(let a=0;a<c.windows;a++){let{nextN:l,offset:u,isZero:f,isNeg:d,isNegF:x,offsetF:E}=ei(o,a,c);o=l,f?i=i.add(Jn(x,n[E])):s=s.add(Jn(d,n[u]))}return{p:s,f:i}},wNAFUnsafe(e,n,o,s=r.ZERO){let i=Qn(e,t);for(let c=0;c<i.windows&&o!==ti;c++){let{nextN:a,offset:l,isZero:u,isNeg:f}=ei(o,c,i);if(o=a,!u){let d=n[l];s=s.add(f?d.negate():d)}}return s},getPrecomputes(e,n,o){let s=to.get(n);return s||(s=this.precomputeWindow(n,e),e!==1&&to.set(n,o(s))),s},wNAFCached(e,n,o){let s=eo(e);return this.wNAF(s,this.getPrecomputes(s,e,o),n)},wNAFCachedUnsafe(e,n,o,s){let i=eo(e);return i===1?this.unsafeLadder(e,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,e,o),n,s)},setWindowSize(e,n){ri(n,t),ni.set(e,n),to.delete(e)}}}function Ur(r,t,e,n){if(cu(e,r),uu(n,t),e.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let o=r.ZERO,s=js(BigInt(e.length)),i=s>12?s-3:s>4?s-2:s?2:1,c=pe(i),a=new Array(Number(c)+1).fill(o),l=Math.floor((t.BITS-1)/i)*i,u=o;for(let f=l;f>=0;f-=i){a.fill(o);for(let x=0;x<n.length;x++){let E=n[x],y=Number(E>>BigInt(f)&c);a[y]=a[y].add(e[x])}let d=o;for(let x=a.length-1,E=o;x>0;x--)E=E.add(a[x]),d=d.add(E);if(u=u.add(d),f!==0)for(let x=0;x<i;x++)u=u.double()}return u}function Qe(r){return Wn(r.Fp),Vt(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...$n(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Dt=BigInt(0),mt=BigInt(1),oi=BigInt(2),fu=BigInt(8),lu={zip215:!0};function hu(r){let t=Qe(r);return Vt(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function si(r){let t=hu(r),{Fp:e,n,prehash:o,hash:s,randomBytes:i,nByteLength:c,h:a}=t,l=oi<<BigInt(c*8)-mt,u=e.create,f=zt(t.n,t.nBitLength),d=t.uvRatio||((g,m)=>{try{return{isValid:!0,value:e.sqrt(g*e.inv(m))}}catch{return{isValid:!1,value:Dt}}}),x=t.adjustScalarBytes||(g=>g),E=t.domain||((g,m,w)=>{if(Ct("phflag",w),m.length||w)throw new Error("Contexts/pre-hash are not supported");return g});function y(g,m,w=!1){let A=w?mt:Dt;St("coordinate "+g,m,A,l)}function h(g){if(!(g instanceof p))throw new Error("ExtendedPoint expected")}let b=Re((g,m)=>{let{ex:w,ey:A,ez:R}=g,N=g.is0();m==null&&(m=N?fu:e.inv(R));let K=u(w*m),k=u(A*m),O=u(R*m);if(N)return{x:Dt,y:mt};if(O!==mt)throw new Error("invZ was invalid");return{x:K,y:k}}),v=Re(g=>{let{a:m,d:w}=t;if(g.is0())throw new Error("bad point: ZERO");let{ex:A,ey:R,ez:N,et:K}=g,k=u(A*A),O=u(R*R),H=u(N*N),tt=u(H*H),X=u(k*m),it=u(H*u(X+O)),bt=u(tt+u(w*u(k*O)));if(it!==bt)throw new Error("bad point: equation left != right (1)");let ot=u(A*R),ct=u(N*K);if(ot!==ct)throw new Error("bad point: equation left != right (2)");return!0});class p{constructor(m,w,A,R){y("x",m),y("y",w),y("z",A,!0),y("t",R),this.ex=m,this.ey=w,this.ez=A,this.et=R,Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(m){if(m instanceof p)throw new Error("extended point not allowed");let{x:w,y:A}=m||{};return y("x",w),y("y",A),new p(w,A,mt,u(w*A))}static normalizeZ(m){let w=Ne(e,m.map(A=>A.ez));return m.map((A,R)=>A.toAffine(w[R])).map(p.fromAffine)}static msm(m,w){return Ur(p,f,m,w)}_setWindowSize(m){D.setWindowSize(this,m)}assertValidity(){v(this)}equals(m){h(m);let{ex:w,ey:A,ez:R}=this,{ex:N,ey:K,ez:k}=m,O=u(w*k),H=u(N*R),tt=u(A*k),X=u(K*R);return O===H&&tt===X}is0(){return this.equals(p.ZERO)}negate(){return new p(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){let{a:m}=t,{ex:w,ey:A,ez:R}=this,N=u(w*w),K=u(A*A),k=u(oi*u(R*R)),O=u(m*N),H=w+A,tt=u(u(H*H)-N-K),X=O+K,it=X-k,bt=O-K,ot=u(tt*it),ct=u(X*bt),Et=u(tt*bt),At=u(it*X);return new p(ot,ct,At,Et)}add(m){h(m);let{a:w,d:A}=t,{ex:R,ey:N,ez:K,et:k}=this,{ex:O,ey:H,ez:tt,et:X}=m,it=u(R*O),bt=u(N*H),ot=u(k*A*X),ct=u(K*tt),Et=u((R+N)*(O+H)-it-bt),At=ct-ot,Me=ct+ot,Qo=u(bt-w*it),da=u(Et*At),pa=u(Me*Qo),ma=u(Et*Qo),ya=u(At*Me);return new p(da,pa,ya,ma)}subtract(m){return this.add(m.negate())}wNAF(m){return D.wNAFCached(this,m,p.normalizeZ)}multiply(m){let w=m;St("scalar",w,mt,n);let{p:A,f:R}=this.wNAF(w);return p.normalizeZ([A,R])[0]}multiplyUnsafe(m,w=p.ZERO){let A=m;return St("scalar",A,Dt,n),A===Dt?C:this.is0()||A===mt?this:D.wNAFCachedUnsafe(this,A,p.normalizeZ,w)}isSmallOrder(){return this.multiplyUnsafe(a).is0()}isTorsionFree(){return D.unsafeLadder(this,n).is0()}toAffine(m){return b(this,m)}clearCofactor(){let{h:m}=t;return m===mt?this:this.multiplyUnsafe(m)}static fromHex(m,w=!1){let{d:A,a:R}=t,N=e.BYTES;m=W("pointHex",m,N),Ct("zip215",w);let K=m.slice(),k=m[N-1];K[N-1]=k&-129;let O=he(K),H=w?l:e.ORDER;St("pointHex.y",O,Dt,H);let tt=u(O*O),X=u(tt-mt),it=u(A*tt-R),{isValid:bt,value:ot}=d(X,it);if(!bt)throw new Error("Point.fromHex: invalid y coordinate");let ct=(ot&mt)===mt,Et=(k&128)!==0;if(!w&&ot===Dt&&Et)throw new Error("Point.fromHex: x=0 and x_0=1");return Et!==ct&&(ot=u(-ot)),p.fromAffine({x:ot,y:O})}static fromPrivateKey(m){let{scalar:w}=T(m);return I.multiply(w)}toRawBytes(){let{x:m,y:w}=this.toAffine(),A=De(w,e.BYTES);return A[A.length-1]|=m&mt?128:0,A}toHex(){return te(this.toRawBytes())}}p.BASE=new p(t.Gx,t.Gy,mt,u(t.Gx*t.Gy)),p.ZERO=new p(Dt,mt,mt,Dt);let{BASE:I,ZERO:C}=p,D=Nr(p,c*8);function _(g){return V(g,n)}function L(g){return _(he(g))}function T(g){let m=e.BYTES;g=W("private key",g,m);let w=W("hashed private key",s(g),2*m),A=x(w.slice(0,m)),R=w.slice(m,2*m),N=L(A);return{head:A,prefix:R,scalar:N}}function z(g){let{head:m,prefix:w,scalar:A}=T(g),R=I.multiply(A),N=R.toRawBytes();return{head:m,prefix:w,scalar:A,point:R,pointBytes:N}}function M(g){return z(g).pointBytes}function U(g=Uint8Array.of(),...m){let w=ee(...m);return L(s(E(w,W("context",g),!!o)))}function et(g,m,w={}){g=W("message",g),o&&(g=o(g));let{prefix:A,scalar:R,pointBytes:N}=z(m),K=U(w.context,A,g),k=I.multiply(K).toRawBytes(),O=U(w.context,k,N,g),H=_(K+O*R);St("signature.s",H,Dt,n);let tt=ee(k,De(H,e.BYTES));return W("result",tt,e.BYTES*2)}let S=lu;function B(g,m,w,A=S){let{context:R,zip215:N}=A,K=e.BYTES;g=W("signature",g,2*K),m=W("message",m),w=W("publicKey",w,K),N!==void 0&&Ct("zip215",N),o&&(m=o(m));let k=he(g.slice(K,2*K)),O,H,tt;try{O=p.fromHex(w,N),H=p.fromHex(g.slice(0,K),N),tt=I.multiplyUnsafe(k)}catch{return!1}if(!N&&O.isSmallOrder())return!1;let X=U(R,H.toRawBytes(),O.toRawBytes(),m);return H.add(O.multiplyUnsafe(X)).subtract(tt).clearCofactor().equals(p.ZERO)}return I._setWindowSize(8),{CURVE:t,getPublicKey:M,sign:et,verify:B,ExtendedPoint:p,utils:{getExtendedPublicKey:z,randomPrivateKey:()=>i(e.BYTES),precompute(g=8,m=p.BASE){return m._setWindowSize(g),m.multiply(BigInt(3)),m}}}}var no=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),ii=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),xh=BigInt(0),du=BigInt(1),ai=BigInt(2),wh=BigInt(3),pu=BigInt(5),mu=BigInt(8);function yu(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=no,c=r*r%s*r%s,a=j(c,ai,s)*c%s,l=j(a,du,s)*r%s,u=j(l,pu,s)*l%s,f=j(u,t,s)*u%s,d=j(f,e,s)*f%s,x=j(d,n,s)*d%s,E=j(x,o,s)*x%s,y=j(E,o,s)*x%s,h=j(y,t,s)*u%s;return{pow_p_5_8:j(h,ai,s)*r%s,b2:c}}function bu(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function gu(r,t){let e=no,n=V(t*t*t,e),o=V(n*n*t,e),s=yu(r*o).pow_p_5_8,i=V(r*n*s,e),c=V(t*i*i,e),a=i,l=V(i*ii,e),u=c===r,f=c===V(-r,e),d=c===V(-r*ii,e);return u&&(i=a),(f||d)&&(i=l),Xs(i,e)&&(i=V(-i,e)),{isValid:u||f,value:i}}var ci=zt(no,void 0,!0),xu={a:ci.create(BigInt(-1)),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:ci,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:mu,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Hs,randomBytes:Ce,adjustScalarBytes:bu,uvRatio:gu},ui=si(xu);var Kr=32;function fi(r,t,e){return ui.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}var kr=class{type="Ed25519";raw;constructor(t){this.raw=oo(t,Kr)}toMultihash(){return Bt.digest(kt(this))}toCID(){return ut.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:xt(this.raw,t.raw)}verify(t,e){return fi(this.raw,e,t)}};function so(r){return r=oo(r,Kr),new kr(r)}function oo(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 Eu=Math.pow(2,7),Su=Math.pow(2,14),vu=Math.pow(2,21),io=Math.pow(2,28),ao=Math.pow(2,35),co=Math.pow(2,42),uo=Math.pow(2,49),q=128,lt=127;function Lt(r){if(r<Eu)return 1;if(r<Su)return 2;if(r<vu)return 3;if(r<io)return 4;if(r<ao)return 5;if(r<co)return 6;if(r<uo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function fo(r,t,e=0){switch(Lt(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 Au(r,t,e=0){switch(Lt(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 lo(r,t){let e=r[t],n=0;if(n+=e<,e<q||(e=r[t+1],n+=(e<)<<7,e<q)||(e=r[t+2],n+=(e<)<<14,e<q)||(e=r[t+3],n+=(e<)<<21,e<q)||(e=r[t+4],n+=(e<)*io,e<q)||(e=r[t+5],n+=(e<)*ao,e<q)||(e=r[t+6],n+=(e<)*co,e<q)||(e=r[t+7],n+=(e<)*uo,e<q))return n;throw new RangeError("Could not decode varint")}function Iu(r,t){let e=r.get(t),n=0;if(n+=e<,e<q||(e=r.get(t+1),n+=(e<)<<7,e<q)||(e=r.get(t+2),n+=(e<)<<14,e<q)||(e=r.get(t+3),n+=(e<)<<21,e<q)||(e=r.get(t+4),n+=(e<)*io,e<q)||(e=r.get(t+5),n+=(e<)*ao,e<q)||(e=r.get(t+6),n+=(e<)*co,e<q)||(e=r.get(t+7),n+=(e<)*uo,e<q))return n;throw new RangeError("Could not decode varint")}function hi(r,t,e=0){return t==null&&(t=ft(Lt(r))),t instanceof Uint8Array?fo(r,t,e):Au(r,t,e)}function di(r,t=0){return r instanceof Uint8Array?lo(r,t):Iu(r,t)}var ho=new Float32Array([-0]),re=new Uint8Array(ho.buffer);function mi(r,t,e){ho[0]=r,t[e]=re[0],t[e+1]=re[1],t[e+2]=re[2],t[e+3]=re[3]}function yi(r,t){return re[0]=r[t],re[1]=r[t+1],re[2]=r[t+2],re[3]=r[t+3],ho[0]}var po=new Float64Array([-0]),ht=new Uint8Array(po.buffer);function bi(r,t,e){po[0]=r,t[e]=ht[0],t[e+1]=ht[1],t[e+2]=ht[2],t[e+3]=ht[3],t[e+4]=ht[4],t[e+5]=ht[5],t[e+6]=ht[6],t[e+7]=ht[7]}function gi(r,t){return ht[0]=r[t],ht[1]=r[t+1],ht[2]=r[t+2],ht[3]=r[t+3],ht[4]=r[t+4],ht[5]=r[t+5],ht[6]=r[t+6],ht[7]=r[t+7],po[0]}var Bu=BigInt(Number.MAX_SAFE_INTEGER),_u=BigInt(Number.MIN_SAFE_INTEGER),vt=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return ye;if(t<Bu&&t>_u)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>xi&&(o=0n,++n>xi&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return ye;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):ye}},ye=new vt(0,0);ye.toBigInt=function(){return 0n};ye.zzEncode=ye.zzDecode=function(){return this};ye.length=function(){return 1};var xi=4294967296n;function wi(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 Ei(r,t,e){if(e-t<1)return"";let o,s=[],i=0,c;for(;t<e;)c=r[t++],c<128?s[i++]=c:c>191&&c<224?s[i++]=(c&31)<<6|r[t++]&63:c>239&&c<365?(c=((c&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(c>>10),s[i++]=56320+(c&1023)):s[i++]=(c&15)<<12|(r[t++]&63)<<6|r[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function mo(r,t,e){let n=e,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function Tt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Or(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var yo=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,Tt(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 Tt(this,4);return Or(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Tt(this,4);return Or(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Tt(this,4);let t=yi(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Tt(this,4);let t=gi(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 Tt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Ei(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Tt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Tt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new vt(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw Tt(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 Tt(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 Tt(this,8);let t=Or(this.buf,this.pos+=4),e=Or(this.buf,this.pos+=4);return new vt(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=lo(this.buf,this.pos);return this.pos+=Lt(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 bo(r){return new yo(r instanceof Uint8Array?r:r.subarray())}function Mr(r,t,e){let n=bo(r);return t.decode(n,void 0,e)}function go(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return ft(i);o+i>t&&(n=ft(t),o=0);let c=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),c}}var be=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function xo(){}var Eo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Lu=go();function Tu(r){return globalThis.Buffer!=null?ft(r):Lu(r)}var er=class{len;head;tail;states;constructor(){this.len=0,this.head=new be(xo,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new be(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new So((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(qr,10,vt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=vt.fromBigInt(t);return this._push(qr,e.length(),e)}uint64Number(t){return this._push(fo,Lt(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=vt.fromBigInt(t).zzEncode();return this._push(qr,e.length(),e)}sint64Number(t){let e=vt.fromNumber(t).zzEncode();return this._push(qr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(wo,1,t?1:0)}fixed32(t){return this._push(tr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=vt.fromBigInt(t);return this._push(tr,4,e.lo)._push(tr,4,e.hi)}fixed64Number(t){let e=vt.fromNumber(t);return this._push(tr,4,e.lo)._push(tr,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(mi,4,t)}double(t){return this._push(bi,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(wo,1,0):this.uint32(e)._push(Cu,e,t)}string(t){let e=wi(t);return e!==0?this.uint32(e)._push(mo,e,t):this._push(wo,1,0)}fork(){return this.states=new Eo(this),this.head=this.tail=new be(xo,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 be(xo,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=Tu(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function wo(r,t,e){t[e]=r&255}function Pu(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var So=class extends be{next;constructor(t,e){super(Pu,t,e),this.next=void 0}};function qr(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 tr(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 Cu(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(er.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Du,t,r),this},er.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Ru,t,r),this});function Du(r,t,e){t.set(r,e)}function Ru(r,t,e){r.length<40?mo(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(F(r),e)}function vo(){return new er}function Hr(r,t){let e=vo();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var Ue;(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"})(Ue||(Ue={}));function Vr(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Ao(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(s,i){let c=t(s);i.int32(c)},n=function(s){let i=s.int32();return t(i)};return Vr("enum",Ue.VARINT,e,n)}function zr(r,t){return Vr("message",Ue.LENGTH_DELIMITED,r,t)}var Q;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(Q||(Q={}));var Io;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(Io||(Io={}));(function(r){r.codec=()=>Ao(Io)})(Q||(Q={}));var Rt;(function(r){let t;r.codec=()=>(t==null&&(t=zr((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),Q.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let c=e.uint32();switch(c>>>3){case 1:{s.Type=Q.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(c&7);break}}}return s})),t),r.encode=e=>Hr(e,r.codec()),r.decode=(e,n)=>Mr(e,r.codec(),n)})(Rt||(Rt={}));var Bo;(function(r){let t;r.codec=()=>(t==null&&(t=zr((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),Q.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let c=e.uint32();switch(c>>>3){case 1:{s.Type=Q.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(c&7);break}}}return s})),t),r.encode=e=>Hr(e,r.codec()),r.decode=(e,n)=>Mr(e,r.codec(),n)})(Bo||(Bo={}));function Fr(r){if(isNaN(r)||r<=0)throw new Z("random bytes length must be a Number bigger than 0");return Ce(r)}var rr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Gr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Ai={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new Gr("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 ne=Ai;var or={};gt(or,{MAX_RSA_KEY_SIZE:()=>_o,generateRSAKeyPair:()=>Li,jwkToJWKKeyPair:()=>Ti,jwkToPkcs1:()=>ku,jwkToPkix:()=>Co,jwkToRSAPrivateKey:()=>Uo,pkcs1MessageToJwk:()=>To,pkcs1MessageToRSAPrivateKey:()=>Do,pkcs1ToJwk:()=>Ku,pkcs1ToRSAPrivateKey:()=>_i,pkixMessageToJwk:()=>Po,pkixMessageToRSAPublicKey:()=>No,pkixToJwk:()=>Ou,pkixToRSAPublicKey:()=>Ro});var jr=Cr;var Ke=class{type="RSA";jwk;_raw;_multihash;constructor(t,e){this.jwk=t,this._multihash=e}get raw(){return this._raw==null&&(this._raw=or.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return ut.createV1(114,this._multihash)}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:xt(this.raw,t.raw)}verify(t,e){return Bi(this.jwk,e,t)}},nr=class{type="RSA";jwk;_raw;publicKey;constructor(t,e){this.jwk=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=or.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:xt(this.raw,t.raw)}sign(t){return Ii(this.jwk,t)}};var _o=8192,Lo=18,Nu=1062,Uu=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Ku(r){let t=Kt(r);return To(t)}function To(r){return{n:G(r[1],"base64url"),e:G(r[2],"base64url"),d:G(r[3],"base64url"),p:G(r[4],"base64url"),q:G(r[5],"base64url"),dp:G(r[6],"base64url"),dq:G(r[7],"base64url"),qi:G(r[8],"base64url"),kty:"RSA"}}function ku(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 $t([wt(Uint8Array.from([0])),wt(F(r.n,"base64url")),wt(F(r.e,"base64url")),wt(F(r.d,"base64url")),wt(F(r.p,"base64url")),wt(F(r.q,"base64url")),wt(F(r.dp,"base64url")),wt(F(r.dq,"base64url")),wt(F(r.qi,"base64url"))]).subarray()}function Ou(r){let t=Kt(r,{offset:0});return Po(t)}function Po(r){let t=Kt(r[1],{offset:0});return{kty:"RSA",n:G(t[0],"base64url"),e:G(t[1],"base64url")}}function Co(r){if(r.n==null||r.e==null)throw new Z("JWK was missing components");return $t([Uu,Br($t([wt(F(r.n,"base64url")),wt(F(r.e,"base64url"))]))]).subarray()}function _i(r){let t=Kt(r);return Do(t)}function Do(r){let t=To(r);return Uo(t)}function Ro(r,t){if(r.byteLength>=Nu)throw new Ee("Key size is too large");let e=Kt(r,{offset:0});return No(e,r,t)}function No(r,t,e){let n=Po(r);if(e==null){let o=jr(Rt.encode({Type:Q.RSA,Data:t}));e=It(Lo,o)}return new Ke(n,e)}function Uo(r){if(Ci(r)>_o)throw new Z("Key size is too large");let t=Ti(r),e=jr(Rt.encode({Type:Q.RSA,Data:Co(t.publicKey)})),n=It(Lo,e);return new nr(t.privateKey,new Ke(t.publicKey,n))}async function Li(r){if(r>_o)throw new Z("Key size is too large");let t=await Pi(r),e=jr(Rt.encode({Type:Q.RSA,Data:Co(t.publicKey)})),n=It(Lo,e);return new nr(t.privateKey,new Ke(t.publicKey,n))}function Ti(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 Pi(r){let t=await ne.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),e=await Mu(t);return{privateKey:e[0],publicKey:e[1]}}async function Ii(r,t){let e=await ne.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await ne.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},e,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(n,0,n.byteLength)}async function Bi(r,t,e){let n=await ne.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return ne.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,t,e instanceof Uint8Array?e:e.subarray())}async function Mu(r){if(r.privateKey==null||r.publicKey==null)throw new Z("Private and public key are required");return Promise.all([ne.get().subtle.exportKey("jwk",r.privateKey),ne.get().subtle.exportKey("jwk",r.publicKey)])}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 Zr=class extends Te{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,_s(t);let n=Ze(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),Ot(s)}update(t){return Pe(this),this.iHash.update(t),this}digestInto(t){Pe(this),ce(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:c}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=c,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Ko=(r,t,e)=>new Zr(r,t).update(e).digest();Ko.create=(r,t)=>new Zr(r,t);function Di(r){r.lowS!==void 0&&Ct("lowS",r.lowS),r.prehash!==void 0&&Ct("prehash",r.prehash)}function qu(r){let t=Qe(r);Vt(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:e,Fp:n,a:o}=t;if(e){if(!n.eql(o,n.ZERO))throw new Error("invalid endomorphism, can only be defined for Koblitz curves that have a=0");if(typeof e!="object"||typeof e.beta!="bigint"||typeof e.splitScalar!="function")throw new Error("invalid endomorphism, expected beta: bigint and splitScalar: function")}return Object.freeze({...t})}var ko=class extends Error{constructor(t=""){super(t)}},Ft={Err:ko,_tlv:{encode:(r,t)=>{let{Err:e}=Ft;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=Xe(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?Xe(o.length/2|128):"";return Xe(r)+s+o+t},decode(r,t){let{Err:e}=Ft,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 a=o&127;if(!a)throw new e("tlv.decode(long): indefinite length not supported");if(a>4)throw new e("tlv.decode(long): byte length is too big");let l=t.subarray(n,n+a);if(l.length!==a)throw new e("tlv.decode: length bytes not complete");if(l[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let u of l)i=i<<8|u;if(n+=a,i<128)throw new e("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+i);if(c.length!==i)throw new e("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=Ft;if(r<Gt)throw new t("integer: negative integers are not allowed");let e=Xe(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}=Ft;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 Ht(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Ft,o=W("signature",r),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:c,l:a}=n.decode(2,s),{v:l,l:u}=n.decode(2,a);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(c),s:e.decode(l)}},hexFromSig(r){let{_tlv:t,_int:e}=Ft,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}},Gt=BigInt(0),st=BigInt(1),Jd=BigInt(2),Ri=BigInt(3),Qd=BigInt(4);function Hu(r){let t=qu(r),{Fp:e}=t,n=zt(t.n,t.nBitLength),o=t.toBytes||((y,h,b)=>{let v=h.toAffine();return ee(Uint8Array.from([4]),e.toBytes(v.x),e.toBytes(v.y))}),s=t.fromBytes||(y=>{let h=y.subarray(1),b=e.fromBytes(h.subarray(0,e.BYTES)),v=e.fromBytes(h.subarray(e.BYTES,2*e.BYTES));return{x:b,y:v}});function i(y){let{a:h,b}=t,v=e.sqr(y),p=e.mul(v,y);return e.add(e.add(p,e.mul(y,h)),b)}if(!e.eql(e.sqr(t.Gy),i(t.Gx)))throw new Error("bad generator point: equation left != right");function c(y){return Dr(y,st,t.n)}function a(y){let{allowedPrivateKeyLengths:h,nByteLength:b,wrapPrivateKey:v,n:p}=t;if(h&&typeof y!="bigint"){if(le(y)&&(y=te(y)),typeof y!="string"||!h.includes(y.length))throw new Error("invalid private key");y=y.padStart(b*2,"0")}let I;try{I=typeof y=="bigint"?y:Ht(W("private key",y,b))}catch{throw new Error("invalid private key, expected hex or "+b+" bytes, got "+typeof y)}return v&&(I=V(I,p)),St("private key",I,st,p),I}function l(y){if(!(y instanceof d))throw new Error("ProjectivePoint expected")}let u=Re((y,h)=>{let{px:b,py:v,pz:p}=y;if(e.eql(p,e.ONE))return{x:b,y:v};let I=y.is0();h==null&&(h=I?e.ONE:e.inv(p));let C=e.mul(b,h),D=e.mul(v,h),_=e.mul(p,h);if(I)return{x:e.ZERO,y:e.ZERO};if(!e.eql(_,e.ONE))throw new Error("invZ was invalid");return{x:C,y:D}}),f=Re(y=>{if(y.is0()){if(t.allowInfinityPoint&&!e.is0(y.py))return;throw new Error("bad point: ZERO")}let{x:h,y:b}=y.toAffine();if(!e.isValid(h)||!e.isValid(b))throw new Error("bad point: x or y not FE");let v=e.sqr(b),p=i(h);if(!e.eql(v,p))throw new Error("bad point: equation left != right");if(!y.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class d{constructor(h,b,v){if(h==null||!e.isValid(h))throw new Error("x required");if(b==null||!e.isValid(b)||e.is0(b))throw new Error("y required");if(v==null||!e.isValid(v))throw new Error("z required");this.px=h,this.py=b,this.pz=v,Object.freeze(this)}static fromAffine(h){let{x:b,y:v}=h||{};if(!h||!e.isValid(b)||!e.isValid(v))throw new Error("invalid affine point");if(h instanceof d)throw new Error("projective point not allowed");let p=I=>e.eql(I,e.ZERO);return p(b)&&p(v)?d.ZERO:new d(b,v,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){let b=Ne(e,h.map(v=>v.pz));return h.map((v,p)=>v.toAffine(b[p])).map(d.fromAffine)}static fromHex(h){let b=d.fromAffine(s(W("pointHex",h)));return b.assertValidity(),b}static fromPrivateKey(h){return d.BASE.multiply(a(h))}static msm(h,b){return Ur(d,n,h,b)}_setWindowSize(h){E.setWindowSize(this,h)}assertValidity(){f(this)}hasEvenY(){let{y:h}=this.toAffine();if(e.isOdd)return!e.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){l(h);let{px:b,py:v,pz:p}=this,{px:I,py:C,pz:D}=h,_=e.eql(e.mul(b,D),e.mul(I,p)),L=e.eql(e.mul(v,D),e.mul(C,p));return _&&L}negate(){return new d(this.px,e.neg(this.py),this.pz)}double(){let{a:h,b}=t,v=e.mul(b,Ri),{px:p,py:I,pz:C}=this,D=e.ZERO,_=e.ZERO,L=e.ZERO,T=e.mul(p,p),z=e.mul(I,I),M=e.mul(C,C),U=e.mul(p,I);return U=e.add(U,U),L=e.mul(p,C),L=e.add(L,L),D=e.mul(h,L),_=e.mul(v,M),_=e.add(D,_),D=e.sub(z,_),_=e.add(z,_),_=e.mul(D,_),D=e.mul(U,D),L=e.mul(v,L),M=e.mul(h,M),U=e.sub(T,M),U=e.mul(h,U),U=e.add(U,L),L=e.add(T,T),T=e.add(L,T),T=e.add(T,M),T=e.mul(T,U),_=e.add(_,T),M=e.mul(I,C),M=e.add(M,M),T=e.mul(M,U),D=e.sub(D,T),L=e.mul(M,z),L=e.add(L,L),L=e.add(L,L),new d(D,_,L)}add(h){l(h);let{px:b,py:v,pz:p}=this,{px:I,py:C,pz:D}=h,_=e.ZERO,L=e.ZERO,T=e.ZERO,z=t.a,M=e.mul(t.b,Ri),U=e.mul(b,I),et=e.mul(v,C),S=e.mul(p,D),B=e.add(b,v),P=e.add(I,C);B=e.mul(B,P),P=e.add(U,et),B=e.sub(B,P),P=e.add(b,p);let g=e.add(I,D);return P=e.mul(P,g),g=e.add(U,S),P=e.sub(P,g),g=e.add(v,p),_=e.add(C,D),g=e.mul(g,_),_=e.add(et,S),g=e.sub(g,_),T=e.mul(z,P),_=e.mul(M,S),T=e.add(_,T),_=e.sub(et,T),T=e.add(et,T),L=e.mul(_,T),et=e.add(U,U),et=e.add(et,U),S=e.mul(z,S),P=e.mul(M,P),et=e.add(et,S),S=e.sub(U,S),S=e.mul(z,S),P=e.add(P,S),U=e.mul(et,P),L=e.add(L,U),U=e.mul(g,P),_=e.mul(B,_),_=e.sub(_,U),U=e.mul(B,et),T=e.mul(g,T),T=e.add(T,U),new d(_,L,T)}subtract(h){return this.add(h.negate())}is0(){return this.equals(d.ZERO)}wNAF(h){return E.wNAFCached(this,h,d.normalizeZ)}multiplyUnsafe(h){let{endo:b,n:v}=t;St("scalar",h,Gt,v);let p=d.ZERO;if(h===Gt)return p;if(this.is0()||h===st)return this;if(!b||E.hasPrecomputes(this))return E.wNAFCachedUnsafe(this,h,d.normalizeZ);let{k1neg:I,k1:C,k2neg:D,k2:_}=b.splitScalar(h),L=p,T=p,z=this;for(;C>Gt||_>Gt;)C&st&&(L=L.add(z)),_&st&&(T=T.add(z)),z=z.double(),C>>=st,_>>=st;return I&&(L=L.negate()),D&&(T=T.negate()),T=new d(e.mul(T.px,b.beta),T.py,T.pz),L.add(T)}multiply(h){let{endo:b,n:v}=t;St("scalar",h,st,v);let p,I;if(b){let{k1neg:C,k1:D,k2neg:_,k2:L}=b.splitScalar(h),{p:T,f:z}=this.wNAF(D),{p:M,f:U}=this.wNAF(L);T=E.constTimeNegate(C,T),M=E.constTimeNegate(_,M),M=new d(e.mul(M.px,b.beta),M.py,M.pz),p=T.add(M),I=z.add(U)}else{let{p:C,f:D}=this.wNAF(h);p=C,I=D}return d.normalizeZ([p,I])[0]}multiplyAndAddUnsafe(h,b,v){let p=d.BASE,I=(D,_)=>_===Gt||_===st||!D.equals(p)?D.multiplyUnsafe(_):D.multiply(_),C=I(this,b).add(I(h,v));return C.is0()?void 0:C}toAffine(h){return u(this,h)}isTorsionFree(){let{h,isTorsionFree:b}=t;if(h===st)return!0;if(b)return b(d,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:b}=t;return h===st?this:b?b(d,this):this.multiplyUnsafe(t.h)}toRawBytes(h=!0){return Ct("isCompressed",h),this.assertValidity(),o(d,this,h)}toHex(h=!0){return Ct("isCompressed",h),te(this.toRawBytes(h))}}d.BASE=new d(t.Gx,t.Gy,e.ONE),d.ZERO=new d(e.ZERO,e.ONE,e.ZERO);let x=t.nBitLength,E=Nr(d,t.endo?Math.ceil(x/2):x);return{CURVE:t,ProjectivePoint:d,normPrivateKeyToScalar:a,weierstrassEquation:i,isWithinCurveOrder:c}}function Vu(r){let t=Qe(r);return Vt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Ni(r){let t=Vu(r),{Fp:e,n}=t,o=e.BYTES+1,s=2*e.BYTES+1;function i(S){return V(S,n)}function c(S){return Rr(S,n)}let{ProjectivePoint:a,normPrivateKeyToScalar:l,weierstrassEquation:u,isWithinCurveOrder:f}=Hu({...t,toBytes(S,B,P){let g=B.toAffine(),m=e.toBytes(g.x),w=ee;return Ct("isCompressed",P),P?w(Uint8Array.from([B.hasEvenY()?2:3]),m):w(Uint8Array.from([4]),m,e.toBytes(g.y))},fromBytes(S){let B=S.length,P=S[0],g=S.subarray(1);if(B===o&&(P===2||P===3)){let m=Ht(g);if(!Dr(m,st,e.ORDER))throw new Error("Point is not on curve");let w=u(m),A;try{A=e.sqrt(w)}catch(K){let k=K instanceof Error?": "+K.message:"";throw new Error("Point is not on curve"+k)}let R=(A&st)===st;return(P&1)===1!==R&&(A=e.neg(A)),{x:m,y:A}}else if(B===s&&P===4){let m=e.fromBytes(g.subarray(0,e.BYTES)),w=e.fromBytes(g.subarray(e.BYTES,2*e.BYTES));return{x:m,y:w}}else{let m=o,w=s;throw new Error("invalid Point, expected length of "+m+", or uncompressed "+w+", got "+B)}}}),d=S=>te(de(S,t.nByteLength));function x(S){let B=n>>st;return S>B}function E(S){return x(S)?i(-S):S}let y=(S,B,P)=>Ht(S.slice(B,P));class h{constructor(B,P,g){St("r",B,st,n),St("s",P,st,n),this.r=B,this.s=P,g!=null&&(this.recovery=g),Object.freeze(this)}static fromCompact(B){let P=t.nByteLength;return B=W("compactSignature",B,P*2),new h(y(B,0,P),y(B,P,2*P))}static fromDER(B){let{r:P,s:g}=Ft.toSig(W("DER",B));return new h(P,g)}assertValidity(){}addRecoveryBit(B){return new h(this.r,this.s,B)}recoverPublicKey(B){let{r:P,s:g,recovery:m}=this,w=D(W("msgHash",B));if(m==null||![0,1,2,3].includes(m))throw new Error("recovery id invalid");let A=m===2||m===3?P+t.n:P;if(A>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let R=(m&1)===0?"02":"03",N=a.fromHex(R+d(A)),K=c(A),k=i(-w*K),O=i(g*K),H=a.BASE.multiplyAndAddUnsafe(N,k,O);if(!H)throw new Error("point at infinify");return H.assertValidity(),H}hasHighS(){return x(this.s)}normalizeS(){return this.hasHighS()?new h(this.r,i(-this.s),this.recovery):this}toDERRawBytes(){return Je(this.toDERHex())}toDERHex(){return Ft.hexFromSig(this)}toCompactRawBytes(){return Je(this.toCompactHex())}toCompactHex(){return d(this.r)+d(this.s)}}let b={isValidPrivateKey(S){try{return l(S),!0}catch{return!1}},normPrivateKeyToScalar:l,randomPrivateKey:()=>{let S=Xn(t.n);return Qs(t.randomBytes(S),t.n)},precompute(S=8,B=a.BASE){return B._setWindowSize(S),B.multiply(BigInt(3)),B}};function v(S,B=!0){return a.fromPrivateKey(S).toRawBytes(B)}function p(S){let B=le(S),P=typeof S=="string",g=(B||P)&&S.length;return B?g===o||g===s:P?g===2*o||g===2*s:S instanceof a}function I(S,B,P=!0){if(p(S))throw new Error("first arg must be private key");if(!p(B))throw new Error("second arg must be public key");return a.fromHex(B).multiply(l(S)).toRawBytes(P)}let C=t.bits2int||function(S){if(S.length>8192)throw new Error("input is too large");let B=Ht(S),P=S.length*8-t.nBitLength;return P>0?B>>BigInt(P):B},D=t.bits2int_modN||function(S){return i(C(S))},_=pe(t.nBitLength);function L(S){return St("num < 2^"+t.nBitLength,S,Gt,_),de(S,t.nByteLength)}function T(S,B,P=z){if(["recovered","canonical"].some(X=>X in P))throw new Error("sign() legacy options not supported");let{hash:g,randomBytes:m}=t,{lowS:w,prehash:A,extraEntropy:R}=P;w==null&&(w=!0),S=W("msgHash",S),Di(P),A&&(S=W("prehashed msgHash",g(S)));let N=D(S),K=l(B),k=[L(K),L(N)];if(R!=null&&R!==!1){let X=R===!0?m(e.BYTES):R;k.push(W("extraEntropy",X))}let O=ee(...k),H=N;function tt(X){let it=C(X);if(!f(it))return;let bt=c(it),ot=a.BASE.multiply(it).toAffine(),ct=i(ot.x);if(ct===Gt)return;let Et=i(bt*i(H+ct*K));if(Et===Gt)return;let At=(ot.x===ct?0:2)|Number(ot.y&st),Me=Et;return w&&x(Et)&&(Me=E(Et),At^=1),new h(ct,Me,At)}return{seed:O,k2sig:tt}}let z={lowS:t.lowS,prehash:!1},M={lowS:t.lowS,prehash:!1};function U(S,B,P=z){let{seed:g,k2sig:m}=T(S,B,P),w=t;return Zs(w.hash.outputLen,w.nByteLength,w.hmac)(g,m)}a.BASE._setWindowSize(8);function et(S,B,P,g=M){let m=S;B=W("msgHash",B),P=W("publicKey",P);let{lowS:w,prehash:A,format:R}=g;if(Di(g),"strict"in g)throw new Error("options.strict was renamed to lowS");if(R!==void 0&&R!=="compact"&&R!=="der")throw new Error("format must be compact or der");let N=typeof m=="string"||le(m),K=!N&&!R&&typeof m=="object"&&m!==null&&typeof m.r=="bigint"&&typeof m.s=="bigint";if(!N&&!K)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let k,O;try{if(K&&(k=new h(m.r,m.s)),N){try{R!=="compact"&&(k=h.fromDER(m))}catch(At){if(!(At instanceof Ft.Err))throw At}!k&&R!=="der"&&(k=h.fromCompact(m))}O=a.fromHex(P)}catch{return!1}if(!k||w&&k.hasHighS())return!1;A&&(B=t.hash(B));let{r:H,s:tt}=k,X=D(B),it=c(tt),bt=i(X*it),ot=i(H*it),ct=a.BASE.multiplyAndAddUnsafe(O,bt,ot)?.toAffine();return ct?i(ct.x)===H:!1}return{CURVE:t,getPublicKey:v,getSharedSecret:I,sign:U,verify:et,ProjectivePoint:a,Signature:h,utils:b}}function zu(r){return{hash:r,hmac:(t,...e)=>Ko(r,t,On(...e)),randomBytes:Ce}}function Ui(r,t){let e=n=>Ni({...r,...zu(n)});return{...e(t),create:e}}var Oi=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Ki=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Fu=BigInt(1),Oo=BigInt(2),ki=(r,t)=>(r+t/Oo)/t;function Gu(r){let t=Oi,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),a=BigInt(88),l=r*r*r%t,u=l*l*r%t,f=j(u,e,t)*u%t,d=j(f,e,t)*u%t,x=j(d,Oo,t)*l%t,E=j(x,o,t)*x%t,y=j(E,s,t)*E%t,h=j(y,c,t)*y%t,b=j(h,a,t)*h%t,v=j(b,c,t)*y%t,p=j(v,e,t)*u%t,I=j(p,i,t)*E%t,C=j(I,n,t)*l%t,D=j(C,Oo,t);if(!Mo.eql(Mo.sqr(D),r))throw new Error("Cannot find square root");return D}var Mo=zt(Oi,void 0,void 0,{sqrt:Gu}),ge=Ui({a:BigInt(0),b:BigInt(7),Fp:Mo,n:Ki,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=Ki,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-Fu*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=e,i=BigInt("0x100000000000000000000000000000000"),c=ki(s*r,t),a=ki(-n*r,t),l=V(r-c*e-a*o,t),u=V(-c*n-a*s,t),f=l>i,d=u>i;if(f&&(l=t-l),d&&(u=t-u),l>i||u>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:f,k1:l,k2neg:d,k2:u}}}},Cr),cp=BigInt(0);var up=ge.ProjectivePoint;function Mi(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function qi(r,t,e){let n=ie.digest(e instanceof Uint8Array?e:e.subarray());if(Mi(n))return n.then(({digest:o})=>ge.verify(t,o,r)).catch(o=>{throw new rr(String(o))});try{return ge.verify(t,n.digest,r)}catch(o){throw new rr(String(o))}}var Yr=class{type="secp256k1";raw;_key;constructor(t){this._key=Vi(t),this.raw=Hi(this._key)}toMultihash(){return Bt.digest(kt(this))}toCID(){return ut.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:xt(this.raw,t.raw)}verify(t,e){return qi(this._key,e,t)}};function qo(r){return new Yr(r)}function Hi(r){return ge.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Vi(r){try{return ge.ProjectivePoint.fromHex(r),r}catch(t){throw new Ee(String(t))}}function Ho(r,t){let{Type:e,Data:n}=Rt.decode(r),o=n??new Uint8Array;switch(e){case Q.RSA:return Ro(o,t);case Q.Ed25519:return so(o);case Q.secp256k1:return qo(o);case Q.ECDSA:return kn(o);default:throw new oe}}function zi(r){let{Type:t,Data:e}=Rt.decode(r.digest),n=e??new Uint8Array;switch(t){case Q.Ed25519:return so(n);case Q.secp256k1:return qo(n);case Q.ECDSA:return kn(n);default:throw new oe}}function kt(r){return Rt.encode({Type:Q[r.type],Data:r.raw})}var Fi=Symbol.for("nodejs.util.inspect.custom"),ju=114,sr=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()})`}[un]=!0;toString(){return this.string==null&&(this.string=Y.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ut.createV1(ju,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return xt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return xt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Fi](){return`PeerId(${this.toString()})`}},ir=class extends sr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},ar=class extends sr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},cr=class extends sr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Zu=2336,Wr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Bt.digest(F(this.url))}[Fi](){return`PeerId(${this.url})`}[un]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ut.createV1(Zu,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=G(t)),t.toString()===this.toString())}};function Vo(r){if(r.type==="Ed25519")return new ar({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new cr({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new ir({multihash:r.toCID().multihash,publicKey:r});throw new oe}function Gi(r){return Vo(r.publicKey)}function ur(r){if(Wu(r))return new ir({multihash:r});if(Yu(r))try{let t=zi(r);if(t.type==="Ed25519")return new ar({multihash:r,publicKey:t});if(t.type==="secp256k1")return new cr({multihash:r,publicKey:t})}catch{let e=G(r.digest);return new Wr(new URL(e))}throw new Er("Supplied PeerID Multihash is invalid")}function Yu(r){return r.code===Bt.code}function Wu(r){return r.code===ie.code}function xe(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 $r(r){let t=Yt(Y.decode(`z${r}`));return ur(t)}var fr=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 xe(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 xe(this.map.values(),t=>t.key)}values(){return xe(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 xe(this.set.entries(),t=>{let e=$r(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=$r(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return xe(this.set.values(),t=>$r(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 jt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Xr=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}},ke=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Xr(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 Xr(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 zo=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function Jr(r={}){return $u(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 $u(r,t){t=t??{};let e=t.onEnd,n=new ke,o,s,i,c=jt(),a=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((h,b)=>{s=v=>{s=null,n.push(v);try{h(r(n))}catch(p){b(p)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{c.resolve(),c=jt()})}},l=h=>s!=null?s(h):(n.push(h),o),u=h=>(n=new ke,s!=null?s({error:h}):(n.push({error:h}),o)),f=h=>{if(i)return o;if(t?.objectMode!==!0&&h?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:h})},d=h=>i?o:(i=!0,h!=null?u(h):l({done:!0})),x=()=>(n=new ke,d(),{done:!0}),E=h=>(d(h),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:a,return:x,throw:E,push:f,end:d,get readableLength(){return n.size},onEmpty:async h=>{let b=h?.signal;if(b?.throwIfAborted(),n.isEmpty())return;let v,p;b!=null&&(v=new Promise((I,C)=>{p=()=>{C(new zo)},b.addEventListener("abort",p)}));try{await Promise.race([c.promise,v])}finally{p!=null&&b!=null&&b?.removeEventListener("abort",p)}}},e==null)return o;let y=o;return o={[Symbol.asyncIterator](){return this},next(){return y.next()},throw(h){return y.throw(h),e!=null&&(e(h),e=void 0),{done:!0}},return(){return y.return(),e!=null&&(e(),e=void 0),{done:!0}},push:f,end(h){return y.end(h),e!=null&&(e(h),e=void 0),o},get readableLength(){return y.readableLength},onEmpty:h=>y.onEmpty(h)},o}var Qr=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 ji(r,t,e){if(t==null)return r;if(t.aborted)return r.catch(()=>{}),Promise.reject(new Qr(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new Qr(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 Fo=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=jt(),this.haveNext=jt()}[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=jt(),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=jt(),await ji(this.readNext.promise,e?.signal,e)}};function Zi(){return new Fo}function Xu(r){return r[Symbol.asyncIterator]!=null}async function Ju(r,t){try{await Promise.all(r.map(async e=>{for await(let n of e)await t.push(n)})),await t.end()}catch(e){await t.end(e).catch(()=>{})}}async function*Qu(r){let t=Zi();Ju(r,t).catch(()=>{}),yield*t}function*tf(r){for(let t of r)yield*t}function ef(...r){let t=[];for(let e of r)Xu(e)||t.push(e);return t.length===r.length?tf(t):Qu(r)}var Yi=ef;function hr(r,...t){if(r==null)throw new Error("Empty pipeline");if(Go(r)){let n=r;r=()=>n.source}else if($i(r)||Wi(r)){let n=r;r=()=>n}let e=[r,...t];if(e.length>1&&Go(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++)Go(e[n])&&(e[n]=nf(e[n]));return rf(...e)}var rf=(...r)=>{let t;for(;r.length>0;)t=r.shift()(t);return t},Wi=r=>r?.[Symbol.asyncIterator]!=null,$i=r=>r?.[Symbol.iterator]!=null,Go=r=>r==null?!1:r.sink!=null&&r.source!=null,nf=r=>t=>{let e=r.sink(t);if(e?.then!=null){let n=Jr({objectMode:!0});e.then(()=>{n.end()},i=>{n.end(i)});let o,s=r.source;if(Wi(s))o=async function*(){yield*s,n.end()};else if($i(s))o=function*(){yield*s,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return Yi(n,o())}return r.source};var Zo=va(Ji(),1);var pr=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},Yo=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},Qi=r=>globalThis.DOMException===void 0?new Yo(r):new DOMException(r),ta=r=>{let t=r.reason===void 0?Qi("This operation was aborted."):r.reason;return t instanceof Error?t:Qi(t)};function Wo(r,t){let{milliseconds:e,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=t,i,c,l=new Promise((u,f)=>{if(typeof e!="number"||Math.sign(e)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${e}\``);if(t.signal){let{signal:x}=t;x.aborted&&f(ta(x)),c=()=>{f(ta(x))},x.addEventListener("abort",c,{once:!0})}if(e===Number.POSITIVE_INFINITY){r.then(u,f);return}let d=new pr;i=s.setTimeout.call(void 0,()=>{if(n){try{u(n())}catch(x){f(x)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?u():o instanceof Error?f(o):(d.message=o??`Promise timed out after ${e} milliseconds`,f(d))},e),(async()=>{try{u(await r)}catch(x){f(x)}})()}).finally(()=>{l.clear(),c&&t.signal&&t.signal.removeEventListener("abort",c)});return l.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},l}function $o(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 mr=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=$o(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 yr=class extends Zo.default{#t;#i;#s=0;#d;#a;#p=0;#r;#c;#e;#m;#n=0;#u;#o;#y;#x=1n;timeout;constructor(t){if(super(),t={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:mr,...t},!(typeof t.intervalCap=="number"&&t.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${t.intervalCap?.toString()??""}\` (${typeof t.intervalCap})`);if(t.interval===void 0||!(Number.isFinite(t.interval)&&t.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${t.interval?.toString()??""}\` (${typeof t.interval})`);this.#t=t.carryoverConcurrencyCount,this.#i=t.intervalCap===Number.POSITIVE_INFINITY||t.interval===0,this.#d=t.intervalCap,this.#a=t.interval,this.#e=new t.queueClass,this.#m=t.queueClass,this.concurrency=t.concurrency,this.timeout=t.timeout,this.#y=t.throwOnTimeout===!0,this.#o=t.autoStart===!1}get#w(){return this.#i||this.#s<this.#d}get#E(){return this.#n<this.#u}#S(){this.#n--,this.#f(),this.emit("next")}#v(){this.#g(),this.#b(),this.#c=void 0}get#A(){let t=Date.now();if(this.#r===void 0){let e=this.#p-t;if(e<0)this.#s=this.#t?this.#n:0;else return this.#c===void 0&&(this.#c=setTimeout(()=>{this.#v()},e)),!0}return!1}#f(){if(this.#e.size===0)return this.#r&&clearInterval(this.#r),this.#r=void 0,this.emit("empty"),this.#n===0&&this.emit("idle"),!1;if(!this.#o){let t=!this.#A;if(this.#w&&this.#E){let e=this.#e.dequeue();return e?(this.emit("active"),e(),t&&this.#b(),!0):!1}}return!1}#b(){this.#i||this.#r!==void 0||(this.#r=setInterval(()=>{this.#g()},this.#a),this.#p=Date.now()+this.#a)}#g(){this.#s===0&&this.#n===0&&this.#r&&(clearInterval(this.#r),this.#r=void 0),this.#s=this.#t?this.#n:0,this.#l()}#l(){for(;this.#f(););}get concurrency(){return this.#u}set concurrency(t){if(!(typeof t=="number"&&t>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${t}\` (${typeof t})`);this.#u=t,this.#l()}async#I(t){return new Promise((e,n)=>{t.addEventListener("abort",()=>{n(t.reason)},{once:!0})})}setPriority(t,e){this.#e.setPriority(t,e)}async add(t,e={}){return e.id??=(this.#x++).toString(),e={timeout:this.timeout,throwOnTimeout:this.#y,...e},new Promise((n,o)=>{this.#e.enqueue(async()=>{this.#n++,this.#s++;try{e.signal?.throwIfAborted();let s=t({signal:e.signal});e.timeout&&(s=Wo(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 pr&&!e.throwOnTimeout){n();return}o(s),this.emit("error",s)}finally{this.#S()}},e),this.emit("add"),this.#f()})}async addAll(t,e){return Promise.all(t.map(async n=>this.add(n,e)))}start(){return this.#o?(this.#o=!1,this.#l(),this):this}pause(){this.#o=!0}clear(){this.#e=new this.#m}async onEmpty(){this.#e.size!==0&&await this.#h("empty")}async onSizeLessThan(t){this.#e.size<t||await this.#h("next",()=>this.#e.size<t)}async onIdle(){this.#n===0&&this.#e.size===0||await this.#h("idle")}async#h(t,e){return new Promise(n=>{let o=()=>{e&&!e()||(this.off(t,o),n())};this.on(t,o)})}get size(){return this.#e.size}sizeBy(t){return this.#e.filter(t).length}get pending(){return this.#n}get isPaused(){return this.#o}};function ea(r){if(r!=null){if(typeof r[Symbol.iterator]=="function")return r[Symbol.iterator]();if(typeof r[Symbol.asyncIterator]=="function")return r[Symbol.asyncIterator]();if(typeof r.next=="function")return r}throw new Error("argument is not an iterator or iterable")}function ra(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function na(r,t){let e=ea(r).return?.();ra(e)&&e.catch(n=>{t.error("could not cause iterator to return",n)})}var en=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Oe=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},rn=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},br=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function nn(r){return r[Symbol.asyncIterator]!=null}function oa(r,t){if(r.byteLength>t)throw new Oe("Message length too long")}var sn=r=>{let t=Lt(r),e=ft(t);return hi(r,e),sn.bytes=t,e};sn.bytes=0;function an(r,t){t=t??{};let e=t.lengthEncoder??sn,n=t?.maxDataLength??4194304;function*o(s){oa(s,n);let i=e(s.byteLength);i instanceof Uint8Array?yield i:yield*i,s instanceof Uint8Array?yield s:yield*s}return nn(r)?async function*(){for await(let s of r)yield*o(s)}():function*(){for(let s of r)yield*o(s)}()}an.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??sn,n=t?.maxDataLength??4194304;return oa(r,n),new rt(e(r.byteLength),r)};var we;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(we||(we={}));var Xo=r=>{let t=di(r);return Xo.bytes=Lt(t),t};Xo.bytes=0;function gr(r,t){let e=new rt,n=we.LENGTH,o=-1,s=t?.lengthDecoder??Xo,i=t?.maxLengthLength??8,c=t?.maxDataLength??4194304;function*a(){for(;e.byteLength>0;){if(n===we.LENGTH)try{if(o=s(e),o<0)throw new en("Invalid message length");if(o>c)throw new Oe("Message length too long");let l=s.bytes;e.consume(l),t?.onLength!=null&&t.onLength(o),n=we.DATA}catch(l){if(l instanceof RangeError){if(e.byteLength>i)throw new rn("Message length length too long");break}throw l}if(n===we.DATA){if(e.byteLength<o)break;let l=e.sublist(0,o);e.consume(o),t?.onData!=null&&t.onData(l),yield l,n=we.LENGTH}}}return nn(r)?async function*(){for await(let l of r)e.append(l),yield*a();if(e.byteLength>0)throw new br("Unexpected end of input")}():function*(){for(let l of r)e.append(l),yield*a();if(e.byteLength>0)throw new br("Unexpected end of input")}()}gr.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 gr(n,{...t??{},onLength:s=>{e=s}})};var cn=class extends Se{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 rt(t):t)}attachInboundStream(t,e){let n=()=>{na(t.source,this.log)};return this._inboundAbortController.signal.addEventListener("abort",n,{once:!0}),this._rawInboundStream=t,this.inboundStream=hr(this._rawInboundStream,o=>gr(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=Jr({onEnd:n=>{this._rawOutboundStream?.closeWrite().catch(o=>{this.log("error closing outbound stream",o)}),this._rawOutboundStream=void 0,this.outboundStream=void 0,n!=null&&this.dispatchEvent(new CustomEvent("close"))}}),hr(this.outboundStream,n=>an(n),this._rawOutboundStream).catch(n=>{this.log.error(n)}),e==null&&this.dispatchEvent(new CustomEvent("stream:outbound")),this.outboundStream}close(){this.closed||(this.closed=!0,this.outboundStream!=null&&this.outboundStream.end(),this.inboundStream!=null&&this._inboundAbortController.abort(),this._rawOutboundStream=void 0,this.outboundStream=void 0,this._rawInboundStream=void 0,this.inboundStream=void 0,this.dispatchEvent(new CustomEvent("close")))}};function sa(){return BigInt(`0x${G(Fr(8),"base16")}`)}var ia=(r,t)=>{let e=F(t.toString(16).padStart(16,"0"),"base16"),n=kt(r),o=new Uint8Array(n.byteLength+e.length);return o.set(n,0),o.set(e,n.byteLength),o},aa=r=>ie.encode(r);var ca=function(r){return Array.isArray(r)?r:[r]},uf=async r=>{if(r.sequenceNumber==null||r.from==null||r.signature==null)return!1;let t=ur(Yt(r.from));if(t.publicKey!=null)return!0;if(r.key!=null){let e=r.key;return Vo(Ho(e)).equals(t)}return!1},ua=async r=>{if(r.from==null)throw new J("RPC message was missing from");if(!await uf(r))return{type:"unsigned",topic:r.topic??"",data:r.data??new Uint8Array(0)};let t=ur(Yt(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:lf(r.sequenceNumber??new Uint8Array(0)),data:r.data??new Uint8Array(0),signature:r.signature??new Uint8Array(0),key:e instanceof Uint8Array?Ho(e):e}},xr=r=>r.type==="signed"?{from:r.from.toMultihash().bytes,data:r.data,sequenceNumber:ff(r.sequenceNumber),topic:r.topic,signature:r.signature,key:r.key?kt(r.key):void 0}:{data:r.data,topic:r.topic},ff=r=>{let t=r.toString(16);return t.length%2!==0&&(t=`0${t}`),F(t,"base16")},lf=r=>BigInt(`0x${G(r,"base16")}`);var fa=F("libp2p-pubsub:");async function la(r,t,e){let n={type:"signed",topic:t.topic,data:t.data,sequenceNumber:t.sequenceNumber,from:Gi(r)},o=se([fa,e(xr(n)).subarray()]);return n.signature=await r.sign(o),n.key=r.publicKey,n}async function ha(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=se([fa,t({...xr(r),signature:void 0,key:void 0}).subarray()]);return hf(r).verify(e,r.signature)}function hf(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 Jo=class extends Se{log;started;topics;subscriptions;peers;globalSignaturePolicy;canRelayMessage;emitSelf;topicValidators;queue;multicodecs;components;_registrarTopologyIds;enabled;maxInboundStreams;maxOutboundStreams;constructor(t,e){super();let{multicodecs:n=[],globalSignaturePolicy:o="StrictSign",canRelayMessage:s=!1,emitSelf:i=!1,messageProcessingConcurrency:c=10,maxInboundStreams:a=1,maxOutboundStreams:l=1}=e;this.log=t.logger.forComponent("libp2p:pubsub"),this.components=t,this.multicodecs=ca(n),this.enabled=e.enabled!==!1,this.started=!1,this.topics=new Map,this.subscriptions=new Set,this.peers=new fr,this.globalSignaturePolicy=o==="StrictNoSign"?"StrictNoSign":"StrictSign",this.canRelayMessage=s,this.emitSelf=i,this.topicValidators=new Map,this.queue=new yr({concurrency:c}),this.maxInboundStreams=a,this.maxOutboundStreams=l,this._onIncomingStream=this._onIncomingStream.bind(this),this._onPeerConnected=this._onPeerConnected.bind(this),this._onPeerDisconnected=this._onPeerDisconnected.bind(this)}async start(){if(this.started||!this.enabled)return;this.log("starting");let t=this.components.registrar;await Promise.all(this.multicodecs.map(async n=>{await t.handle(n,this._onIncomingStream,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams})}));let e={onConnect:this._onPeerConnected,onDisconnect:this._onPeerDisconnected};this._registrarTopologyIds=await Promise.all(this.multicodecs.map(async n=>t.register(n,e))),this.log("started"),this.started=!0}async stop(){if(!this.started||!this.enabled)return;let t=this.components.registrar;this._registrarTopologyIds!=null&&this._registrarTopologyIds?.forEach(e=>{t.unregister(e)}),await Promise.all(this.multicodecs.map(async e=>{await t.unhandle(e)})),this.log("stopping");for(let e of this.peers.values())e.close();this.peers.clear(),this.subscriptions=new Set,this.started=!1,this.log("stopped")}isStarted(){return this.started}_onIncomingStream(t){let{stream:e,connection:n}=t,o=n.remotePeer;if(e.protocol==null){e.abort(new Error("Stream was not multiplexed"));return}let s=this.addPeer(o,e.protocol),i=s.attachInboundStream(e);this.processMessages(o,i,s).catch(c=>{this.log(c)})}_onPeerConnected(t,e){if(this.log("connected %p",t),e.streams.find(n=>n.direction==="outbound"&&n.protocol!=null&&this.multicodecs.includes(n.protocol))!=null){this.log("outbound pubsub streams already present on connection from %p",t);return}Promise.resolve().then(async()=>{try{let n=await e.newStream(this.multicodecs);if(n.protocol==null){n.abort(new Error("Stream was not multiplexed"));return}await this.addPeer(t,n.protocol).attachOutboundStream(n)}catch(n){this.log.error(n)}this.send(t,{subscriptions:Array.from(this.subscriptions).map(n=>n.toString()),subscribe:!0})}).catch(n=>{this.log.error(n)})}_onPeerDisconnected(t,e){this.log("connection ended %p",t),this._removePeer(t)}addPeer(t,e){let n=this.peers.get(t);if(n!=null)return n;this.log("new peer %p",t);let o=new 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 hr(e,async o=>{for await(let s of o){let i=this.decodeRpc(s),c=[];for(let a of i.messages??[]){if(a.from==null||a.data==null||a.topic==null){this.log("message from %p was missing from, data or topic fields, dropping",t);continue}c.push({from:a.from,data:a.data,topic:a.topic,sequenceNumber:a.sequenceNumber??void 0,signature:a.signature??void 0,key:a.key??void 0})}this.processRpc(t,n,{subscriptions:(i.subscriptions??[]).map(a=>({subscribe:!!a.subscribe,topic:a.topic??""})),messages:c}).catch(a=>{this.log(a)})}})}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:c})=>({topic:`${i??""}`,subscribe:!!c}))}}))),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 c=await ua(i);await this.processMessage(t,c)}catch(c){this.log.error(c)}})).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)){try{await this.validate(t,e)}catch(n){this.log("Message is invalid, dropping it. %O",n);return}this.subscriptions.has(e.topic)&&(!this.components.peerId.equals(t)||this.emitSelf)&&super.dispatchEvent(new CustomEvent("message",{detail:e})),await this.publishMessage(t,e)}}getMsgId(t){switch(this.globalSignaturePolicy){case"StrictSign":if(t.type!=="signed")throw new J('Message type should be "signed" when signature policy is StrictSign but it was not');if(t.sequenceNumber==null)throw new J("Need sequence number when signature policy is StrictSign but it was missing");if(t.key==null)throw new J("Need key when signature policy is StrictSign but it was missing");return ia(t.key,t.sequenceNumber);case"StrictNoSign":return aa(t.data);default:throw new J("Cannot get message id: unhandled signature policy")}}acceptFrom(t){return!0}send(t,e){let{messages:n,subscriptions:o,subscribe:s}=e;this.sendRpc(t,{subscriptions:(o??[]).map(i=>({topic:i,subscribe:!!s})),messages:(n??[]).map(xr)})}sendRpc(t,e){let n=this.peers.get(t);if(n==null){this.log.error("Cannot send RPC to %p as there are no streams to it available",t);return}if(!n.isWritable){this.log.error("Cannot send RPC to %p as there is no outbound stream to it available",t);return}n.write(this.encodeRpc(e))}async validate(t,e){switch(this.globalSignaturePolicy){case"StrictNoSign":if(e.type!=="unsigned")throw new J('Message type should be "unsigned" when signature policy is StrictNoSign but it was not');if(e.signature!=null)throw new J("StrictNoSigning: signature should not be present");if(e.key!=null)throw new J("StrictNoSigning: key should not be present");if(e.sequenceNumber!=null)throw new J("StrictNoSigning: seqno should not be present");break;case"StrictSign":if(e.type!=="signed")throw new J('Message type should be "signed" when signature policy is StrictSign but it was not');if(e.signature==null)throw new J("StrictSigning: Signing required and no signature was present");if(e.sequenceNumber==null)throw new J("StrictSigning: Signing required and no sequenceNumber was present");if(!await ha(e,this.encodeMessage.bind(this)))throw new J("StrictSigning: Invalid message signature");break;default:throw new J("Cannot validate message: unhandled signature policy")}let o=this.topicValidators.get(e.topic);if(o!=null){let s=await o(t,e);if(s===qe.Reject||s===qe.Ignore)throw new J("Message validation failed")}}async buildMessage(t){switch(this.globalSignaturePolicy){case"StrictSign":return la(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 Sr("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:sa()};this.log("publish topic: %s from: %p data: %m",t,n.from,n.data);let o=await this.buildMessage(n),s=!1;this.emitSelf&&this.subscriptions.has(t)&&(s=!0,super.dispatchEvent(new CustomEvent("message",{detail:o})));let i=await this.publishMessage(this.components.peerId,o);return s&&(i.recipients=[...i.recipients,this.components.peerId]),i}subscribe(t){if(!this.started)throw new Error("Pubsub has not started");if(this.log("subscribe to topic: %s",t),!this.subscriptions.has(t)){this.subscriptions.add(t);for(let e of this.peers.keys())this.send(e,{subscriptions:[t],subscribe:!0})}}unsubscribe(t){if(!this.started)throw new Error("Pubsub is not started");super.removeEventListener(t);let e=this.subscriptions.has(t);if(this.log("unsubscribe from %s - am subscribed %s",t,e),e){this.subscriptions.delete(t);for(let n of this.peers.keys())this.send(n,{subscriptions:[t],subscribe:!1})}}getTopics(){if(!this.started)throw new Error("Pubsub is not started");return Array.from(this.subscriptions)}getPeers(){if(!this.started)throw new Error("Pubsub is not started");return Array.from(this.peers.keys())}};return Aa(df);})();
|
3
3
|
/*! Bundled license information:
|
4
4
|
|
5
5
|
@noble/hashes/esm/utils.js:
|
6
6
|
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
7
7
|
|
8
8
|
@noble/curves/esm/abstract/utils.js:
|
9
|
-
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
10
|
-
|
11
9
|
@noble/curves/esm/abstract/modular.js:
|
12
|
-
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
13
|
-
|
14
10
|
@noble/curves/esm/abstract/curve.js:
|
15
|
-
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
16
|
-
|
17
11
|
@noble/curves/esm/abstract/edwards.js:
|
18
|
-
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
19
|
-
|
20
12
|
@noble/curves/esm/ed25519.js:
|
21
|
-
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
22
|
-
|
23
13
|
@noble/curves/esm/abstract/weierstrass.js:
|
24
|
-
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
25
|
-
|
26
14
|
@noble/curves/esm/_shortw_utils.js:
|
27
|
-
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
28
|
-
|
29
15
|
@noble/curves/esm/secp256k1.js:
|
30
16
|
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
31
17
|
*/
|
32
18
|
return Libp2PPubsub}));
|
19
|
+
//# sourceMappingURL=index.min.js.map
|